|
7 | 7 |
|
8 | 8 | import os
|
9 | 9 | import pytest
|
10 |
| -import functools |
11 | 10 | from itertools import product
|
12 | 11 |
|
13 | 12 | import pandas.util.testing as tm
|
14 | 13 | from pandas import DataFrame
|
15 | 14 | from pandas.io.parsers import read_csv, read_table
|
16 | 15 |
|
17 | 16 |
|
18 |
| -class TestCompressedUrl(object): |
| 17 | +@pytest.fixture(scope='module') |
| 18 | +def salaries_table(): |
| 19 | + path = os.path.join(tm.get_data_path(), 'salaries.csv') |
| 20 | + return read_table(path) |
19 | 21 |
|
20 |
| - compression_to_extension = { |
21 |
| - 'gzip': '.gz', |
22 |
| - 'bz2': '.bz2', |
23 |
| - 'zip': '.zip', |
24 |
| - 'xz': '.xz', |
25 |
| - } |
26 | 22 |
|
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') |
| 23 | +@tm.network |
| 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 | + # test reading compressed urls with various engines and |
| 29 | + # extension inference |
| 30 | + base_url = ('https://github.com/pandas-dev/pandas/raw/master/' |
| 31 | + 'pandas/tests/io/parser/data/salaries.csv') |
| 32 | + |
| 33 | + url = base_url + extension |
| 34 | + |
| 35 | + # args is a (compression, engine) tuple |
| 36 | + for (c, engine) in product([compression, 'infer'], ['python', 'c']): |
32 | 37 |
|
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): |
50 | 38 | if url.endswith('.xz'):
|
51 | 39 | 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) |
| 40 | + |
| 41 | + url_table = read_table(url, compression=c, engine=engine) |
| 42 | + tm.assert_frame_equal(url_table, salaries_table) |
54 | 43 |
|
55 | 44 |
|
56 | 45 | class TestS3(tm.TestCase):
|
|
0 commit comments