Mercurial > python-cmd2
comparison cmd2.py @ 378:0b77ca917fd2
now attempting new outputtrap
author | cat@eee |
---|---|
date | Mon, 22 Feb 2010 19:18:58 -0500 |
parents | 70ca35d96c49 |
children | 1babd3df22d1 |
comparison
equal
deleted
inserted
replaced
377:70ca35d96c49 | 378:0b77ca917fd2 |
---|---|
1443 except TypeError: | 1443 except TypeError: |
1444 return result | 1444 return result |
1445 def tearDown(self): | 1445 def tearDown(self): |
1446 sys.stdout = self.old_stdout | 1446 sys.stdout = self.old_stdout |
1447 | 1447 |
1448 | 1448 class OutputTrap(Borg): |
1449 '''Instantiate an OutputTrap to divert/capture ALL stdout output. For use in unit testing. | |
1450 Call `tearDown()` to return to normal output.''' | |
1451 def __init__(self): | |
1452 self.contents = '' | |
1453 self.old_stdout = sys.stdout | |
1454 sys.stdout = self | |
1455 def write(self, txt): | |
1456 self.contents += txt | |
1457 def read(self): | |
1458 return self.contents | |
1459 def tearDown(self): | |
1460 sys.stdout = self.old_stdout | |
1461 self.contents = '' | |
1462 | |
1449 class Cmd2TestCase(unittest.TestCase): | 1463 class Cmd2TestCase(unittest.TestCase): |
1450 '''Subclass this, setting CmdApp, to make a unittest.TestCase class | 1464 '''Subclass this, setting CmdApp, to make a unittest.TestCase class |
1451 that will execute the commands in a transcript file and expect the results shown. | 1465 that will execute the commands in a transcript file and expect the results shown. |
1452 See example.py''' | 1466 See example.py''' |
1453 CmdApp = None | 1467 CmdApp = None |