88
99
1010import pytest
11- from fsspec import filesystem
1211from fsspec .implementations .local import LocalFileSystem
1312from fsspec .registry import (
1413 register_implementation ,
1514 _registry
1615)
1716
1817
18+ def pytest_addoption (parser ):
19+ parser .addoption (
20+ "--skiphdfs" ,
21+ action = "store_true" ,
22+ default = False ,
23+ help = "skip hdfs tests"
24+ )
25+
26+
27+ def pytest_configure (config ):
28+ config .addinivalue_line ("markers" , "hdfs: mark test as hdfs" )
29+
30+
31+ def pytest_collection_modifyitems (config , items ):
32+ if not config .getoption ("--skiphdfs" ):
33+ return
34+ skip_hdfs = pytest .mark .skip (reason = "skipping hdfs" )
35+ for item in items :
36+ if "hdfs" in item .keywords :
37+ item .add_marker (skip_hdfs )
38+
39+
1940class DummyTestFS (LocalFileSystem ):
2041 protocol = "mock"
2142
@@ -28,25 +49,16 @@ def clear_registry():
2849 finally :
2950 _registry .clear ()
3051
31-
32- # folder_structure = {
33- # 'folders': {'folder1': {'folders': {},
34- # 'files': {'file1.txt': 'file1.txt',
35- # 'file2.txt': 'file2.txt'}}
36- # 'files': {'file1.txt': 'hello_world',
37- # 'file2.txt': 'hello_world'}
38-
39-
40- # }
4152
4253@pytest .fixture ()
4354def tempdir (clear_registry ):
4455 tempdir = tempfile .TemporaryDirectory ()
4556 tempdir = tempdir .name
4657 return tempdir
4758
59+
4860@pytest .fixture ()
49- def local_testdir (tempdir , clear_registry ):
61+ def local_testdir (tempdir , clear_registry ):
5062 tmp = Path (tempdir )
5163 tmp .mkdir ()
5264 folder1 = tmp .joinpath ('folder1' )
@@ -66,26 +78,28 @@ def local_testdir(tempdir, clear_registry):
6678 yield tempdir
6779 shutil .rmtree (tempdir )
6880
81+
6982@pytest .fixture (scope = 'session' )
7083def htcluster ():
7184 proc = subprocess .Popen (shlex .split ("htcluster startup" ),
72- stderr = subprocess .DEVNULL , stdout = subprocess .DEVNULL )
85+ stderr = subprocess .DEVNULL ,
86+ stdout = subprocess .DEVNULL )
7387 time .sleep (30 )
7488 yield
7589 proc .terminate ()
7690 proc .wait ()
7791 proc1 = subprocess .Popen (shlex .split ("htcluster shutdown" ),
78- stderr = subprocess .DEVNULL , stdout = subprocess .DEVNULL )
92+ stderr = subprocess .DEVNULL ,
93+ stdout = subprocess .DEVNULL )
7994 proc1 .terminate ()
8095 proc1 .wait ()
8196 time .sleep (10 )
82-
97+
98+
8399@pytest .fixture ()
84100def hdfs (htcluster , tempdir , local_testdir ):
85-
86101 pyarrow = pytest .importorskip ('pyarrow' )
87102 host , user , port = '0.0.0.0' , 'hdfs' , 9000
88- #hdfs = filesystem('hdfs', host=host, user=user, port=port, driver='libhdfs3')
89103 hdfs = pyarrow .hdfs .connect (host = '0.0.0.0' , port = 9000 , user = user )
90104 hdfs .mkdir (tempdir , create_parents = True )
91105 for x in Path (local_testdir ).glob ('**/*' ):
@@ -96,10 +110,10 @@ def hdfs(htcluster, tempdir, local_testdir):
96110 with hdfs .open (str (x ), 'wb' ) as f :
97111 f .write (text )
98112 else :
99- hdfs .mkdir (str (x ))
113+ hdfs .mkdir (str (x ))
100114 hdfs .close ()
101115 yield host , user , port
102-
116+
103117
104118@pytest .fixture (scope = 'session' )
105119def s3_server ():
@@ -131,8 +145,7 @@ def s3_server():
131145 time .sleep (0.1 ) # pragma: no cover
132146 anon = False
133147 s3so = dict (client_kwargs = {'endpoint_url' : endpoint_uri },
134- use_listings_cache = False )
135-
148+ use_listings_cache = False )
136149 yield anon , s3so
137150 proc .terminate ()
138151 proc .wait ()
0 commit comments