common: fix __repr__ on AttributeHolder

This commit is contained in:
Roman Zeyde
2015-01-16 10:51:11 +02:00
parent b4dc0922eb
commit cb8ce9e8ec
2 changed files with 11 additions and 1 deletions

View File

@@ -80,4 +80,6 @@ class AttributeHolder(object):
self.__dict__.update(d)
def __repr__(self):
return '{}({})'.format(self.__class__.__name__, self.__dict__)
items = sorted(self.__dict__.items())
args = ', '.join('{0}={1}'.format(k, v) for k, v in items)
return '{}({})'.format(self.__class__.__name__, args)

View File

@@ -51,3 +51,11 @@ def test_izip():
x = range(10)
y = range(-10, 0)
assert list(common.izip([x, y])) == list(zip(x, y))
def test_holder():
d = {'x': 1, 'y': 2.3}
a = common.AttributeHolder(d)
assert a.x == d['x']
assert a.y == d['y']
assert repr(a) == 'AttributeHolder(x=1, y=2.3)'