...
 
Commits (4)
This diff is collapsed.
......@@ -42,13 +42,13 @@ from ..dataformat import DataFormat
from . import prefix
#----------------------------------------------------------
# ----------------------------------------------------------
def doit(format):
df = DataFormat(prefix, format)
assert df.valid, '\n * %s' % '\n * '.join(df.errors)
nose.tools.assert_true(df.valid, "\n * %s" % "\n * ".join(df.errors))
ftype = df.type
obj = ftype()
......@@ -56,55 +56,61 @@ def doit(format):
# checks JSON enconding
copy = ftype()
copy.from_dict(obj.as_dict())
assert copy.isclose(obj), "%r is not close enough to %r" % (copy.as_dict(), obj.as_dict())
nose.tools.assert_true(
copy.isclose(obj),
"%r is not close enough to %r" % (copy.as_dict(), obj.as_dict()),
)
# checks binary encoding
copy = ftype()
copy.unpack(obj.pack())
assert copy.isclose(obj), "%r is not close enough to %r" % (copy.as_dict(), obj.as_dict())
nose.tools.assert_true(
copy.isclose(obj),
"%r is not close enough to %r" % (copy.as_dict(), obj.as_dict()),
)
return obj
#----------------------------------------------------------
# ----------------------------------------------------------
def test_valid():
obj = doit('user/extended/1')
obj = doit("user/extended/1")
assert hasattr(obj, 'value')
assert isinstance(obj.value, numpy.int32)
assert hasattr(obj, 'value2')
assert isinstance(obj.value2, numpy.bool_)
nose.tools.assert_true(hasattr(obj, "value"))
nose.tools.assert_true(isinstance(obj.value, numpy.int32))
nose.tools.assert_true(hasattr(obj, "value2"))
nose.tools.assert_true(isinstance(obj.value2, numpy.bool_))
#----------------------------------------------------------
# ----------------------------------------------------------
def test_extension_of_extended():
obj = doit('user/extended2/1')
obj = doit("user/extended2/1")
assert hasattr(obj, 'value')
assert isinstance(obj.value, numpy.int32)
assert hasattr(obj, 'value2')
assert isinstance(obj.value2, numpy.bool_)
assert hasattr(obj, 'value3')
assert isinstance(obj.value3, numpy.float32)
nose.tools.assert_true(hasattr(obj, "value"))
nose.tools.assert_true(isinstance(obj.value, numpy.int32))
nose.tools.assert_true(hasattr(obj, "value2"))
nose.tools.assert_true(isinstance(obj.value2, numpy.bool_))
nose.tools.assert_true(hasattr(obj, "value3"))
nose.tools.assert_true(isinstance(obj.value3, numpy.float32))
#----------------------------------------------------------
# ----------------------------------------------------------
def test_issubclass():
first = DataFormat(prefix, 'user/single_integer/1')
assert first.valid, '\n * %s' % '\n * '.join(first.errors)
first = DataFormat(prefix, "user/single_integer/1")
nose.tools.assert_true(first.valid, "\n * %s" % "\n * ".join(first.errors))
middle = DataFormat(prefix, 'user/extended/1')
assert middle.valid, '\n * %s' % '\n * '.join(middle.errors)
middle = DataFormat(prefix, "user/extended/1")
nose.tools.assert_true(middle.valid, "\n * %s" % "\n * ".join(middle.errors))
last = DataFormat(prefix, 'user/extended2/1')
assert last.valid, '\n * %s' % '\n * '.join(last.errors)
last = DataFormat(prefix, "user/extended2/1")
nose.tools.assert_true(last.valid, "\n * %s" % "\n * ".join(last.errors))
assert first.isparent(middle)
assert middle.isparent(last)
assert first.isparent(last) #two hops
nose.tools.assert_true(first.isparent(middle))
nose.tools.assert_true(middle.isparent(last))
nose.tools.assert_true(first.isparent(last)) # two hops
......@@ -41,228 +41,228 @@ from ..dataformat import DataFormat
from . import prefix
#----------------------------------------------------------
# ----------------------------------------------------------
def doit(format, data):
df = DataFormat(prefix, format)
assert df.valid
nose.tools.assert_true(df.valid, df.errors)
obj = df.type()
obj.from_dict(data, casting='unsafe', add_defaults=False)
obj.from_dict(data, casting="unsafe", add_defaults=False)
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_integer():
doit('user/single_integer/1', {})
doit("user/single_integer/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_float():
doit('user/single_float/1', {})
doit("user/single_float/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_boolean():
doit('user/single_boolean/1', {})
doit("user/single_boolean/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_string():
doit('user/single_string/1', {})
doit("user/single_string/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_object():
doit('user/single_object/1', {})
doit("user/single_object/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_single_object_field():
doit('user/single_object/1', dict(obj={}))
doit("user/single_object/1", dict(obj={}))
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_hierarchy_of_objects():
doit('user/hierarchy_of_objects/1', dict(obj1=dict(obj2={})))
doit("user/hierarchy_of_objects/1", dict(obj1=dict(obj2={})))
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_hierarchy_of_objects_field():
doit('user/hierarchy_of_objects/1', dict(obj1=dict(obj2=dict(obj3={}))))
doit("user/hierarchy_of_objects/1", dict(obj1=dict(obj2=dict(obj3={}))))
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_1d_array_of_integers():
doit('user/empty_1d_array_of_integers/1', {})
doit("user/empty_1d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_2d_array_of_integers():
doit('user/empty_2d_array_of_integers/1', {})
doit("user/empty_2d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_3d_array_of_integers():
doit('user/empty_3d_array_of_integers/1', {})
doit("user/empty_3d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_1d_array_of_integers():
doit('user/1d_array_of_integers/1', {})
doit("user/1d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_2d_array_of_integers():
doit('user/2d_array_of_integers/1', {})
doit("user/2d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_3d_array_of_integers():
doit('user/3d_array_of_integers/1', {})
doit("user/3d_array_of_integers/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_1d_array_of_objects():
doit('user/empty_1d_array_of_objects/1', {})
doit("user/empty_1d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_1d_array_of_objects4():
doit('user/empty_1d_array_of_objects4/1', {})
doit("user/empty_1d_array_of_objects4/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_2d_array_of_objects():
doit('user/empty_2d_array_of_objects/1', {})
doit("user/empty_2d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_3d_array_of_objects():
doit('user/empty_3d_array_of_objects/1', {})
doit("user/empty_3d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_1d_array_of_objects():
doit('user/1d_array_of_objects/1', {})
doit("user/1d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_2d_array_of_objects():
doit('user/2d_array_of_objects/1', {})
doit("user/2d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_3d_array_of_objects():
doit('user/3d_array_of_objects/1', {})
doit("user/3d_array_of_objects/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_1d_array_of_dataformat():
doit('user/empty_1d_array_of_dataformat/1', {})
doit("user/empty_1d_array_of_dataformat/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_2d_array_of_dataformat():
doit('user/empty_2d_array_of_dataformat/1', {})
doit("user/empty_2d_array_of_dataformat/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_empty_3d_array_of_dataformat():
doit('user/empty_3d_array_of_dataformat/1', {})
doit("user/empty_3d_array_of_dataformat/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_1d_array_of_dataformat():
doit('user/1d_array_of_dataformat/1', {})
doit("user/1d_array_of_dataformat/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_2d_array_of_dataformat():
doit('user/2d_array_of_dataformat/1', {})
doit("user/2d_array_of_dataformat/1", {})
#----------------------------------------------------------
# ----------------------------------------------------------
@nose.tools.raises(AttributeError)
def test_3d_array_of_dataformat():
doit('user/3d_array_of_dataformat/1', {})
doit("user/3d_array_of_dataformat/1", {})
......@@ -40,80 +40,84 @@ import six
from .. import hash
#----------------------------------------------------------
# ----------------------------------------------------------
def test_path_from_username():
path = hash.toUserPath('johndoe')
path = hash.toUserPath("johndoe")
assert path is not None
assert isinstance(path, str)
assert len(path) > 0
nose.tools.assert_is_not_none(path)
nose.tools.assert_true(isinstance(path, str))
nose.tools.assert_true(len(path) > 0)
parts = path.split('/')
parts = path.split("/")
nose.tools.eq_(len(parts), 3)
for folder in parts[:-1]:
nose.tools.eq_(len(folder), 2)
nose.tools.eq_(parts[-1], 'johndoe')
nose.tools.eq_(parts[-1], "johndoe")
#----------------------------------------------------------
# ----------------------------------------------------------
def test_basic_hash():
nose.tools.eq_(hash._sha256('123456'),
'8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92')
nose.tools.eq_(
hash._sha256("123456"),
"8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92",
)
#----------------------------------------------------------
# ----------------------------------------------------------
def test_accented_hash():
if six.PY2:
ref = '4cb6985f5b4ec0ad4ce46904364f374194386426996a56683dc1c8d2944272ce'
ref = "4cb6985f5b4ec0ad4ce46904364f374194386426996a56683dc1c8d2944272ce"
else:
ref = '477993339861be6552873127471f9da6ae443991d5aced735f51140c34cd7599'
ref = "477993339861be6552873127471f9da6ae443991d5aced735f51140c34cd7599"
nose.tools.eq_(hash._sha256('áéçü'), ref)
nose.tools.eq_(hash._sha256("áéçü"), ref)
#----------------------------------------------------------
# ----------------------------------------------------------
def test_unicode_hash():
nose.tools.eq_(hash._sha256(u'áéçü'),
'477993339861be6552873127471f9da6ae443991d5aced735f51140c34cd7599')
nose.tools.eq_(
hash._sha256(u"áéçü"),
"477993339861be6552873127471f9da6ae443991d5aced735f51140c34cd7599",
)
#----------------------------------------------------------
# ----------------------------------------------------------
def test_dataset_hash():
h = hash.hashDataset('some_database/1', 'some_protocol',' some_set')
assert h is not None
assert isinstance(h, str)
assert len(h) > 0
h = hash.hashDataset("some_database/1", "some_protocol", " some_set")
nose.tools.assert_is_not_none(h)
nose.tools.assert_true(isinstance(h, str))
nose.tools.assert_true(len(h) > 0)
#----------------------------------------------------------
# ----------------------------------------------------------
def test_dataset_hash_repeatability():
h1 = hash.hashDataset('some_database/1', 'some_protocol',' some_set')
h2 = hash.hashDataset('some_database/1', 'some_protocol',' some_set')
h1 = hash.hashDataset("some_database/1", "some_protocol", " some_set")
h2 = hash.hashDataset("some_database/1", "some_protocol", " some_set")
nose.tools.eq_(h1, h2)
#----------------------------------------------------------
# ----------------------------------------------------------
def test_different_dataset_hashes():
h1 = hash.hashDataset('some_database/1', 'some_protocol',' some_set1')
h2 = hash.hashDataset('some_database/1', 'some_protocol',' some_set2')
assert h1 != h2, "%r != %r" % (h1, h2)
h1 = hash.hashDataset("some_database/1", "some_protocol", " some_set1")
h2 = hash.hashDataset("some_database/1", "some_protocol", " some_set2")
nose.tools.assert_not_equal(h1, h2, "%r != %r" % (h1, h2))
This diff is collapsed.