diff --git a/amodem/common.py b/amodem/common.py index 2fda33c..54e37a7 100644 --- a/amodem/common.py +++ b/amodem/common.py @@ -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) diff --git a/tests/test_common.py b/tests/test_common.py index 499600e..7a9bd9d 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -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)'