Commit 95c6787a authored by Samuel GAIST's avatar Samuel GAIST

[test][algorithm_dependencies] Code cleanup

parent 8a3e9811
...@@ -38,25 +38,25 @@ import nose.tools ...@@ -38,25 +38,25 @@ import nose.tools
from ..algorithm import Algorithm, Storage from ..algorithm import Algorithm, Storage
from ..library import Library, Storage as LibraryStorage from ..library import Library, Storage as LibraryStorage
from ..dataformat import DataFormat, Storage as DataFormatStorage from ..dataformat import Storage as DataFormatStorage
from . import prefix, tmp_prefix from . import prefix, tmp_prefix
from .utils import cleanup from .utils import cleanup
def copy_objects(algo, lib): def copy_objects(algorithm, library):
a = Algorithm(prefix, algo) alg = Algorithm(prefix, algorithm)
storage = Storage(tmp_prefix, a.name) storage = Storage(tmp_prefix, alg.name)
a.write(storage) alg.write(storage)
for d in a.dataformats: for dataformat in alg.dataformats:
storage = DataFormatStorage(tmp_prefix, d) storage = DataFormatStorage(tmp_prefix, dataformat)
a.dataformats[d].write(storage) alg.dataformats[dataformat].write(storage)
l = Library(prefix, lib) lib = Library(prefix, library)
storage = LibraryStorage(tmp_prefix, l.name) storage = LibraryStorage(tmp_prefix, lib.name)
l.write(storage) lib.write(storage)
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(teardown=cleanup)
...@@ -66,43 +66,43 @@ def test_dependencies(): ...@@ -66,43 +66,43 @@ def test_dependencies():
copy_objects(name, dep_name) copy_objects(name, dep_name)
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert a.valid, "\n * %s" % "\n * ".join(a.errors) nose.tools.assert_true(alg.valid, "\n * %s" % "\n * ".join(alg.errors))
nose.tools.eq_(len(a.uses), 0) nose.tools.eq_(len(alg.uses), 0)
nose.tools.eq_(len(a.libraries), 0) nose.tools.eq_(len(alg.libraries), 0)
l_dep = Library(tmp_prefix, dep_name) l_dep = Library(tmp_prefix, dep_name)
assert l_dep.valid, "\n * %s" % "\n * ".join(l_dep.errors) nose.tools.assert_true(l_dep.valid, "\n * %s" % "\n * ".join(l_dep.errors))
# check modification # check modification
a.uses["dep1"] = dep_name alg.uses["dep1"] = dep_name
a.write() alg.write()
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert a.valid, "\n * %s" % "\n * ".join(a.errors) nose.tools.assert_true(alg.valid, "\n * %s" % "\n * ".join(alg.errors))
nose.tools.eq_(len(a.uses), 1) nose.tools.eq_(len(alg.uses), 1)
nose.tools.eq_(len(a.libraries), 1) nose.tools.eq_(len(alg.libraries), 1)
nose.tools.eq_(list(a.uses.keys())[0], "dep1") nose.tools.eq_(list(alg.uses.keys())[0], "dep1")
nose.tools.eq_(list(a.uses.values())[0], "user/dep/1") nose.tools.eq_(list(alg.uses.values())[0], "user/dep/1")
a.uses = {} alg.uses = {}
a.uses["mod1"] = dep_name alg.uses["mod1"] = dep_name
a.write() alg.write()
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert a.valid, "\n * %s" % "\n * ".join(a.errors) nose.tools.assert_true(alg.valid, "\n * %s" % "\n * ".join(alg.errors))
nose.tools.eq_(len(a.uses), 1) nose.tools.eq_(len(alg.uses), 1)
nose.tools.eq_(len(a.libraries), 1) nose.tools.eq_(len(alg.libraries), 1)
nose.tools.eq_(list(a.uses.keys())[0], "mod1") nose.tools.eq_(list(alg.uses.keys())[0], "mod1")
nose.tools.eq_(list(a.uses.values())[0], "user/dep/1") nose.tools.eq_(list(alg.uses.values())[0], "user/dep/1")
a.uses = {} alg.uses = {}
a.write() alg.write()
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert a.valid, "\n * %s" % "\n * ".join(a.errors) nose.tools.assert_true(alg.valid, "\n * %s" % "\n * ".join(alg.errors))
nose.tools.eq_(len(a.uses), 0) nose.tools.eq_(len(alg.uses), 0)
nose.tools.eq_(len(a.libraries), 0) nose.tools.eq_(len(alg.libraries), 0)
@nose.tools.with_setup(teardown=cleanup) @nose.tools.with_setup(teardown=cleanup)
...@@ -113,16 +113,16 @@ def test_invalid_dependencies(): ...@@ -113,16 +113,16 @@ def test_invalid_dependencies():
copy_objects(name, dep_name) copy_objects(name, dep_name)
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert a.valid, "\n * %s" % "\n * ".join(a.errors) nose.tools.assert_true(alg.valid, "\n * %s" % "\n * ".join(alg.errors))
nose.tools.eq_(len(a.uses), 0) nose.tools.eq_(len(alg.uses), 0)
nose.tools.eq_(len(a.libraries), 0) nose.tools.eq_(len(alg.libraries), 0)
l_dep = Library(tmp_prefix, "user/invalid_dep/1") l_dep = Library(tmp_prefix, "user/invalid_dep/1")
assert l_dep.valid, "\n * %s" % "\n * ".join(l_dep.errors) nose.tools.assert_true(l_dep.valid, "\n * %s" % "\n * ".join(l_dep.errors))
a.uses["dep"] = dep_name alg.uses["dep"] = dep_name
a.write() alg.write()
a = Algorithm(tmp_prefix, name) alg = Algorithm(tmp_prefix, name)
assert not a.valid nose.tools.assert_false(alg.valid)
assert a.errors[0].find("differs from current language") != -1 nose.tools.assert_not_equal(alg.errors[0].find("differs from current language"), -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