Commit e57794cf authored by Dylan Baker's avatar Dylan Baker

framework/ 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 <>
Signed-off-by: default avatarDylan Baker <>
parent 765d790d
......@@ -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:
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):
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
......@@ -72,8 +72,7 @@ def test_piglitest_no_clobber():
test.result.returncode = 0
{'test1': 'pass', 'test2': 'pass'})
nt.eq_(test.result.subtests, {'test1': 'pass', 'test2': 'pass'})
def test_piglittest_command_getter_serial():
......@@ -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():
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