11import pickle
22from pathlib import Path
3+ from tempfile import TemporaryDirectory
34
45import pytest
56
@@ -44,30 +45,36 @@ def test_local_from_url():
4445 store = LocalStore .from_url (url )
4546
4647
47- def test_create_prefix (tmp_path : Path ):
48- tmpdir = tmp_path / "abc"
49- assert not tmpdir .exists ()
50- LocalStore (tmpdir , mkdir = True )
51- assert tmpdir .exists ()
48+ def test_create_prefix ():
49+ with TemporaryDirectory () as tmp :
50+ tmp_path = Path (tmp )
51+ tmpdir = tmp_path / "abc"
52+ assert not tmpdir .exists ()
53+ LocalStore (tmpdir , mkdir = True )
54+ assert tmpdir .exists ()
5255
53- # Assert that mkdir=True works even when the dir already exists
54- LocalStore (tmpdir , mkdir = True )
55- assert tmpdir .exists ()
56+ # Assert that mkdir=True works even when the dir already exists
57+ LocalStore (tmpdir , mkdir = True )
58+ assert tmpdir .exists ()
5659
5760
58- def test_prefix_property (tmp_path : Path ):
59- store = LocalStore (tmp_path )
60- assert store .prefix == tmp_path
61- assert isinstance (store .prefix , Path )
62- # Can pass it back to the store init
63- LocalStore (store .prefix )
61+ def test_prefix_property ():
62+ with TemporaryDirectory () as tmp :
63+ tmp_path = Path (tmp )
64+ store = LocalStore (tmp_path )
65+ assert store .prefix == tmp_path
66+ assert isinstance (store .prefix , Path )
67+ # Can pass it back to the store init
68+ LocalStore (store .prefix )
6469
6570
66- def test_pickle (tmp_path : Path ):
67- store = LocalStore (tmp_path )
68- store .put ("path.txt" , b"foo" )
69- new_store : LocalStore = pickle .loads (pickle .dumps (store ))
70- assert new_store .get ("path.txt" ).bytes () == b"foo"
71+ def test_pickle ():
72+ with TemporaryDirectory () as tmp :
73+ tmp_path = Path (tmp )
74+ store = LocalStore (tmp_path )
75+ store .put ("path.txt" , b"foo" )
76+ new_store : LocalStore = pickle .loads (pickle .dumps (store ))
77+ assert new_store .get ("path.txt" ).bytes () == b"foo"
7178
7279
7380def test_eq ():
@@ -79,18 +86,20 @@ def test_eq():
7986 assert store != store3
8087
8188
82- def test_local_store_percent_encoded (tmp_path : Path ):
83- fname1 = "hello%20world.txt"
84- content1 = b"Hello, World!"
85- with (tmp_path / fname1 ).open ("wb" ) as f :
86- f .write (content1 )
89+ def test_local_store_percent_encoded ():
90+ with TemporaryDirectory () as tmp :
91+ tmp_path = Path (tmp )
92+ fname1 = "hello%20world.txt"
93+ content1 = b"Hello, World!"
94+ with (tmp_path / fname1 ).open ("wb" ) as f :
95+ f .write (content1 )
8796
88- store = LocalStore (tmp_path )
89- assert store .get (fname1 ).bytes () == content1
97+ store = LocalStore (tmp_path )
98+ assert store .get (fname1 ).bytes () == content1
9099
91- fname2 = "hello world.txt"
92- content2 = b"Hello, World! (with spaces)"
93- with (tmp_path / fname2 ).open ("wb" ) as f :
94- f .write (content2 )
100+ fname2 = "hello world.txt"
101+ content2 = b"Hello, World! (with spaces)"
102+ with (tmp_path / fname2 ).open ("wb" ) as f :
103+ f .write (content2 )
95104
96- assert store .get (fname2 ).bytes () == content2
105+ assert store .get (fname2 ).bytes () == content2
0 commit comments