From: A. Jesse Jiryu Davis Date: Sat, 28 Feb 2015 17:19:18 +0000 (-0500) Subject: Define Condition's and Event's repr, not str. X-Git-Tag: v4.2.0b1~90^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1355%2Fhead;p=thirdparty%2Ftornado.git Define Condition's and Event's repr, not str. Consistent with asyncio's Condition and Event. --- diff --git a/tornado/locks.py b/tornado/locks.py index 1367e1de8..f941a89c9 100644 --- a/tornado/locks.py +++ b/tornado/locks.py @@ -34,7 +34,7 @@ class Condition(object): self._waiters = collections.deque() # Futures. self._timeouts = 0 - def __str__(self): + def __repr__(self): result = '<%s' % (self.__class__.__name__, ) if self._waiters: result += ' waiters[%s]' % len(self._waiters) @@ -89,7 +89,7 @@ class Event(object): def __init__(self): self._future = Future() - def __str__(self): + def __repr__(self): return '<%s %s>' % ( self.__class__.__name__, 'set' if self.is_set() else 'clear') diff --git a/tornado/test/locks_test.py b/tornado/test/locks_test.py index 29d80b94f..c2930ca32 100644 --- a/tornado/test/locks_test.py +++ b/tornado/test/locks_test.py @@ -33,12 +33,12 @@ class ConditionTest(AsyncTestCase): self.history.append(key) future.add_done_callback(callback) - def test_str(self): + def test_repr(self): c = locks.Condition() - self.assertIn('Condition', str(c)) - self.assertNotIn('waiters', str(c)) + self.assertIn('Condition', repr(c)) + self.assertNotIn('waiters', repr(c)) c.wait() - self.assertIn('waiters', str(c)) + self.assertIn('waiters', repr(c)) @gen_test def test_notify(self): @@ -170,7 +170,7 @@ class ConditionTest(AsyncTestCase): class EventTest(AsyncTestCase): - def test_str(self): + def test_repr(self): event = locks.Event() self.assertTrue('clear' in str(event)) self.assertFalse('set' in str(event)) @@ -220,15 +220,15 @@ class SemaphoreTest(AsyncTestCase): def test_negative_value(self): self.assertRaises(ValueError, locks.Semaphore, value=-1) - def test_str(self): + def test_repr(self): sem = locks.Semaphore() - self.assertIn('Semaphore', str(sem)) - self.assertIn('unlocked,value:1', str(sem)) + self.assertIn('Semaphore', repr(sem)) + self.assertIn('unlocked,value:1', repr(sem)) sem.acquire() - self.assertIn('locked', str(sem)) - self.assertNotIn('waiters', str(sem)) + self.assertIn('locked', repr(sem)) + self.assertNotIn('waiters', repr(sem)) sem.acquire() - self.assertIn('waiters', str(sem)) + self.assertIn('waiters', repr(sem)) def test_acquire(self): sem = locks.Semaphore()