Skip to content

Commit 7ce4071

Browse files
authored
Merge pull request #277 from compas-dev/fix-rosmsg-repr
Fix ROSmsg representation
2 parents 76308cb + e09cdea commit 7ce4071

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Unreleased
1616

1717
**Fixed**
1818

19+
* Fix ``repr()`` of ``ROSmsg`` class
20+
1921
**Deprecated**
2022

2123
**Removed**

src/compas_fab/backends/ros/messages/std_msgs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def __str__(self):
3232
return str(self.msg)
3333

3434
def __repr__(self):
35-
return self.__str__
35+
args = []
36+
for key, value in self.__dict__.items():
37+
args.append('{}={!r}'.format(key, value))
38+
39+
return '{}({})'.format(self.__class__.__name__, ', '.join(args))
3640

3741

3842
class Time(ROSmsg):
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from compas_fab.backends.ros.messages import ROSmsg
2+
from compas_fab.backends.ros.messages import Header
3+
from compas_fab.backends.ros.messages import Time
4+
5+
6+
def test_rosmsg_attributes():
7+
r = ROSmsg(a=1, b=2)
8+
assert r.a == 1
9+
assert r.b == 2
10+
11+
12+
def test_rosmsg_str():
13+
r = ROSmsg(a=1, b='2')
14+
assert str(r) == str(dict(a=1, b='2'))
15+
16+
17+
def test_nested_repr():
18+
t = Time(80, 20)
19+
h = Header(seq=10, stamp=t, frame_id='/wow')
20+
assert repr(h) == "Header(seq=10, stamp=Time(secs=80, nsecs=20), frame_id='/wow')"

0 commit comments

Comments
 (0)