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

[test][algorithm_dependencies] Code cleanup

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