Skip to content

TST: remove yielding tests from test_msgpacks.py #15427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@
_ZLIB_INSTALLED = True


@pytest.fixture(scope='module')
def current_packers_data():
# our current version packers data
from pandas.tests.io.generate_legacy_storage_files import (
create_msgpack_data)
return create_msgpack_data()


@pytest.fixture(scope='module')
def all_packers_data():
# our all of our current version packers data
from pandas.tests.io.generate_legacy_storage_files import (
create_data)
return create_data()


def check_arbitrary(a, b):

if isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)):
Expand Down Expand Up @@ -778,7 +794,16 @@ def test_default_encoding(self):
assert_frame_equal(result, frame)


class TestMsgpack():
def legacy_packers_versions():
# yield the packers versions
path = tm.get_data_path('legacy_msgpack')
for v in os.listdir(path):
p = os.path.join(path, v)
if os.path.isdir(p):
yield v


class TestMsgpack(object):
"""
How to add msgpack tests:

Expand All @@ -788,48 +813,38 @@ class TestMsgpack():
$ python generate_legacy_storage_files.py <output_dir> msgpack

3. Move the created pickle to "data/legacy_msgpack/<version>" directory.

NOTE: TestMsgpack can't be a subclass of tm.Testcase to use test generator.
http://stackoverflow.com/questions/6689537/nose-test-generators-inside-class
"""

@classmethod
def setup_class(cls):
from pandas.tests.io.generate_legacy_storage_files import (
create_msgpack_data, create_data)
cls.data = create_msgpack_data()
cls.all_data = create_data()
cls.path = u('__%s__.msgpack' % tm.rands(10))
cls.minimum_structure = {'series': ['float', 'int', 'mixed',
'ts', 'mi', 'dup'],
'frame': ['float', 'int', 'mixed', 'mi'],
'panel': ['float'],
'index': ['int', 'date', 'period'],
'mi': ['reg2']}

def check_min_structure(self, data):
minimum_structure = {'series': ['float', 'int', 'mixed',
'ts', 'mi', 'dup'],
'frame': ['float', 'int', 'mixed', 'mi'],
'panel': ['float'],
'index': ['int', 'date', 'period'],
'mi': ['reg2']}

def check_min_structure(self, data, version):
for typ, v in self.minimum_structure.items():
assert typ in data, '"{0}" not found in unpacked data'.format(typ)
for kind in v:
msg = '"{0}" not found in data["{1}"]'.format(kind, typ)
assert kind in data[typ], msg

def compare(self, vf, version):
def compare(self, current_data, all_data, vf, version):
# GH12277 encoding default used to be latin-1, now utf-8
if LooseVersion(version) < '0.18.0':
data = read_msgpack(vf, encoding='latin-1')
else:
data = read_msgpack(vf)
self.check_min_structure(data)
self.check_min_structure(data, version)
for typ, dv in data.items():
assert typ in self.all_data, ('unpacked data contains '
'extra key "{0}"'
.format(typ))
assert typ in all_data, ('unpacked data contains '
'extra key "{0}"'
.format(typ))
for dt, result in dv.items():
assert dt in self.all_data[typ], ('data["{0}"] contains extra '
'key "{1}"'.format(typ, dt))
assert dt in current_data[typ], ('data["{0}"] contains extra '
'key "{1}"'.format(typ, dt))
try:
expected = self.data[typ][dt]
expected = current_data[typ][dt]
except KeyError:
continue

Expand Down Expand Up @@ -862,9 +877,11 @@ def compare_frame_dt_mixed_tzs(self, result, expected, typ, version):
else:
tm.assert_frame_equal(result, expected)

def read_msgpacks(self, version):
@pytest.mark.parametrize('version', legacy_packers_versions())
def test_msgpacks_legacy(self, current_packers_data, all_packers_data,
version):

pth = tm.get_data_path('legacy_msgpack/{0}'.format(str(version)))
pth = tm.get_data_path('legacy_msgpack/{0}'.format(version))
n = 0
for f in os.listdir(pth):
# GH12142 0.17 files packed in P2 can't be read in P3
Expand All @@ -873,19 +890,10 @@ def read_msgpacks(self, version):
continue
vf = os.path.join(pth, f)
try:
self.compare(vf, version)
self.compare(current_packers_data, all_packers_data,
vf, version)
except ImportError:
# blosc not installed
continue
n += 1
assert n > 0, 'Msgpack files are not tested'

def test_msgpack(self):
msgpack_path = tm.get_data_path('legacy_msgpack')
n = 0
for v in os.listdir(msgpack_path):
pth = os.path.join(msgpack_path, v)
if os.path.isdir(pth):
yield self.read_msgpacks, v
n += 1
assert n > 0, 'Msgpack files are not tested'
8 changes: 4 additions & 4 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def compare_sp_frame_float(result, expected, typ, version):
# ---------------------
def legacy_pickle_versions():
# yield the pickle versions
pickle_path = tm.get_data_path('legacy_pickle')
for v in os.listdir(pickle_path):
pth = os.path.join(pickle_path, v)
if os.path.isdir(pth):
path = tm.get_data_path('legacy_pickle')
for v in os.listdir(path):
p = os.path.join(path, v)
if os.path.isdir(p):
yield v


Expand Down