From 8b02c0b85e8125edb6757c43c78f8a1e73f38464 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Barth Date: Fri, 2 Oct 2015 03:37:14 +0200 Subject: [PATCH] Move *Type __repr__ to GenericType --- moto/swf/models.py | 11 +++++------ tests/test_swf/test_models.py | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/moto/swf/models.py b/moto/swf/models.py index 27295b710..4cdfb3536 100644 --- a/moto/swf/models.py +++ b/moto/swf/models.py @@ -73,6 +73,11 @@ class GenericType(object): for key, value in kwargs.iteritems(): self.__setattr__(key, value) + def __repr__(self): + cls = self.__class__.__name__ + attrs = "name: %(name)s, version: %(version)s" % self.__dict__ + return "{}({})".format(cls, attrs) + @property def kind(self): raise NotImplementedError() @@ -116,9 +121,6 @@ class GenericType(object): return hsh class ActivityType(GenericType): - def __repr__(self): - return "ActivityType(name: %(name)s, version: %(version)s)" % self.__dict__ - @property def _configuration_keys(self): return [ @@ -134,9 +136,6 @@ class ActivityType(GenericType): class WorkflowType(GenericType): - def __repr__(self): - return "WorkflowType(name: %(name)s, version: %(version)s)" % self.__dict__ - @property def _configuration_keys(self): return [ diff --git a/tests/test_swf/test_models.py b/tests/test_swf/test_models.py index 2211e2264..2843e559a 100644 --- a/tests/test_swf/test_models.py +++ b/tests/test_swf/test_models.py @@ -44,3 +44,7 @@ def test_full_dict_representation(): _type.non_whitelisted_property = "34" _type.to_full_dict()["configuration"].keys().should.equal(["defaultTaskList", "justAnExampleTimeout"]) + +def test_string_representation(): + _type = FooType("test-foo", "v1.0") + str(_type).should.equal("FooType(name: test-foo, version: v1.0)")