1414
1515from pandas import read_csv , concat
1616
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-
2717
2818class CustomFSPath (object ):
2919 """For testing fspath on unknown objects"""
@@ -34,6 +24,21 @@ def __fspath__(self):
3424 return self .path
3525
3626
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+
3742HERE = os .path .dirname (__file__ )
3843
3944
@@ -83,6 +88,19 @@ def test_stringify_path_fspath(self):
8388 result = common ._stringify_path (p )
8489 assert result == 'foo/bar.csv'
8590
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+
86104 def test_get_filepath_or_buffer_with_path (self ):
87105 filename = '~/sometest'
88106 filepath_or_buffer , _ , _ = common .get_filepath_or_buffer (filename )
0 commit comments