tristate: fix __repr__
authorGuido Günther <agx@sigxcpu.org>
Sun, 22 Jan 2012 15:57:02 +0000 (16:57 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 22 Jan 2012 16:26:39 +0000 (17:26 +0100)
and add doctest

gbp/tristate.py

index 95391b9..67b1052 100644 (file)
@@ -43,12 +43,22 @@ class Tristate(object):
             raise TypeError
 
     def __repr__(self):
-        if self._state == ON:
-            return "on"
-        elif self._state == AUTO:
-            return "auto"
+        """
+        >>> Tristate('on').__repr__()
+        'on'
+        >>> Tristate(True).__repr__()
+        'on'
+        >>> Tristate(False).__repr__()
+        'off'
+        >>> Tristate('auto').__repr__()
+        'auto'
+        """
+        if self._state == self.ON:
+            return 'on'
+        elif self._state == self.AUTO:
+            return 'auto'
         else:
-            return "off"
+            return 'off'
 
     @classmethod
     def is_valid_state(self, stat):