diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-10-08 12:19:00 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-10-09 12:23:37 -0700 |
commit | 942928623ee7208a07ab1f5da953e627c18cc5fd (patch) | |
tree | 8fe6f7f13dfc2b70b67dbf7898857e202c39f75a | |
parent | 6986bc53b64de1a91c2fc2b9fe9f9b5f61a683dd (diff) |
framework/tests/results_tests.py: add new method for dict-like objects
This adds a dictionary assert that is similar to assert_dict_equal, but
it calls dict() on each object before comparing them. This allows
dictionary like objects (like Subtest) to be compared with the powerful
nose tools.
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r-- | framework/tests/results_tests.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py index d35cfa387..8128b384c 100644 --- a/framework/tests/results_tests.py +++ b/framework/tests/results_tests.py @@ -29,6 +29,15 @@ from framework import results, status, exceptions, grouptools import framework.tests.utils as utils +def dict_eq(one, two): + """Assert two dict-like objects are equal. + + Casts to dict, and then uses nose.tools.assert_dict_equal. + + """ + nt.assert_dict_equal(dict(one), dict(two)) + + @utils.nose_generator def test_generate_initialize(): """ Generator that creates tests to initialize all of the classes in core @@ -79,7 +88,7 @@ def test_Subtests_from_dict(): test = results.Subtests.from_dict(baseline.to_json()) - nt.assert_dict_equal(baseline, test) + dict_eq(baseline, test) def test_Subtests_from_dict_instance(): @@ -386,7 +395,7 @@ class TestTestrunResultTotals(object): root['crash'] += 1 root['skip'] += 1 - nt.assert_dict_equal(self.test['root'], root) + dict_eq(self.test['root'], root) def test_recurse(self): """results.TestrunResult.totals: Recurses correctly""" @@ -394,14 +403,14 @@ class TestTestrunResultTotals(object): expected['fail'] += 1 expected['crash'] += 1 expected['skip'] += 1 - nt.assert_dict_equal(self.test['foo'], expected) + dict_eq(self.test['foo'], expected) def test_two_parents(self): """results.TestrunResult.totals: Handles multiple parents correctly""" expected = results.Totals() expected['crash'] += 1 expected['skip'] += 1 - nt.assert_dict_equal(self.test[grouptools.join('foo', 'foo')], expected) + dict_eq(self.test[grouptools.join('foo', 'foo')], expected) class TestTestrunResultTotalsSubtests(object): @@ -425,7 +434,7 @@ class TestTestrunResultTotalsSubtests(object): expect['pass'] += 1 expect['crash'] += 1 expect['fail'] += 1 - nt.assert_dict_equal(self.test['root'], expect) + dict_eq(self.test['root'], expect) def test_node(self): """results.TestrunResult.totals: Tests with subtests are treated as groups""" @@ -439,7 +448,7 @@ class TestTestrunResultTotalsSubtests(object): expect['pass'] += 1 expect['crash'] += 1 expect['fail'] += 1 - nt.assert_dict_equal(self.test[grouptools.join('sub', 'test')], expect) + dict_eq(self.test[grouptools.join('sub', 'test')], expect) def test_totals_false(): @@ -484,7 +493,7 @@ class TestTestrunResultToJson(object): def test_options(self): """results.TestrunResult.to_json: options is properly encoded""" - nt.assert_dict_equal(self.test['options'], {'some': 'option'}) + dict_eq(self.test['options'], {'some': 'option'}) def test_glxinfo(self): """results.TestrunResult.to_json: glxinfo is properly encoded""" @@ -568,7 +577,7 @@ class TestTestrunResultFromDict(object): def test_totals(self): """results.TestrunResult.from_dict: totals is restored correctly""" - nt.assert_dict_equal(self.baseline.totals, self.test.totals) + dict_eq(self.baseline.totals, self.test.totals) def test_subtests(self): """results.TestrunResult.from_dict: subtests are restored correctly""" |