Skip to content

Commit

Permalink
Added support and tests for specifying a 'time' field as the string
Browse files Browse the repository at this point in the history
"now"
  • Loading branch information
jon committed Aug 17, 2012
1 parent f77daf4 commit 8e3eb96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def _to_binary_inst(msg):

def _to_time_inst(msg, rostype, inst=None):
# Create an instance if we haven't been provided with one
if rostype == "time" and msg == "now":
return rospy.get_rostime()

if inst is None:
if rostype == "time":
inst = rospy.rostime.Time()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,23 @@ def test_time_msg(self):

msg = {"times": [{"secs": 3, "nsecs": 5}, {"secs": 2, "nsecs": 7}]}
self.do_test(msg, "rosbridge_test/TimeArrayTest")

def test_time_msg_now(self):
msg = {"data": "now"}
msgtype = "std_msgs/Time"

inst = ros_loader.get_message_instance(msgtype)
c.populate_instance(msg, inst)
currenttime = rospy.get_rostime()
self.validate_instance(inst)
extracted = c.extract_values(inst)
print extracted
self.assertIn("data", extracted)
self.assertIn("secs", extracted["data"])
self.assertIn("nsecs", extracted["data"])
self.assertNotEqual(extracted["data"]["secs"], 0)
self.assertLessEqual(extracted["data"]["secs"], currenttime.secs)
self.assertGreaterEqual(currenttime.secs, extracted["data"]["secs"])

def test_duration_msg(self):
msg = {"data": {"secs": 3, "nsecs": 5}}
Expand Down

0 comments on commit 8e3eb96

Please sign in to comment.