14
14
15
15
from pandas import read_csv , concat
16
16
17
- try :
18
- from pathlib import Path
19
- except ImportError :
20
- pass
21
-
22
- try :
23
- from py .path import local as LocalPath
24
- except ImportError :
25
- pass
26
-
27
17
28
18
class CustomFSPath (object ):
29
19
"""For testing fspath on unknown objects"""
@@ -34,6 +24,21 @@ def __fspath__(self):
34
24
return self .path
35
25
36
26
27
+ # Functions that consume a string path and return a string or path-like object
28
+ path_types = [str , CustomFSPath ]
29
+
30
+ try :
31
+ from pathlib import Path
32
+ path_types .append (Path )
33
+ except ImportError :
34
+ pass
35
+
36
+ try :
37
+ from py .path import local as LocalPath
38
+ path_types .append (LocalPath )
39
+ except ImportError :
40
+ pass
41
+
37
42
HERE = os .path .dirname (__file__ )
38
43
39
44
@@ -83,6 +88,19 @@ def test_stringify_path_fspath(self):
83
88
result = common ._stringify_path (p )
84
89
assert result == 'foo/bar.csv'
85
90
91
+ @pytest .mark .parametrize ('extension,expected' , [
92
+ ('' , None ),
93
+ ('.gz' , 'gzip' ),
94
+ ('.bz2' , 'bz2' ),
95
+ ('.zip' , 'zip' ),
96
+ ('.xz' , 'xz' ),
97
+ ])
98
+ @pytest .mark .parametrize ('path_type' , path_types )
99
+ def test_infer_compression_from_path (self , extension , expected , path_type ):
100
+ path = path_type ('foo/bar.csv' + extension )
101
+ compression = common ._infer_compression (path , compression = 'infer' )
102
+ assert compression == expected
103
+
86
104
def test_get_filepath_or_buffer_with_path (self ):
87
105
filename = '~/sometest'
88
106
filepath_or_buffer , _ , _ = common .get_filepath_or_buffer (filename )
0 commit comments