44import warnings
55
66import pytest
7+ from fsspec .registry import get_filesystem_class
78
89from upath import UPath
10+ from upath .tests .cases import BaseTests
911
1012
1113@pytest .mark .skipif (
@@ -31,212 +33,18 @@ def test_UPath_warning():
3133 assert "mock" in str (w [- 1 ].message )
3234
3335
34- class TestUpath :
36+
37+ class TestUpath (BaseTests ):
38+
3539 @pytest .fixture (autouse = True )
3640 def path (self , local_testdir ):
3741 with warnings .catch_warnings ():
3842 warnings .simplefilter ("ignore" )
3943 self .path = UPath (f"mock:{ local_testdir } " )
4044
41- def test_cwd (self ):
42- with pytest .raises (NotImplementedError ):
43- self .path .cwd ()
44-
45- def test_home (self ):
46- with pytest .raises (NotImplementedError ):
47- self .path .home ()
48-
49- def test_stat (self ):
50- stat = self .path .stat ()
51- assert stat
52-
53- def test_chmod (self ):
54- with pytest .raises (NotImplementedError ):
55- self .path .joinpath ("file1.txt" ).chmod (777 )
56-
57- @pytest .mark .parametrize (
58- "url, expected" , [("file1.txt" , True ), ("fakefile.txt" , False )]
59- )
60- def test_exists (self , url , expected ):
61- path = self .path .joinpath (url )
62- assert path .exists () == expected
63-
64- def test_expanduser (self ):
65- with pytest .raises (NotImplementedError ):
66- self .path .expanduser ()
67-
68- def test_glob (self , pathlib_base ):
69- mock_glob = list (self .path .glob ("**.txt" ))
70- path_glob = list (pathlib_base .glob ("**/*.txt" ))
71-
72- assert len (mock_glob ) == len (path_glob )
73- assert all (
74- map (
75- lambda m : m .path
76- in [str (p ).replace ("\\ " , "/" ) for p in path_glob ],
77- mock_glob ,
78- )
79- )
80-
81- def test_group (self ):
82- with pytest .raises (NotImplementedError ):
83- self .path .group ()
84-
85- def test_is_dir (self ):
86- assert self .path .is_dir ()
87-
88- path = self .path .joinpath ("file1.txt" )
89- assert not path .is_dir ()
90-
91- def test_is_file (self ):
92- path = self .path .joinpath ("file1.txt" )
93- assert path .is_file ()
94- assert not self .path .is_file ()
95-
96- def test_is_mount (self ):
97- with pytest .raises (NotImplementedError ):
98- self .path .is_mount ()
99-
100- def test_is_symlink (self ):
101- with pytest .raises (NotImplementedError ):
102- self .path .is_symlink ()
103-
104- def test_is_socket (self ):
105- with pytest .raises (NotImplementedError ):
106- self .path .is_socket ()
107-
108- def test_is_fifo (self ):
109- with pytest .raises (NotImplementedError ):
110- self .path .is_fifo ()
111-
112- def test_is_block_device (self ):
113- with pytest .raises (NotImplementedError ):
114- self .path .is_block_device ()
115-
116- def test_is_char_device (self ):
117- with pytest .raises (NotImplementedError ):
118- self .path .is_char_device ()
119-
120- def test_iterdir (self , local_testdir ):
121- pl_path = Path (local_testdir )
122-
123- up_iter = list (self .path .iterdir ())
124- pl_iter = list (pl_path .iterdir ())
125-
126- assert len (up_iter ) == len (pl_iter )
127- pnames = [p .name for p in pl_iter ]
128- assert all (map (lambda x : x .name in pnames , up_iter ))
129-
130- def test_lchmod (self ):
131- with pytest .raises (NotImplementedError ):
132- self .path .lchmod (mode = 77 )
133-
134- def test_lstat (self ):
135- with pytest .raises (NotImplementedError ):
136- self .path .lstat ()
137-
138- def test_mkdir (self ):
139- new_dir = self .path .joinpath ("new_dir" )
140- new_dir .mkdir ()
141- assert new_dir .exists ()
142-
143- def test_open (self ):
45+ def test_fsspec_compat (self ):
14446 pass
14547
146- def test_owner (self ):
147- with pytest .raises (NotImplementedError ):
148- self .path .owner ()
149-
150- def test_read_bytes (self , pathlib_base ):
151- mock = self .path .joinpath ("file2.txt" )
152- pl = pathlib_base .joinpath ("file2.txt" )
153- assert mock .read_bytes () == pl .read_bytes ()
154-
155- def test_read_text (self , local_testdir ):
156- upath = self .path .joinpath ("file1.txt" )
157- assert (
158- upath .read_text ()
159- == Path (local_testdir ).joinpath ("file1.txt" ).read_text ()
160- )
161-
162- def test_readlink (self ):
163- with pytest .raises (NotImplementedError ):
164- self .path .readlink ()
165-
166- @pytest .mark .xfail
167- def test_rename (self ):
168- # need to impliment
169- raise False
170-
171- def test_replace (self ):
172- pass
173-
174- def test_resolve (self ):
175- pass
176-
177- def test_rglob (self ):
178- pass
179-
180- def test_samefile (self ):
181- pass
182-
183- def test_symlink_to (self ):
184- pass
185-
186- def test_touch_unlink (self ):
187- path = self .path .joinpath ("test_touch.txt" )
188- path .touch ()
189- assert path .exists ()
190- path .unlink ()
191- assert not path .exists ()
192-
193- # should raise FileNotFoundError since file is missing
194- with pytest .raises (FileNotFoundError ):
195- path .unlink ()
196-
197- # file doesn't exists, but missing_ok is True
198- path .unlink (missing_ok = True )
199-
200- def test_link_to (self ):
201- pass
202-
203- def test_write_bytes (self , pathlib_base ):
204- fn = "test_write_bytes.txt"
205- s = b"hello_world"
206- path = self .path .joinpath (fn )
207- path .write_bytes (s )
208- assert path .read_bytes () == s
209-
210- def test_write_text (self , pathlib_base ):
211- fn = "test_write_text.txt"
212- s = "hello_world"
213- path = self .path .joinpath (fn )
214- path .write_text (s )
215- assert path .read_text () == s
216-
217- def prepare_file_system (self ):
218- self .make_top_folder ()
219- self .make_test_files ()
220-
221- def make_top_folder (self ):
222- self .path .mkdir (parents = True , exist_ok = True )
223-
224- def make_test_files (self ):
225- folder1 = self .path .joinpath ("folder1" )
226- folder1 .mkdir (exist_ok = True )
227- folder1_files = ["file1.txt" , "file2.txt" ]
228- for f in folder1_files :
229- p = folder1 .joinpath (f )
230- p .touch ()
231- p .write_text (f )
232-
233- file1 = self .path .joinpath ("file1.txt" )
234- file1 .touch ()
235- file1 .write_text ("hello world" )
236- file2 = self .path .joinpath ("file2.txt" )
237- file2 .touch ()
238- file2 .write_bytes (b"hello world" )
239-
24048
24149@pytest .mark .hdfs
24250def test_multiple_backend_paths (local_testdir , s3 , hdfs ):
0 commit comments