Commit af761d30 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[test][format_composed] Code cleanup

parent 08bd88c1
......@@ -34,8 +34,6 @@
###################################################################################
import os
import numpy
import nose.tools
......@@ -47,16 +45,16 @@ from . import prefix
def test_valid():
df = DataFormat(prefix, "user/composed/1")
assert df.valid
nose.tools.assert_true(df.valid)
ftype = df.type
assert numpy.issubdtype(ftype.integers.value8, numpy.int8)
assert numpy.issubdtype(ftype.integers.value16, numpy.int16)
assert numpy.issubdtype(ftype.integers.value32, numpy.int32)
assert numpy.issubdtype(ftype.integers.value64, numpy.int64)
assert numpy.issubdtype(ftype.floats.value32, numpy.float32)
assert numpy.issubdtype(ftype.floats.value64, numpy.float64)
nose.tools.assert_true(numpy.issubdtype(ftype.integers.value8, numpy.int8))
nose.tools.assert_true(numpy.issubdtype(ftype.integers.value16, numpy.int16))
nose.tools.assert_true(numpy.issubdtype(ftype.integers.value32, numpy.int32))
nose.tools.assert_true(numpy.issubdtype(ftype.integers.value64, numpy.int64))
nose.tools.assert_true(numpy.issubdtype(ftype.floats.value32, numpy.float32))
nose.tools.assert_true(numpy.issubdtype(ftype.floats.value64, numpy.float64))
obj = ftype(
integers=dict(
......@@ -81,31 +79,31 @@ def test_valid():
nose.tools.eq_(obj.integers.value64, 2 ** 62)
nose.tools.eq_(obj.floats.value32.dtype, numpy.float32)
assert numpy.isclose(obj.floats.value32, 3.14)
nose.tools.assert_true(numpy.isclose(obj.floats.value32, 3.14))
nose.tools.eq_(obj.floats.value64.dtype, numpy.float64)
assert numpy.isclose(obj.floats.value64, 2.78)
nose.tools.assert_true(numpy.isclose(obj.floats.value64, 2.78))
# 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()),
)
def test_invalid():
df = DataFormat(prefix, "user/composed_unknown/1")
assert df.valid is False
assert df.errors[0].find("referred dataformat") != -1
assert df.errors[0].find("invalid") != -1
nose.tools.assert_false(df.valid)
nose.tools.assert_not_equal(df.errors[0].find("referred dataformat"), -1)
nose.tools.assert_not_equal(df.errors[0].find("invalid"), -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