diff options
author | cat <cat@eee> | 2010-02-22 19:18:58 -0500 |
---|---|---|
committer | cat <cat@eee> | 2010-02-22 19:18:58 -0500 |
commit | afbd5361421d221d456c47099671053dae9fa257 (patch) | |
tree | 9160e0432ddd7dda00833b37f26ee090de63c968 /cmd2.py | |
parent | a2a9f51029cb96c9e3f7ecf540159ac30490ea81 (diff) | |
download | cmd2-hg-afbd5361421d221d456c47099671053dae9fa257.tar.gz |
now attempting new outputtrap
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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. |