Add pysawsim.invoke.CommandError.__repr__() method and doctest.
authorW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 14:15:58 +0000 (10:15 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 14:15:58 +0000 (10:15 -0400)
pysawsim/invoke.py

index 165701c3f84d0ad7ad5a45af2a7655219b9829da..bb501e768901702c12758c153aae820dc5bfb14d 100644 (file)
@@ -39,6 +39,9 @@ class CommandError(Exception):
     <BLANKLINE>
     while executing
       somefunc
+    >>> print repr(b)  # doctest: +NORMALIZE_WHITESPACE
+    CommandError(command='somefunc', status=1, stdout='',
+                 stderr='could not find "somefunc"')
     """
     def __init__(self, command=None, status=None, stdout=None, stderr=None):
         self.command = command
@@ -59,6 +62,12 @@ class CommandError(Exception):
                 "while executing\n  %s" % self.command,
                 ])
 
+    def __repr__(self):
+        return '%s(%s)' % (
+            self.__class__.__name__,
+            ', '.join(['%s=%s' % (attr, repr(getattr(self, attr)))
+                       for attr in ['command', 'status', 'stdout', 'stderr']]))
+
 
 def invoke(cmd_string, stdin=None, expect=(0,), cwd=None, verbose=False):
     """