Skip to content

Commit d215a8c

Browse files
Replace tmp_dir2 fixture with tmp_path. (#270)
1 parent f3ea387 commit d215a8c

File tree

5 files changed

+33
-42
lines changed

5 files changed

+33
-42
lines changed

pins/tests/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ def df():
6464
return pd.DataFrame({"x": [1, 2, 3], "y": ["a", "b", "c"]})
6565

6666

67-
@pytest.fixture
68-
def tmp_dir2():
69-
# fixture for offering a temporary directory
70-
# note that pytest has a built-in fixture tmp_dir, but it uses the lib py.path
71-
# which recommends using pathlib, etc..
72-
with tempfile.TemporaryDirectory() as tmp_dir:
73-
yield Path(tmp_dir)
74-
75-
7667
@pytest.fixture
7768
def tmp_cache():
7869
with rm_env("PINS_CACHE_DIR"):

pins/tests/test_boards.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def test_board_pin_write_default_title(board):
7676
assert meta.title == "df_csv: a pinned 3 x 2 DataFrame"
7777

7878

79-
def test_board_pin_write_prepare_pin(board, tmp_dir2):
79+
def test_board_pin_write_prepare_pin(board, tmp_path: Path):
8080
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
8181

82-
meta = board.prepare_pin_version(str(tmp_dir2), df, "df_csv", title=None, type="csv")
82+
meta = board.prepare_pin_version(str(tmp_path), df, "df_csv", title=None, type="csv")
8383
assert meta.file == "df_csv.csv"
84-
assert (tmp_dir2 / "data.txt").exists()
85-
assert (tmp_dir2 / "df_csv.csv").exists()
86-
assert not (tmp_dir2 / "df_csv.csv").is_dir()
84+
assert (tmp_path / "data.txt").exists()
85+
assert (tmp_path / "df_csv.csv").exists()
86+
assert not (tmp_path / "df_csv.csv").is_dir()
8787

8888

8989
def test_board_pin_write_roundtrip(board):
@@ -231,7 +231,7 @@ def test_board_pin_upload_path_list(board_with_cache, tmp_path):
231231
(pin_path,) = board_with_cache.pin_download("cool_pin")
232232

233233

234-
def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
234+
def test_board_pin_write_rsc_index_html(board, tmp_path: Path, snapshot):
235235
if board.fs.protocol != "rsc":
236236
pytest.skip()
237237

@@ -240,7 +240,7 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
240240
pin_name = "test_rsc_pin"
241241

242242
board.prepare_pin_version(
243-
str(tmp_dir2),
243+
str(tmp_path),
244244
df,
245245
pin_name,
246246
type="csv",
@@ -249,7 +249,7 @@ def test_board_pin_write_rsc_index_html(board, tmp_dir2, snapshot):
249249
created=DEFAULT_CREATION_DATE,
250250
)
251251

252-
snapshot.assert_equal_dir(tmp_dir2)
252+
snapshot.assert_equal_dir(tmp_path)
253253

254254

255255
# pin_write against different types -------------------------------------------
@@ -474,14 +474,14 @@ def test_board_pin_search_name(board, df, search, matches):
474474
from pins.cache import PinsCache # noqa
475475

476476

477-
def test_board_base_pin_meta_cache_touch(tmp_dir2, df):
477+
def test_board_base_pin_meta_cache_touch(tmp_path: Path, df):
478478
cache = fsspec.filesystem(
479479
"pinscache",
480480
target_protocol="file",
481481
same_names=True,
482-
hash_prefix=str(tmp_dir2),
482+
hash_prefix=str(tmp_path),
483483
)
484-
board = BaseBoard(str(tmp_dir2), fs=cache)
484+
board = BaseBoard(str(tmp_path), fs=cache)
485485

486486
board.pin_write(df, "some_df", type="csv")
487487
meta = board.pin_meta("some_df")

pins/tests/test_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def _sleep():
2828

2929

3030
@pytest.fixture
31-
def some_file(tmp_dir2):
32-
p = tmp_dir2 / "some_file.txt"
31+
def some_file(tmp_path):
32+
p = tmp_path / "some_file.txt"
3333
p.touch()
3434
return p
3535

@@ -87,8 +87,8 @@ def test_pins_cache_open():
8787

8888

8989
@pytest.fixture
90-
def a_cache(tmp_dir2):
91-
return tmp_dir2 / "board_cache"
90+
def a_cache(tmp_path):
91+
return tmp_path / "board_cache"
9292

9393

9494
def create_metadata(p, access_time):

pins/tests/test_constructors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ def test_board_constructor_temp_writable():
274274
assert len(list(p_board.glob("*"))) == 0
275275

276276

277-
def test_board_constructor_folder(tmp_dir2, df):
278-
board = c.board_folder(str(tmp_dir2))
277+
def test_board_constructor_folder(tmp_path: Path, df):
278+
board = c.board_folder(str(tmp_path))
279279
board.pin_write(df, "some_df", type="csv")
280280

281-
assert (tmp_dir2 / "some_df").exists()
281+
assert (tmp_path / "some_df").exists()
282282
df2 = board.pin_read("some_df")
283283

284284
assert df.equals(df2)

pins/tests/test_drivers.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414

1515
@pytest.fixture
16-
def some_joblib(tmp_dir2):
16+
def some_joblib(tmp_path: Path):
1717
import joblib
1818

19-
p_obj = tmp_dir2 / "some.joblib"
19+
p_obj = tmp_path / "some.joblib"
2020
joblib.dump({"a": 1}, p_obj)
2121

2222
return p_obj
@@ -54,7 +54,7 @@ def test_default_title(obj, dst_title):
5454
"joblib",
5555
],
5656
)
57-
def test_driver_roundtrip(tmp_dir2, type_):
57+
def test_driver_roundtrip(tmp_path: Path, type_):
5858
# TODO: I think this test highlights the challenge of getting the flow
5959
# between metadata, drivers, and the metafactory right.
6060
# There is the name of the data (relative to the pin directory), and the full
@@ -66,13 +66,13 @@ def test_driver_roundtrip(tmp_dir2, type_):
6666
fname = "some_df"
6767
full_file = f"{fname}.{type_}"
6868

