Commit 97ec6f07 authored by Mark Hymers's avatar Mark Hymers

Add more tests

Signed-off-by: Mark Hymers's avatarMark Hymers <mhy@debian.org>
parent 78c4a8a1
......@@ -408,7 +408,7 @@ class AbstractAnam(object):
# Write any additional data
for hname, val in self.extra_data.items():
if val is not None:
if isinstance(val, AbstractAnam):
if isinstance(val, AbstractAnam): # pragma: nocover
# Implement a simple setbit implementation to avoid
# infinite recursion where A wants to write B as a
# subobject and B wants to write A as a subobject
......@@ -436,12 +436,12 @@ class AbstractAnam(object):
try:
ret = cls()
except Exception, e:
except Exception, e: # pragma: nocover
raise StandardError("Failure creating class "
"%s (%s)" % (cls.get_hdf5name(), e))
# Check the class name against the group
if not ret.check_classname(subgroup.attrs['class']):
if not ret.check_classname(subgroup.attrs['class']): # pragma: nocover
raise ValueError('Subgroup specifies %s '
'instead of %s' % (subgroup.attrs['class'],
ret.get_hdf5name()))
......@@ -450,9 +450,6 @@ class AbstractAnam(object):
namemaps = {}
if 'namemaps' in subgroup.attrs.keys():
namemaps = dict(subgroup.attrs['namemaps'])
# Backwards compatibility
elif 'subgroupmap' in subgroup.attrs.keys():
namemaps = dict(subgroup.attrs['subgroupmap'])
# Deal with old-fashioned lists
lists = []
......@@ -586,7 +583,7 @@ class AbstractAnam(object):
honames[hname] = False
check = m.bcast(None, root=root)
if check != 'DATA':
if check != 'DATA': # pragma: nocover
raise StandardError('State machine error in MPI implementation; '
'recieved %s, expecting DATA' % check)
......@@ -609,7 +606,7 @@ class AbstractAnam(object):
# Read any additional data
check = m.bcast(None, root=root)
if check != 'ADDDATA':
if check != 'ADDDATA': # pragma: nocover
raise StandardError('State machine error in MPI implementation; '
'recieved %s, expecting ADDDATA' % check)
......@@ -660,7 +657,7 @@ class AbstractAnam(object):
# Check the class name against the group
# TODO: Deal with class aliases
if clsname != cls.get_hdf5name():
if clsname != cls.get_hdf5name(): # pragma: nocover
raise ValueError('MPI specifies %s '
'instead of %s' % (clsname,
cls.get_hdf5name()))
......
#!/usr/bin/python
# This file should be loaded during the register tests
from ..abstract import AbstractAnam
from ..register import register_class
class NameMapTestCase(AbstractAnam):
hdf5_outputs = ['_classvarname']
hdf5_mapnames = {'_classvarname': 'filevarname'}
def __init__(self):
AbstractAnam.__init__(self)
self._classvarname = 'foo'
__all__ = ['NameMapTestCase']
register_class(NameMapTestCase)
......@@ -97,6 +97,15 @@ class AbstractWritingTest(AnamTestBase):
b = self.read_it('test.hdf5', TestWriter)
assert((expected == b.dat))
def test_write_extra_data(self):
"""Check that we can save and restore extra data"""
a = TestWriter('nothing')
a.extra_data['foo'] = 1
self.write_it('test.hdf5', a)
b = self.read_it('test.hdf5', TestWriter)
assert('foo' in b.extra_data)
assert(b.extra_data['foo'] == 1)
def test_write_array_int8(self):
"""Check that we can save and restore a int8 numpy array"""
from numpy import array, int8
......@@ -997,3 +1006,35 @@ class AnamListTest(AnamTestBase):
a = AnamList(d)
assert(len(a.data) == 1)
class AnamNamemapTest(AnamTestBase):
def test_namemap_read(self):
"""Test use of namemap functionality from existing file"""
from ..abstract import obj_from_hdf5file
from .namemap_example import NameMapTestCase
n = obj_from_hdf5file(join(DATADIR, 'namemap_example.hdf5'))
assert(isinstance(n, NameMapTestCase))
assert(n._classvarname == 'foo')
def test_namemap_readwrite(self):
"""Test use of namemap functionality with new file"""
import h5py
from ..abstract import obj_from_hdf5file
from .namemap_example import NameMapTestCase
n = NameMapTestCase()
n._classvarname = 'fooblah'
f = h5py.File(join(self.tempdir, 'testnm.hdf5'), 'w')
n.to_hdf5(f.create_group('nmtest'))
f.close()
f = h5py.File(join(self.tempdir, 'testnm.hdf5'), 'r')
assert('filevarname' in f['nmtest'].attrs)
blah = NameMapTestCase.from_hdf5(f['nmtest'])
f.close()
assert(isinstance(n, NameMapTestCase))
assert(n._classvarname == 'fooblah')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment