99
1010import os
1111import unittest
12+ from typing import Any , Dict , List
1213
1314from .helperfunctions import _compare_xlsx_files
1415
@@ -20,29 +21,62 @@ class ExcelComparisonTest(unittest.TestCase):
2021
2122 """
2223
23- def set_filename (self , filename ):
24- # Set the filename and paths for the test xlsx files.
25- self .maxDiff = None
26- self .got_filename = ""
27- self .exp_filename = ""
28- self .ignore_files = []
29- self .ignore_elements = {}
30- self .test_dir = "xlsxwriter/test/comparison/"
31- self .vba_dir = self .test_dir + "xlsx_files/"
32- self .image_dir = self .test_dir + "images/"
33- self .theme_dir = self .test_dir + "themes/"
24+ def __init__ (self , * args : Any ) -> None :
25+ """
26+ Initialize the ExcelComparisonTest instance.
3427
28+ Args:
29+ *args: Variable arguments passed to unittest.TestCase.
30+ """
31+ super ().__init__ (* args )
32+
33+ # pylint: disable=invalid-name
34+ self .maxDiff : None = None
35+
36+ self .got_filename : str = ""
37+ self .exp_filename : str = ""
38+ self .ignore_files : List [str ] = []
39+ self .ignore_elements : Dict [str , Any ] = {}
40+ self .txt_filename : str = ""
41+ self .delete_output : bool = True
42+
43+ # Set the paths for the test files.
44+ self .test_dir : str = "xlsxwriter/test/comparison/"
45+ self .vba_dir : str = self .test_dir + "xlsx_files/"
46+ self .image_dir : str = self .test_dir + "images/"
47+ self .theme_dir : str = self .test_dir + "themes/"
48+ self .output_dir : str = self .test_dir + "output/"
49+
50+ def set_filename (self , filename : str ) -> None :
51+ """
52+ Set the filenames for the Excel comparison test.
53+
54+ Args:
55+ filename (str): The base filename for the test files.
56+ """
3557 # The reference Excel generated file.
3658 self .exp_filename = self .test_dir + "xlsx_files/" + filename
3759
3860 # The generated XlsxWriter file.
39- self .got_filename = self .test_dir + "_test_" + filename
61+ self .got_filename = self .output_dir + "py_" + filename
62+
63+ def set_text_file (self , filename : str ) -> None :
64+ """
65+ Set the filename and path for text files used in tests.
4066
41- def set_text_file (self , filename ):
67+ Args:
68+ filename (str): The name of the text file.
69+ """
4270 # Set the filename and path for text files used in tests.
4371 self .txt_filename = self .test_dir + "xlsx_files/" + filename
4472
45- def assertExcelEqual (self ):
73+ def assertExcelEqual (self ) -> None : # pylint: disable=invalid-name
74+ """
75+ Compare the generated file with the reference Excel file.
76+
77+ Raises:
78+ AssertionError: If the files are not equivalent.
79+ """
4680 # Compare the generate file and the reference Excel file.
4781 got , exp = _compare_xlsx_files (
4882 self .got_filename ,
@@ -53,7 +87,12 @@ def assertExcelEqual(self):
5387
5488 self .assertEqual (exp , got )
5589
56- def tearDown (self ):
90+ def tearDown (self ) -> None :
91+ """
92+ Clean up after each test by removing temporary files.
93+ Raises:
94+ OSError: If there is an error deleting the file.
95+ """
5796 # Cleanup by removing the temp excel file created for testing.
58- if os .path .exists (self .got_filename ):
97+ if self . delete_output and os .path .exists (self .got_filename ):
5998 os .remove (self .got_filename )
0 commit comments