Skip to content

Commit 896812d

Browse files
committed
TST: fix incorrect url in compressed url network tests in parser
1 parent 4b97db4 commit 896812d

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

pandas/tests/io/parser/test_network.py

+25-31
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,36 @@
1515
from pandas.io.parsers import read_csv, read_table
1616

1717

18-
class TestCompressedUrl(object):
18+
@pytest.fixture(scope='module')
19+
def salaries_table():
20+
path = os.path.join(tm.get_data_path(), 'salaries.csv')
21+
return read_table(path)
1922

20-
compression_to_extension = {
21-
'gzip': '.gz',
22-
'bz2': '.bz2',
23-
'zip': '.zip',
24-
'xz': '.xz',
25-
}
2623

27-
def setup(self):
28-
path = os.path.join(tm.get_data_path(), 'salaries.csv')
29-
self.local_table = read_table(path)
30-
self.base_url = ('https://github.com/pandas-dev/pandas/raw/master/'
31-
'pandas/io/tests/parser/data/salaries.csv')
24+
@pytest.mark.parametrize(
25+
"compression,extension", [('gzip', '.gz'), ('bz2', '.bz2'),
26+
('zip', '.zip'), ('xz', '.xz')])
27+
def test_compressed_urls(salaries_table, compression, extension):
28+
check_compressed_urls(salaries_table, compression, extension)
29+
30+
31+
@tm.network
32+
def check_compressed_urls(salaries_table, compression, extension):
33+
# test reading compressed urls with various engines and
34+
# extension inference
35+
base_url = ('https://github.com/pandas-dev/pandas/raw/master/'
36+
'pandas/tests/io/parser/data/salaries.csv')
37+
38+
url = base_url + extension
39+
40+
# args is a (compression, engine) tuple
41+
for (c, engine) in product([compression, 'infer'], ['python', 'c']):
3242

33-
@tm.network
34-
def test_compressed_urls(self):
35-
# Test reading compressed tables from URL.
36-
msg = ('Test reading {}-compressed tables from URL: '
37-
'compression="{}", engine="{}"')
38-
39-
for compression, extension in self.compression_to_extension.items():
40-
url = self.base_url + extension
41-
# args is a (compression, engine) tuple
42-
for args in product([compression, 'infer'], ['python', 'c']):
43-
# test_fxn is a workaround for more descriptive nose reporting.
44-
# See http://stackoverflow.com/a/37393684/4651668.
45-
test_fxn = functools.partial(self.check_table)
46-
test_fxn.description = msg.format(compression, *args)
47-
yield (test_fxn, url) + args
48-
49-
def check_table(self, url, compression, engine):
5043
if url.endswith('.xz'):
5144
tm._skip_if_no_lzma()
52-
url_table = read_table(url, compression=compression, engine=engine)
53-
tm.assert_frame_equal(url_table, self.local_table)
45+
46+
url_table = read_table(url, compression=c, engine=engine)
47+
tm.assert_frame_equal(url_table, salaries_table)
5448

5549

5650
class TestS3(tm.TestCase):

0 commit comments

Comments
 (0)