diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2015-09-23 16:01:17 -0700 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-09-24 14:29:24 -0700 |
commit | e57794cf3b1a4b3d424185f924435d9994e50724 (patch) | |
tree | be8846f0175fa2019d0b56b541b0b2646fb375ab | |
parent | 765d790d550dd1feb230cad34d14e7589069960c (diff) |
framework/results.py: Fix Subtests class
Sub-classing built-in types in python is an error-prone leap, and many
corner cases came out to bit us in this instance. By wrapping a dict
inside of another class we can get the desired results, it means more
code, but it also means less corner cases.
Also change the equality test of two unit tests, since Subtests isn't a
dictionary anymore assert_dict_equal wont work anymore.
cc: Mark Janes <mark.a.janes@intel.com>
Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r-- | framework/results.py | 32 | ||||
-rw-r--r-- | framework/tests/piglit_test_tests.py | 3 | ||||
-rw-r--r-- | framework/tests/results_tests.py | 2 |
3 files changed, 29 insertions, 8 deletions
diff --git a/framework/results.py b/framework/results.py index 61841b76a..d358cca70 100644 --- a/framework/results.py +++ b/framework/results.py @@ -34,9 +34,31 @@ __all__ = [ ] -class Subtests(dict): +class Subtests(collections.MutableMapping): + """A dict-like object that stores Statuses as values.""" + def __init__(self, dict_=None): + self.__container = {} + + if dict_ is not None: + self.update(dict_) + def __setitem__(self, name, value): - super(Subtests, self).__setitem__(name, status.status_lookup(value)) + self.__container[name] = status.status_lookup(value) + + def __getitem__(self, name): + return self.__container[name] + + def __delitem__(self, name): + del self.__container[name] + + def __iter__(self): + return iter(self.__container) + + def __len__(self): + return len(self.__container) + + def __repr__(self): + return repr(self.__container) def to_json(self): res = dict(self) @@ -45,10 +67,10 @@ class Subtests(dict): @classmethod def from_dict(cls, dict_): - res = cls(dict_) + if '__type__' in dict_: + del dict_['__type__'] - if '__type__' in res: - del res['__type__'] + res = cls(dict_) return res diff --git a/framework/tests/piglit_test_tests.py b/framework/tests/piglit_test_tests.py index db4c8b06e..c7c4c8f9d 100644 --- a/framework/tests/piglit_test_tests.py +++ b/framework/tests/piglit_test_tests.py @@ -72,8 +72,7 @@ def test_piglitest_no_clobber(): test.result.returncode = 0 test.interpret_result() - nt.assert_dict_equal(test.result.subtests, - {'test1': 'pass', 'test2': 'pass'}) + nt.eq_(test.result.subtests, {'test1': 'pass', 'test2': 'pass'}) def test_piglittest_command_getter_serial(): diff --git a/framework/tests/results_tests.py b/framework/tests/results_tests.py index ab5f0d3a6..a28d78b96 100644 --- a/framework/tests/results_tests.py +++ b/framework/tests/results_tests.py @@ -68,7 +68,7 @@ def test_Subtests_to_json(): test['foo'] = status.PASS test['bar'] = status.CRASH - nt.assert_dict_equal(baseline, test.to_json()) + nt.eq_(baseline, test.to_json()) def test_Subtests_from_dict(): |