2222answer_files = {}
2323
2424# List of answer files
25- answer_file_list = ' tests/tests.yaml'
26- answer_dir = os .path .join (ytcfg .get ('yt' , ' test_data_dir' ), ' answers' )
25+ answer_file_list = " tests/tests.yaml"
26+ answer_dir = os .path .join (ytcfg .get ("yt" , " test_data_dir" ), " answers" )
2727
2828
2929def pytest_addoption (parser ):
3030 """
3131 Lets options be passed to test functions.
3232 """
3333 parser .addoption (
34- "--with-answer-testing" ,
35- action = "store_true" ,
36- default = False ,
34+ "--with-answer-testing" , action = "store_true" , default = False ,
3735 )
3836 parser .addoption (
39- "--answer-store" ,
40- action = "store_true" ,
41- default = False ,
37+ "--answer-store" , action = "store_true" , default = False ,
4238 )
4339 parser .addoption (
44- "--answer-big-data" ,
45- action = "store_true" ,
46- default = False ,
40+ "--answer-big-data" , action = "store_true" , default = False ,
4741 )
4842 parser .addoption (
49- "--save-answer-arrays" ,
50- action = "store_true" ,
43+ "--save-answer-arrays" , action = "store_true" ,
5144 )
5245
5346
@@ -62,12 +55,13 @@ def pytest_configure(config):
6255 os .mkdir (answer_dir )
6356 # Read the list of answer test classes and their associated answer
6457 # file
65- with open (answer_file_list , 'r' ) as f :
58+ with open (answer_file_list , "r" ) as f :
6659 answer_files = yaml .safe_load (f )
6760 # Register custom marks for answer tests and big data
68- config .addinivalue_line ('markers' , 'answer_test: Run the answer tests.' )
69- config .addinivalue_line ('markers' , 'big_data: Run answer tests that require'
70- ' large data files.' )
61+ config .addinivalue_line ("markers" , "answer_test: Run the answer tests." )
62+ config .addinivalue_line (
63+ "markers" , "big_data: Run answer tests that require" " large data files."
64+ )
7165
7266
7367def pytest_collection_modifyitems (config , items ):
@@ -81,21 +75,23 @@ def pytest_collection_modifyitems(config, items):
8175 for item in items :
8276 # If it's an answer test and the appropriate CL option hasn't
8377 # been set, skip it
84- if "answer_test" in item .keywords and not config .getoption ("--with-answer-testing" ):
78+ if "answer_test" in item .keywords and not config .getoption (
79+ "--with-answer-testing"
80+ ):
8581 item .add_marker (skip_answer )
8682 # If it's an answer test that requires big data and the CL
8783 # option hasn't been set, skip it
8884 if "big_data" in item .keywords and not config .getoption ("--answer-big-data" ):
8985 item .add_marker (skip_big )
9086
9187
92- @pytest .fixture (scope = ' function' )
88+ @pytest .fixture (scope = " function" )
9389def temp_dir ():
9490 r"""
9591 Creates a temporary directory needed by certain tests.
9692 """
9793 curdir = os .getcwd ()
98- if int (os .environ .get (' GENERATE_YTDATA' , 0 )):
94+ if int (os .environ .get (" GENERATE_YTDATA" , 0 )):
9995 tmpdir = os .getcwd ()
10096 else :
10197 tmpdir = tempfile .mkdtemp ()
@@ -106,7 +102,7 @@ def temp_dir():
106102 shutil .rmtree (tmpdir )
107103
108104
109- @pytest .fixture (scope = ' class' )
105+ @pytest .fixture (scope = " class" )
110106def answer_file (request ):
111107 r"""
112108 Assigns the name of the appropriate answer file as an attribute of
@@ -145,12 +141,11 @@ def answer_file(request):
145141 answer_file = answer_files [request .cls .__name__ ]
146142 # Make sure we're not overwriting an existing answer set
147143 if os .path .isfile (os .path .join (answer_dir , answer_file )):
148- if request .config .getoption ('--answer-store' ):
149- raise FileExistsError ("Error, attempting to overwrite "
144+ if request .config .getoption ("--answer-store" ):
145+ raise FileExistsError (
146+ "Error, attempting to overwrite "
150147 "answer file {}. Either specify a new version or "
151- "set the `--force-override-answers` option" .format (
152- answer_file
153- )
148+ "set the `--force-override-answers` option" .format (answer_file )
154149 )
155150 else :
156151 assert False
@@ -167,13 +162,13 @@ def _param_list(request):
167162 # co_varnames is all of the variable names local to the function
168163 # starting with self, then the passed args, then the vars defined
169164 # in the function body. This excludes fixture names
170- args = func .__code__ .co_varnames [1 : func .__code__ .co_argcount ]
165+ args = func .__code__ .co_varnames [1 : func .__code__ .co_argcount ]
171166 # funcargs includes the names and values of all arguments, including
172167 # fixtures, so we use args to weed out the fixtures. Need to have
173168 # special treatment of the data files loaded in fixtures for the
174169 # frontends
175170 for key , val in request .node .funcargs .items ():
176- if key in args and not key .startswith (' ds_' ):
171+ if key in args and not key .startswith (" ds_" ):
177172 test_params [key ] = val
178173 # Convert python-specific data objects (such as tuples) to a more
179174 # io-friendly format (in order to not have python-specific anchors
@@ -182,7 +177,7 @@ def _param_list(request):
182177 return test_params
183178
184179
185- @pytest .fixture (scope = ' function' )
180+ @pytest .fixture (scope = " function" )
186181def hashing (request ):
187182 r"""
188183 Handles initialization, generation, and saving of answer test
@@ -244,12 +239,20 @@ def hashing(request):
244239 # Add the other test parameters
245240 hashes .update (params )
246241 # Add the function name as the "master" key to the hashes dict
247- hashes = {request .node .name : hashes }
242+ hashes = {request .node .name : hashes }
248243 # Either save or compare
249- utils ._handle_hashes (answer_dir , request .cls .answer_file , hashes ,
250- request .config .getoption ('--answer-store' ))
251- if request .config .getoption ('--save-answer-arrays' ):
244+ utils ._handle_hashes (
245+ answer_dir ,
246+ request .cls .answer_file ,
247+ hashes ,
248+ request .config .getoption ("--answer-store" ),
249+ )
250+ if request .config .getoption ("--save-answer-arrays" ):
252251 # answer_file has .yaml appended to it, but here we're saving
253252 # the arrays as .npy files, so we remove the .yaml extension
254- utils ._save_arrays (answer_dir , request .cls .answer_file .split ('.' )[0 ],
255- request .cls .hashes , request .config .getoption ('--answer-store' ))
253+ utils ._save_arrays (
254+ answer_dir ,
255+ request .cls .answer_file .split ("." )[0 ],
256+ request .cls .hashes ,
257+ request .config .getoption ("--answer-store" ),
258+ )
0 commit comments