@@ -1309,11 +1309,6 @@ def test_ExcelWriter_dispatch_raises(self):
1309
1309
ExcelWriter ("nothing" )
1310
1310
1311
1311
def test_register_writer (self ):
1312
- # some awkward mocking to test out dispatch and such actually works
1313
- called_save = []
1314
- called_write_cells = []
1315
- called_sheets = []
1316
-
1317
1312
class DummyClass (ExcelWriter ):
1318
1313
called_save = False
1319
1314
called_write_cells = False
@@ -1325,34 +1320,37 @@ def book(self):
1325
1320
pass
1326
1321
1327
1322
def _save (self ):
1328
- called_save . append ( True )
1323
+ type( self ). called_save = True
1329
1324
1330
1325
def _write_cells (self , * args , ** kwargs ):
1331
- called_write_cells . append ( True )
1326
+ type( self ). called_write_cells = True
1332
1327
1333
1328
@property
1334
1329
def sheets (self ):
1335
- called_sheets .append (True )
1330
+ type(self ).called_sheets = True
1331
+
1332
+ @classmethod
1333
+ def assert_called_and_reset (cls ):
1334
+ assert cls .called_save
1335
+ assert cls .called_write_cells
1336
+ assert not cls .called_sheets
1337
+ cls .called_save = False
1338
+ cls .called_write_cells = False
1336
1339
1337
- def check_called (func ):
1338
- func ()
1339
- assert len (called_save ) >= 1
1340
- assert len (called_write_cells ) >= 1
1341
- assert len (called_sheets ) == 0
1342
- del called_save [:]
1343
- del called_write_cells [:]
1344
- del called_sheets [:]
1340
+ register_writer (DummyClass )
1345
1341
1346
1342
with option_context ("io.excel.xlsx.writer" , "dummy" ):
1347
1343
path = "something.xlsx"
1348
1344
with tm .ensure_clean (path ) as filepath :
1349
- register_writer (DummyClass )
1350
1345
with ExcelWriter (filepath ) as writer :
1351
1346
assert isinstance (writer , DummyClass )
1352
1347
df = tm .makeCustomDataframe (1 , 1 )
1353
- check_called (lambda : df .to_excel (filepath ))
1354
- with tm .ensure_clean ("something.xls" ) as filepath :
1355
- check_called (lambda : df .to_excel (filepath , engine = "dummy" ))
1348
+ df .to_excel (filepath )
1349
+ DummyClass .assert_called_and_reset ()
1350
+
1351
+ with tm .ensure_clean ("something.xls" ) as filepath :
1352
+ df .to_excel (filepath , engine = "dummy" )
1353
+ DummyClass .assert_called_and_reset ()
1356
1354
1357
1355
@pytest .mark .parametrize (
1358
1356
"ext" ,
0 commit comments