Skip to content

Commit

Permalink
Merge pull request #71 from ros/fix_python3_regressions
Browse files Browse the repository at this point in the history
fix Python 3 regressions
  • Loading branch information
dirk-thomas committed Oct 21, 2016
2 parents 6db907f + eca8d88 commit e176e70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/genpy/rostime.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def __ne__(self, other):
def __cmp__(self, other):
if not isinstance(other, TVal):
raise TypeError("Cannot compare to non-TVal")
return cmp(self.to_nsec(), other.to_nsec())
a = self.to_nsec()
b = other.to_nsec()
return (a > b) - (a < b)

def __eq__(self, other):
if not isinstance(other, TVal):
Expand Down Expand Up @@ -226,6 +228,9 @@ def to_time(self):
"""
return self.to_sec()

def __hash__(self):
return super(Time, self).__hash__()

def __repr__(self):
return "genpy.Time[%d]"%self.to_nsec()

Expand Down Expand Up @@ -261,7 +266,9 @@ def __cmp__(self, other):
"""
if not isinstance(other, Time):
raise TypeError("cannot compare to non-Time")
return cmp(self.to_nsec(), other.to_nsec())
a = self.to_nsec()
b = other.to_nsec()
return (a > b) - (a < b)

def __eq__(self, other):
"""
Expand Down Expand Up @@ -303,6 +310,9 @@ def __setstate__(self, state):
"""
self.secs, self.nsecs = state

def __hash__(self):
return super(Duration, self).__hash__()

def __repr__(self):
return "genpy.Duration[%d]"%self.to_nsec()

Expand Down Expand Up @@ -423,7 +433,9 @@ def __divmod__(self, val):
def __cmp__(self, other):
if not isinstance(other, Duration):
raise TypeError("Cannot compare to non-Duration")
return cmp(self.to_nsec(), other.to_nsec())
a = self.to_nsec()
b = other.to_nsec()
return (a > b) - (a < b)

def __eq__(self, other):
if not isinstance(other, Duration):
Expand Down
14 changes: 7 additions & 7 deletions test/test_genpy_rostime.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,19 +419,19 @@ def test_Duration(self):
self.assertEquals(Duration(4), Duration(8) / 2.)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
self.assertEquals(Duration(4), Duration(8) // 2)
self.assertEquals(Duration(4), Duration(8) // 2.)
self.assertEquals(Duration(4), Duration(9) // 2)
self.assertEquals(Duration(4), Duration(9) // 2.)
self.assertEqual(Duration(4), Duration(8) // 2)
self.assertEqual(Duration(4), Duration(8) // 2.)
self.assertEqual(Duration(4), Duration(9) // 2)
self.assertEqual(Duration(4), Duration(9) // 2.)
self.assertEqual(len(w), 0)
self.assertEquals(Duration(4, 2), Duration(8, 4) / 2)
v = Duration(4, 2) - (Duration(8, 4) / 2.)
self.assert_(abs(v.to_nsec()) < 100)

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
self.assertEquals(Duration(4, 0), Duration(8, 4) // 2)
self.assertEquals(Duration(4, 0), Duration(9, 5) // 2)
self.assertEqual(Duration(4, 0), Duration(8, 4) // 2)
self.assertEqual(Duration(4, 0), Duration(9, 5) // 2)
v = Duration(4, 2) - (Duration(9, 5) // 2.)
self.assert_(abs(v.to_nsec()) < 100)
self.assertTrue(abs(v.to_nsec()) < 100)
self.assertEqual(len(w), 0)

0 comments on commit e176e70

Please sign in to comment.