Commit 988b5469 authored by Mark Hymers's avatar Mark Hymers

Add more tests

Signed-off-by: Mark Hymers's avatarMark Hymers <mhy@debian.org>
parent de0561d0
......@@ -398,7 +398,7 @@ class AbstractAnam(object):
# infinite recursion where A wants to write B as a
# subobject and B wants to write A as a subobject
id_obj = id(val)
if id_obj in seenit.keys():
if id_obj in seenit.keys(): # pragma: nocover
raise StandardError("Recursion detected in to_hdf5 "
"(object %s)" % a)
seenit[id_obj] = 1
......@@ -765,7 +765,7 @@ class AnamEmptyArray(AbstractAnam):
arr = cls()
# Check the class name against the group
if not arr.check_classname(subgroup.attrs['class']):
if not arr.check_classname(subgroup.attrs['class']): # pragma: nocover
raise ValueError('Subgroup specifies %s '
'instead of %s' % (subgroup.attrs['class'],
arr.get_hdf5name()))
......@@ -830,7 +830,7 @@ class AnamList(AbstractAnam):
"""
ret = []
if not subgroup.attrs[name + '_count']:
if not subgroup.attrs[name + '_count']: # pragma: nocover
raise StandardError("Malformed old-style list: "
"missing %s" % (name + '_count'))
......@@ -838,7 +838,7 @@ class AnamList(AbstractAnam):
for n in range(count):
sg = subgroup.get(name + str(n), None)
cls = find_class(sg.attrs['class'])
if not cls:
if not cls: # pragma: nocover
raise StandardError("Class %s missing reading item "
"%d for old-style list %s" %
(sg.attrs['class'], n, name))
......@@ -853,13 +853,13 @@ class AnamList(AbstractAnam):
ret = []
# Check the class name against the group
if not arr.check_classname(subgroup.attrs['class']):
if not arr.check_classname(subgroup.attrs['class']): # pragma: nocover
raise ValueError('Subgroup specifies %s instead '
'of %s' % (subgroup.attrs['class'],
arr.get_hdf5name()))
# Get number of elements
if 'count' not in subgroup.attrs:
if 'count' not in subgroup.attrs: # pragma: nocover
raise ValueError('Number of element missing')
cnt = subgroup.attrs['count']
......@@ -915,22 +915,22 @@ class AnamDict(AbstractAnam):
arr = cls()
# Check the class name against the group
if not arr.check_classname(subgroup.attrs['class']):
if not arr.check_classname(subgroup.attrs['class']): # pragma: nocover
raise ValueError('Subgroup specifies %s '
'instead of %s' % (subgroup.attrs['class'],
arr.get_hdf5name()))
# Get number of elements
if 'count' not in subgroup.attrs:
if 'count' not in subgroup.attrs: # pragma: nocover
raise ValueError('Number of elements missing')
cnt = subgroup.attrs['count']
# Get number of elements
if 'dictkeys' not in subgroup.keys():
if 'dictkeys' not in subgroup.keys(): # pragma: nocover
raise ValueError('Dictionary keys missing')
if 'dictdata' not in subgroup.keys():
if 'dictdata' not in subgroup.keys(): # pragma: nocover
raise ValueError('Dictionary data missing')
keys = parse_hdf5_value(subgroup, 'dictkeys',
......@@ -939,11 +939,11 @@ class AnamDict(AbstractAnam):
items = parse_hdf5_value(subgroup, 'dictdata',
None, subgroup['dictdata'])
if len(keys) != cnt:
if len(keys) != cnt: # pragma: nocover
raise ValueError("Incorrect number of keys found "
"(%d vs %d)" % (len(keys), cnt))
if len(items) != cnt:
if len(items) != cnt: # pragma: nocover
raise ValueError("Incorrect number of items found "
"(%d vs %d)" % (len(items), cnt))
......
......@@ -396,6 +396,14 @@ class AbstractWritingTest(AnamTestBase):
assert(isinstance(s, Store))
assert(s.extra_data['foo'] == 1)
def test_from_hdf5file(self):
"""Check that we can use from_hdf5file properly"""
from ..store import Store
s = Store.from_hdf5file(join(DATADIR, 'simplestore.hdf5'), 'store')
assert(isinstance(s, Store))
assert(s.extra_data['foo'] == 1)
def test_objfromhdf5file_wrongexplicitclass(self):
"""Check that we can't use obj_from_hdf5file with a the wrong explicit
name"""
......@@ -456,6 +464,16 @@ class AbstractWritingTest(AnamTestBase):
s = parse_hdf5_value(None, None, None, 'blah')
assert(s == 'blah')
def test_classname(self):
"""Check that we correctly check alias names"""
from ..abstract import AbstractAnam
class AliasNameTest(AbstractAnam):
hdf5_aliases = ['test.this.is.an.alias']
a = AliasNameTest()
assert(a.check_classname('test.this.is.an.alias'))
assert(not a.check_classname('test.this.is.not.an.alias'))
class AbstractCollectionTest(AnamTestBase):
def write_it(self, filename, dat):
......@@ -631,6 +649,9 @@ class AbstractCollectionTest(AnamTestBase):
assert('data2' in n._cache)
assert(n._cache['data1'].shape == (10, 1))
assert(n._cache['data2'].shape == (20, 1))
assert(len(n.keys()) == 2)
assert('data1' in n.keys())
assert('data2' in n.keys())
def test_update_cache_with_multiple_members(self):
"""Check that we can update our cache on a collection with multiple
......@@ -938,3 +959,41 @@ class AbstractCollectionTest(AnamTestBase):
assert(k == item2)
c += 1
assert(c == 2)
class AnamDictTest(AnamTestBase):
def test_create_anam_dict(self):
"""Test creation of anam dict"""
from ..abstract import AnamDict
d = {1: 1, 2: 2}
a = AnamDict(d)
assert(len(a.data.keys()) == 2)
def test_bad_create_anam_dict(self):
"""Test that we fail to create an AnamDict with bad data"""
from ..abstract import AnamDict
d = []
self.assertRaises(ValueError, AnamDict, d)
class AnamListTest(AnamTestBase):
def test_create_anam_list(self):
"""Test creation of anam list"""
from ..abstract import AnamList
d = [1, 2, 3]
a = AnamList(d)
assert(len(a.data) == 3)
d = None
a = AnamList(d)
assert(len(a.data) == 0)
d = 1
a = AnamList(d)
assert(len(a.data) == 1)
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