Skip to content

Commit a755b9e

Browse files
committed
Include module name in ModelObject.__repr__.
1 parent fcd4c97 commit a755b9e

9 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎src/robot/model/modelobject.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
@py3to2
2222
class ModelObject(with_metaclass(SetterAwareType, object)):
23-
repr_args = ('name',)
23+
repr_args = ()
2424
__slots__ = []
2525

2626
def config(self, **attributes):
@@ -71,7 +71,10 @@ def deepcopy(self, **attributes):
7171

7272
def __repr__(self):
7373
args = ['%s=%r' % (n, getattr(self, n)) for n in self.repr_args]
74-
return '%s(%s)' % (type(self).__name__, ', '.join(args))
74+
module = type(self).__module__.split('.')
75+
if len(module) > 1 and module[0] == 'robot':
76+
module = module[:2]
77+
return '%s.%s(%s)' % ('.'.join(module), type(self).__name__, ', '.join(args))
7578

7679
def __setstate__(self, state):
7780
"""Customize attribute updating when using the `copy` module.

‎src/robot/model/testcase.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class TestCase(ModelObject):
3232
"""
3333
body_class = Body
3434
fixture_class = Keyword
35+
repr_args = ('name',)
3536
__slots__ = ['parent', 'name', 'doc', 'timeout']
3637

3738
def __init__(self, name='', doc='', tags=None, timeout=None, parent=None):

‎src/robot/model/testsuite.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TestSuite(ModelObject):
3535
"""
3636
test_class = TestCase #: Internal usage only.
3737
fixture_class = Keyword #: Internal usage only.
38+
repr_args = ('name',)
3839
__slots__ = ['parent', 'source', '_name', 'doc', '_my_visitors', 'rpa']
3940

4041
def __init__(self, name='', doc='', metadata=None, source=None, rpa=False,

‎utest/model/test_control.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_string_reprs(self):
2424
u"For(variables=[%r], flavor='IN', values=[%r])" % (u'${\xfc}', u'f\xf6\xf6'))
2525
]:
2626
assert_equal(unicode(for_), exp_str)
27-
assert_equal(repr(for_), exp_repr)
27+
assert_equal(repr(for_), 'robot.model.' + exp_repr)
2828
if PY2:
2929
assert_equal(str(for_), unicode(for_).encode('UTF-8'))
3030

@@ -67,7 +67,7 @@ def test_string_reprs(self):
6767
u'If(condition=%r)' % u'$x == "\xe4iti"'),
6868
]:
6969
assert_equal(unicode(if_), exp_str)
70-
assert_equal(repr(if_), exp_repr)
70+
assert_equal(repr(if_), 'robot.model.' + exp_repr)
7171
if PY2:
7272
assert_equal(str(if_), unicode(if_).encode('UTF-8'))
7373

‎utest/model/test_keyword.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_string_reprs(self):
7575
u'Keyword(name=%r, args=[%r], assign=[%r])' % (u'\xe4', u'\xe5', u'${\xe3}'))
7676
]:
7777
assert_equal(unicode(kw), exp_str)
78-
assert_equal(repr(kw), exp_repr)
78+
assert_equal(repr(kw), 'robot.model.' + exp_repr)
7979
if PY2:
8080
assert_equal(str(kw), unicode(kw).encode('UTF-8'))
8181

‎utest/model/test_message.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_repr(self):
6565
(self.ascii, "Message(message='Kekkonen', level='WARN')"),
6666
(self.non_ascii, u"Message(message=%r, level='INFO')"
6767
% u'hyv\xe4 nimi')]:
68-
assert_equal(repr(tc), expected)
68+
assert_equal(repr(tc), 'robot.model.' + expected)
6969

7070

7171
if __name__ == '__main__':

‎utest/model/test_modelobject.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import unittest
2+
3+
from robot.model.modelobject import ModelObject
4+
from robot.utils.asserts import assert_equal
5+
6+
7+
class TestRepr(unittest.TestCase):
8+
9+
def test_default(self):
10+
assert_equal(repr(ModelObject()), 'robot.model.ModelObject()')
11+
12+
def test_module_when_extending(self):
13+
class X(ModelObject):
14+
pass
15+
assert_equal(repr(X()), '%s.X()' % __name__)
16+
17+
def test_repr_args(self):
18+
class X(ModelObject):
19+
repr_args = ('z', 'x')
20+
x, y, z = 1, 2, 3
21+
assert_equal(repr(X()), '%s.X(z=3, x=1)' % __name__)
22+
23+
24+
if __name__ == '__main__':
25+
unittest.main()

‎utest/model/test_testcase.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_repr(self):
119119
for tc, expected in [(self.empty, "TestCase(name='')"),
120120
(self.ascii, "TestCase(name='Kekkonen')"),
121121
(self.non_ascii, u"TestCase(name=%r)" % u'hyv\xe4 nimi')]:
122-
assert_equal(repr(tc), expected)
122+
assert_equal(repr(tc), 'robot.model.' + expected)
123123

124124

125125
class TestTestCases(unittest.TestCase):

‎utest/model/test_testsuite.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_repr(self):
144144
for tc, expected in [(self.empty, "TestSuite(name='')"),
145145
(self.ascii, "TestSuite(name='Kekkonen')"),
146146
(self.non_ascii, u"TestSuite(name=%r)" % u'hyv\xe4 nimi')]:
147-
assert_equal(repr(tc), expected)
147+
assert_equal(repr(tc), 'robot.model.' + expected)
148148

149149

150150
if __name__ == '__main__':

0 commit comments

Comments
 (0)