summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorcat <cat@eee>2010-02-22 19:18:58 -0500
committercat <cat@eee>2010-02-22 19:18:58 -0500
commitafbd5361421d221d456c47099671053dae9fa257 (patch)
tree9160e0432ddd7dda00833b37f26ee090de63c968 /cmd2.py
parenta2a9f51029cb96c9e3f7ecf540159ac30490ea81 (diff)
downloadcmd2-hg-afbd5361421d221d456c47099671053dae9fa257.tar.gz
now attempting new outputtrap
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd2.py b/cmd2.py
index d3513df..fc0bb96 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1445,7 +1445,21 @@ class OutputTrap(Borg):
def tearDown(self):
sys.stdout = self.old_stdout
-
+class OutputTrap(Borg):
+ '''Instantiate an OutputTrap to divert/capture ALL stdout output. For use in unit testing.
+ Call `tearDown()` to return to normal output.'''
+ def __init__(self):
+ self.contents = ''
+ self.old_stdout = sys.stdout
+ sys.stdout = self
+ def write(self, txt):
+ self.contents += txt
+ def read(self):
+ return self.contents
+ def tearDown(self):
+ sys.stdout = self.old_stdout
+ self.contents = ''
+
class Cmd2TestCase(unittest.TestCase):
'''Subclass this, setting CmdApp, to make a unittest.TestCase class
that will execute the commands in a transcript file and expect the results shown.