@@ -234,9 +234,21 @@ def test_style(self):
234234 f .set_cell_style ("SheetN" , "A1" , "B2" , style_id )
235235 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
236236 self .assertIsNone (f .set_col_style ("Sheet1" , "H" , style_id ))
237+ with self .assertRaises (TypeError ) as context :
238+ f .set_cell_style ("SheetN" , "A1" , "B2" , True )
239+ self .assertEqual (
240+ str (context .exception ),
241+ "expected type int for argument 'style_id', but got bool" ,
242+ )
237243 with self .assertRaises (RuntimeError ) as context :
238244 f .set_col_style ("SheetN" , "H" , style_id )
239245 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
246+ with self .assertRaises (TypeError ) as context :
247+ f .set_col_style ("Sheet1" , "H" , True )
248+ self .assertEqual (
249+ str (context .exception ),
250+ "expected type int for argument 'style_id', but got bool" ,
251+ )
240252 self .assertEqual (f .get_col_style ("Sheet1" , "H" ), style_id )
241253 with self .assertRaises (RuntimeError ) as context :
242254 f .get_col_style ("SheetN" , "H" )
@@ -366,10 +378,22 @@ def test_style(self):
366378 with self .assertRaises (RuntimeError ) as context :
367379 f .set_cell_int ("SheetN" , "A10" , 100 )
368380 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
381+ with self .assertRaises (TypeError ) as context :
382+ f .set_cell_int ("Sheet1" , "A1" , True )
383+ self .assertEqual (
384+ str (context .exception ),
385+ "expected type int for argument 'value', but got bool" ,
386+ )
369387 self .assertIsNone (f .set_cell_str ("Sheet1" , "A12" , "Hello" ))
370388 with self .assertRaises (RuntimeError ) as context :
371389 f .set_cell_str ("SheetN" , "A12" , "Hello" )
372390 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
391+ with self .assertRaises (TypeError ) as context :
392+ f .set_cell_str ("SheetN1" , "A12" , excelize .RichTextRun ())
393+ self .assertEqual (
394+ str (context .exception ),
395+ "expected type str for argument 'value', but got RichTextRun" ,
396+ )
373397 with self .assertRaises (RuntimeError ) as context :
374398 f .set_cell_value ("SheetN" , "A9" , None )
375399 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
@@ -505,6 +529,12 @@ def test_style(self):
505529 with self .assertRaises (RuntimeError ) as context :
506530 f .set_col_outline_level ("SheetN" , "D" , 2 )
507531 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
532+ with self .assertRaises (TypeError ) as context :
533+ f .set_col_outline_level ("SheetN" , "D" , True )
534+ self .assertEqual (
535+ str (context .exception ),
536+ "expected type int for argument 'level', but got bool" ,
537+ )
508538 self .assertEqual (f .get_col_outline_level ("Sheet1" , "D" ), 2 )
509539 with self .assertRaises (RuntimeError ) as context :
510540 f .get_col_outline_level ("SheetN" , "D" )
@@ -858,12 +888,30 @@ def test_none_file_pointer(self):
858888 with self .assertRaises (RuntimeError ) as context :
859889 f .set_default_font ("" )
860890 self .assertEqual (str (context .exception ), expected )
891+ with self .assertRaises (TypeError ) as context :
892+ f .set_default_font (1 )
893+ self .assertEqual (
894+ str (context .exception ),
895+ "expected type str for argument 'font_name', but got int" ,
896+ )
861897 with self .assertRaises (RuntimeError ) as context :
862898 f .set_defined_name (excelize .DefinedName ())
863899 self .assertEqual (str (context .exception ), expected )
900+ with self .assertRaises (TypeError ) as context :
901+ f .set_defined_name (1 )
902+ self .assertEqual (
903+ str (context .exception ),
904+ "expected type DefinedName for argument 'defined_name', but got int" ,
905+ )
864906 with self .assertRaises (RuntimeError ) as context :
865907 f .set_doc_props (excelize .DocProperties ())
866908 self .assertEqual (str (context .exception ), expected )
909+ with self .assertRaises (TypeError ) as context :
910+ f .set_doc_props (1 )
911+ self .assertEqual (
912+ str (context .exception ),
913+ "expected type DocProperties for argument 'doc_properties', but got int" ,
914+ )
867915 with self .assertRaises (RuntimeError ) as context :
868916 f .set_workbook_props (excelize .WorkbookPropsOptions ())
869917 self .assertEqual (str (context .exception ), expected )
@@ -1280,6 +1328,12 @@ def test_header_footer(self):
12801328 with self .assertRaises (RuntimeError ) as context :
12811329 f .set_header_footer ("SheetN" , excelize .HeaderFooterOptions ())
12821330 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1331+ with self .assertRaises (TypeError ) as context :
1332+ f .set_header_footer ("Sheet1" , 1 )
1333+ self .assertEqual (
1334+ str (context .exception ),
1335+ "expected type HeaderFooterOptions for argument 'opts', but got int" ,
1336+ )
12831337 self .assertIsNone (f .save_as (os .path .join ("test" , "TestHeaderFooter.xlsx" )))
12841338 self .assertIsNone (f .close ())
12851339
@@ -1303,6 +1357,12 @@ def test_page_layout(self):
13031357 with self .assertRaises (RuntimeError ) as context :
13041358 f .set_page_layout ("SheetN" , excelize .PageLayoutOptions ())
13051359 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1360+ with self .assertRaises (TypeError ) as context :
1361+ f .set_page_layout ("Sheet1" , 1 )
1362+ self .assertEqual (
1363+ str (context .exception ),
1364+ "expected type PageLayoutOptions for argument 'opts', but got int" ,
1365+ )
13061366 self .assertIsNone (f .save_as (os .path .join ("test" , "TestPageLayout.xlsx" )))
13071367 self .assertIsNone (f .close ())
13081368
@@ -1326,6 +1386,12 @@ def test_page_margins(self):
13261386 with self .assertRaises (RuntimeError ) as context :
13271387 f .set_page_margins ("SheetN" , excelize .PageLayoutMarginsOptions ())
13281388 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1389+ with self .assertRaises (TypeError ) as context :
1390+ f .set_page_margins ("Sheet1" , 1 )
1391+ self .assertEqual (
1392+ str (context .exception ),
1393+ "expected type PageLayoutMarginsOptions for argument 'opts', but got int" ,
1394+ )
13291395 self .assertIsNone (f .save_as (os .path .join ("test" , "TestPageMargins.xlsx" )))
13301396 self .assertIsNone (f .close ())
13311397
@@ -1354,6 +1420,12 @@ def test_panes(self):
13541420 with self .assertRaises (RuntimeError ) as context :
13551421 f .set_panes ("SheetN" , excelize .Panes ())
13561422 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1423+ with self .assertRaises (TypeError ) as context :
1424+ f .set_panes ("Sheet1" , 1 )
1425+ self .assertEqual (
1426+ str (context .exception ),
1427+ "expected type Panes for argument 'opts', but got int" ,
1428+ )
13571429 self .assertIsNone (f .save_as (os .path .join ("test" , "TestPanes.xlsx" )))
13581430 self .assertIsNone (f .close ())
13591431
@@ -1749,8 +1821,14 @@ def test_cell_rich_text(self):
17491821
17501822 self .assertIsNone (f .set_col_width ("Sheet1" , "A" , "A" , 44.5 ))
17511823 with self .assertRaises (RuntimeError ) as context :
1752- f .set_col_width ("SheetN" , "A" , "A" , 44 )
1824+ f .set_col_width ("SheetN" , "A" , "A" , 44.0 )
17531825 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1826+ with self .assertRaises (TypeError ) as context :
1827+ f .set_col_width ("Sheet1" , "A" , "A" , 44 )
1828+ self .assertEqual (
1829+ str (context .exception ),
1830+ "expected type float for argument 'width', but got int" ,
1831+ )
17541832 self .assertEqual (f .get_col_width ("Sheet1" , "A" ), 44.5 )
17551833 with self .assertRaises (RuntimeError ) as context :
17561834 f .get_col_width ("SheetN" , "A" )
@@ -1842,6 +1920,12 @@ def test_cell_rich_text(self):
18421920 with self .assertRaises (RuntimeError ) as context :
18431921 f .set_cell_rich_text ("SheetN" , "A1" , expected )
18441922 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1923+ with self .assertRaises (TypeError ) as context :
1924+ f .set_cell_rich_text ("Sheet1" , "A1" , 1 )
1925+ self .assertEqual (
1926+ str (context .exception ),
1927+ "expected type list for argument 'runs', but got int" ,
1928+ )
18451929 style = f .new_style (
18461930 excelize .Style (alignment = excelize .Alignment (wrap_text = True ))
18471931 )
@@ -1889,6 +1973,12 @@ def test_conditional_format(self):
18891973 with self .assertRaises (RuntimeError ) as context :
18901974 f .set_conditional_format ("SheetN" , "A1:A10" , [])
18911975 self .assertEqual (str (context .exception ), "sheet SheetN does not exist" )
1976+ with self .assertRaises (TypeError ) as context :
1977+ f .set_conditional_format ("Sheet1" , "A1:A10" , 1 )
1978+ self .assertEqual (
1979+ str (context .exception ),
1980+ "expected type list for argument 'opts', but got int" ,
1981+ )
18921982 self .assertIsNone (f .save_as (os .path .join ("test" , "TestConditionalFormat.xlsx" )))
18931983 self .assertIsNone (f .close ())
18941984
0 commit comments