69-
p_obj = tmp_dir2 / fname
69+
p_obj = tmp_path / fname
7070
res_fname = save_data(df, p_obj, type_)
7171

7272
assert Path(res_fname).name == full_file
7373

7474
meta = MetaRaw(full_file, type_, "my_pin")
75-
obj = load_data(meta, fsspec.filesystem("file"), tmp_dir2, allow_pickle_read=True)
75+
obj = load_data(meta, fsspec.filesystem("file"), tmp_path, allow_pickle_read=True)
7676

7777
assert df.equals(obj)
7878

@@ -83,50 +83,50 @@ def test_driver_roundtrip(tmp_dir2, type_):
8383
"json",
8484
],
8585
)
86-
def test_driver_roundtrip_json(tmp_dir2, type_):
86+
def test_driver_roundtrip_json(tmp_path: Path, type_):
8787
df = {"x": [1, 2, 3]}
8888

8989
fname = "some_df"
9090
full_file = f"{fname}.{type_}"
9191

92-
p_obj = tmp_dir2 / fname
92+
p_obj = tmp_path / fname
9393
res_fname = save_data(df, p_obj, type_)
9494

9595
assert Path(res_fname).name == full_file
9696

9797
meta = MetaRaw(full_file, type_, "my_pin")
98-
obj = load_data(meta, fsspec.filesystem("file"), tmp_dir2, allow_pickle_read=True)
98+
obj = load_data(meta, fsspec.filesystem("file"), tmp_path, allow_pickle_read=True)
9999

100100
assert df == obj
101101

102102

103-
def test_driver_feather_write_error(tmp_dir2):
103+
def test_driver_feather_write_error(tmp_path: Path):
104104
import pandas as pd
105105

106106
df = pd.DataFrame({"x": [1, 2, 3]})
107107

108108
fname = "some_df"
109109

110-
p_obj = tmp_dir2 / fname
110+
p_obj = tmp_path / fname
111111

112112
with pytest.raises(NotImplementedError) as exc_info:
113113
save_data(df, p_obj, "feather")
114114

115115
assert '"feather" no longer supported.' in exc_info.value.args[0]
116116

117117

118-
def test_driver_feather_read_backwards_compat(tmp_dir2):
118+
def test_driver_feather_read_backwards_compat(tmp_path: Path):
119119
import pandas as pd
120120

121121
df = pd.DataFrame({"x": [1, 2, 3]})
122122

123123
fname = "some_df"
124124
full_file = f"{fname}.feather"
125125

126-
df.to_feather(tmp_dir2 / full_file)
126+
df.to_feather(tmp_path / full_file)
127127

128128
obj = load_data(
129-
MetaRaw(full_file, "feather", "my_pin"), fsspec.filesystem("file"), tmp_dir2
129+
MetaRaw(full_file, "feather", "my_pin"), fsspec.filesystem("file"), tmp_path
130130
)
131131

132132
assert df.equals(obj)
@@ -148,15 +148,15 @@ def test_driver_pickle_read_fail_default(some_joblib):
148148
)
149149

150150

151-
def test_driver_apply_suffix_false(tmp_dir2):
151+
def test_driver_apply_suffix_false(tmp_path: Path):
152152
import pandas as pd
153153

154154
df = pd.DataFrame({"x": [1, 2, 3]})
155155

156156
fname = "some_df"
157157
type_ = "csv"
158158

159-
p_obj = tmp_dir2 / fname
159+
p_obj = tmp_path / fname
160160
res_fname = save_data(df, p_obj, type_, apply_suffix=False)
161161

162162
assert Path(res_fname).name == "some_df"

0 commit comments

Comments
 (0)