]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Define Condition's and Event's repr, not str. 1355/head
authorA. Jesse Jiryu Davis <jesse@mongodb.com>
Sat, 28 Feb 2015 17:19:18 +0000 (12:19 -0500)
committerA. Jesse Jiryu Davis <jesse@mongodb.com>
Sat, 28 Feb 2015 17:19:18 +0000 (12:19 -0500)
Consistent with asyncio's Condition and Event.

tornado/locks.py
tornado/test/locks_test.py

index 1367e1de89e8a25762a8b4c30067f199592be1d4..f941a89c97028fb0c8949c06a7044aa8206a5f3c 100644 (file)
@@ -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')
 
index 29d80b94fd29cbcc7cc2e33bebfff82da34516b0..c2930ca3256cd6a2d5ff9e0c39addb7d32906ef1 100644 (file)
@@ -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()