@@ -52,12 +52,12 @@ def test_load(
52
52
) -> None :
53
53
filepath = DATA_FILES [data_key ]
54
54
# intercept HTTP requests and write dummy df to disk instead
55
- with patch ("urllib.request.urlretrieve" ) as urlretrieve :
55
+ with patch ("urllib.request.urlretrieve" ) as url_retrieve :
56
56
# dummy df with random floats and material_id column
57
57
df_csv = pd ._testing .makeDataFrame ().reset_index (names = "material_id" )
58
58
59
59
writer = dummy_df_serialized .to_json if ".json" in filepath else df_csv .to_csv
60
- urlretrieve .side_effect = lambda url , path : writer (path )
60
+ url_retrieve .side_effect = lambda _url , path : writer (path )
61
61
out = load (
62
62
data_key ,
63
63
hydrate = hydrate ,
@@ -70,7 +70,7 @@ def test_load(
70
70
assert f"Downloading { data_key !r} from { figshare_urls [data_key ][0 ]} " in stdout
71
71
72
72
# check we called read_csv/read_json once for each data_name
73
- assert urlretrieve .call_count == 1
73
+ assert url_retrieve .call_count == 1
74
74
75
75
assert isinstance (out , pd .DataFrame ), f"{ data_key } not a DataFrame"
76
76
@@ -201,21 +201,17 @@ def test_df_wbm() -> None:
201
201
assert set (df_wbm ) > {"bandgap_pbe" , "formula" , "material_id" }
202
202
203
203
204
- @pytest .mark .parametrize ("pattern" , ["tmp/*df.csv" , "tmp/*df.json" ])
205
- def test_glob_to_df (pattern : str ) -> None :
206
- try :
207
- df = pd ._testing .makeMixedDataFrame ()
204
+ @pytest .mark .parametrize ("pattern" , ["*df.csv" , "*df.json" ])
205
+ def test_glob_to_df (pattern : str , tmp_path : Path ) -> None :
206
+ df = pd ._testing .makeMixedDataFrame ()
208
207
209
- os .makedirs (f"{ ROOT } /tmp " , exist_ok = True )
210
- df .to_csv (f"{ ROOT } /tmp /dummy_df.csv" , index = False )
211
- df .to_json (f"{ ROOT } /tmp /dummy_df.json" )
208
+ os .makedirs (f"{ tmp_path } " , exist_ok = True )
209
+ df .to_csv (f"{ tmp_path } /dummy_df.csv" , index = False )
210
+ df .to_json (f"{ tmp_path } /dummy_df.json" )
212
211
213
- df_out = glob_to_df (pattern )
214
- assert df_out .shape == df .shape
215
- assert list (df_out ) == list (df )
212
+ df_out = glob_to_df (f" { tmp_path } / { pattern } " )
213
+ assert df_out .shape == df .shape
214
+ assert list (df_out ) == list (df )
216
215
217
- with pytest .raises (FileNotFoundError ):
218
- glob_to_df ("foo" )
219
- finally :
220
- os .remove (f"{ ROOT } /tmp/dummy_df.csv" )
221
- os .remove (f"{ ROOT } /tmp/dummy_df.json" )
216
+ with pytest .raises (FileNotFoundError ):
217
+ glob_to_df ("foo" )
0 commit comments