提交 84f2a37d 编写于 作者: C Cleber Rosa

selftests/unit/test_jobdata.py: employ a "assertful" approach

Let's make this test more in line with the unittest.TestCase style,
making use of the assertions, whose failures can be point us to the
exact location of the failure.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 3b5818dd
......@@ -14,78 +14,65 @@ class JobdataTest(unittest.TestCase):
def _check_results(self, dirname):
pth = os.path.join(BASEDIR, "selftests", ".data", dirname)
errs = []
# pwd
exp = "/home/medic/Work/Projekty/avocado/avocado"
act = jobdata.retrieve_pwd(pth)
if act != exp:
errs.append("pwd: '%s' '%s'" % (exp, act))
self.assertEqual(jobdata.retrieve_pwd(pth),
"/home/medic/Work/Projekty/avocado/avocado",
"pwd mismatch")
# references
exp = ["yes", "no"]
act = jobdata.retrieve_references(pth)
if act != exp:
errs.append("references: '%s' '%s'" % (exp, act))
self.assertEqual(jobdata.retrieve_references(pth),
["yes", "no"], "references mismatch")
# variants
try:
variants = jobdata.retrieve_variants(pth)
act = variants.to_str(0, 99)
except Exception as details:
errs.append("variants: Unable to retrieve: %s" % details)
else:
exp = ("\nVariant variant1-6ec4: /run/variant1\n"
" /run/variant1:foo => bar\n\n"
"Variant variant2-a6fe: /run/variant2\n"
" /run/variant2:foo => baz")
if not act or exp not in act:
errs.append("variants:\n%s\n\n%s" % (exp, act))
self.fail("variants: Unable to retrieve: %s" % details)
act = variants.to_str(0, 99)
self.assertTrue(act)
exp = ("\nVariant variant1-6ec4: /run/variant1\n"
" /run/variant1:foo => bar\n\n"
"Variant variant2-a6fe: /run/variant2\n"
" /run/variant2:foo => baz")
self.assertIn(exp, act, "variants mismatch")
# args
try:
args = jobdata.retrieve_args(pth)
except Exception as details:
errs.append("args: Unable to retrieve: %s" % details)
else:
if isinstance(args, dict):
for scenario in [["loaders", [u"external:/bin/echo"]],
["external_runner", u"/bin/echo"],
["failfast", False, None],
["ignore_missing_references", False, None],
["execution_order", "variants-per-test",
None]]:
act = args.get(scenario[0])
for exp in scenario[1:]:
if act == exp:
break
else:
errs.append("args: Invalid value '%s' of key '%s' "
"%s" % (act, scenario[0],
scenario[1:]))
else:
errs.append("args: Invalid args: %s" % args)
self.fail("args: Unable to retrieve: %s" % details)
self.assertTrue(isinstance(args, dict),
"args: Invalid args: %s" % args)
for scenario in [["loaders", [u"external:/bin/echo"]],
["external_runner", u"/bin/echo"],
["failfast", False, None],
["ignore_missing_references", False, None],
["execution_order", "variants-per-test",
None]]:
act = args.get(scenario[0])
self.assertIn(act, scenario[1:],
"args: Invalid value '%s' of key '%s' '%s'" % (
act, scenario[0], scenario[1:]))
# config
conf_path = jobdata.retrieve_config(pth)
if os.path.exists(conf_path):
exp = "[avocado.selftest]\njobdata = yes"
with open(conf_path, "r") as conf:
act = conf.read()
if exp not in act:
errs.append("config: Expected string\n%s\n\nNot in:\n%s"
% (exp, act))
else:
errs.append("config: Retrieved path '%s' does not exists"
% conf_path)
self.assertTrue(os.path.exists(conf_path),
"config: Retrieved path '%s' does not exists" %
conf_path)
exp = "[avocado.selftest]\njobdata = yes"
with open(conf_path, "r") as conf:
act = conf.read()
self.assertIn(exp, act,
"config: Expected string\n%s\n\nNot in:\n%s" % (
exp, act))
# cmdline
act = jobdata.retrieve_cmdline(pth)
exp = ['/usr/local/bin/avocado', 'run', '--external-runner',
'/bin/echo', '-m', 'examples/mux-0.yaml', '--', 'yes', 'no']
if exp != act:
errs.append("cmdline: Invalid cmdline '%s' (%s)" % (act, exp))
self.assertFalse(errs, "Errors: %s" % "\n ".join(errs))
self.assertEqual(exp, act,
"cmdline: Invalid cmdline '%s' (%s)" % (act, exp))
@unittest.skipIf(PY3, "Skipping tests with data pickled on Python 2")
def setUp(self):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册