summaryrefslogtreecommitdiff
path: root/cmd2/transcript.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-23 18:51:30 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-09-23 18:51:30 -0400
commit35550e048bde73b08fad28c2a8d844dcbdea7f35 (patch)
treeac4781f9ac5e4abf97710b8dcd2d67187ffe1bc2 /cmd2/transcript.py
parentdbe485957b421f6fd973b3a493de7b264b363d54 (diff)
downloadcmd2-git-35550e048bde73b08fad28c2a8d844dcbdea7f35.tar.gz
Fixed several hack classes build to simulate file descriptors
Now there is a single class, StdSim in utils.py, which is intended to simulate stdout and stderr file objects. This class replaced the following: - pyscript_bridge.py::CopyStream - transcript.py::OutputTrap - conftest.py::StdOut
Diffstat (limited to 'cmd2/transcript.py')
-rw-r--r--cmd2/transcript.py23
1 files changed, 1 insertions, 22 deletions
diff --git a/cmd2/transcript.py b/cmd2/transcript.py
index 8df58634..2d94f4e4 100644
--- a/cmd2/transcript.py
+++ b/cmd2/transcript.py
@@ -44,7 +44,7 @@ class Cmd2TestCase(unittest.TestCase):
# Trap stdout
self._orig_stdout = self.cmdapp.stdout
- self.cmdapp.stdout = OutputTrap()
+ self.cmdapp.stdout = utils.StdSim(self.cmdapp.stdout)
def runTest(self): # was testall
if self.cmdapp:
@@ -203,24 +203,3 @@ class Cmd2TestCase(unittest.TestCase):
if self.cmdapp:
# Restore stdout
self.cmdapp.stdout = self._orig_stdout
-
-class OutputTrap(object):
- """Instantiate an OutputTrap to divert/capture ALL stdout output.
- For use in transcript testing.
- """
-
- def __init__(self):
- self.contents = ''
-
- def write(self, txt: str):
- """Add text to the internal contents."""
- self.contents += txt
-
- def read(self) -> str:
- """Read from the internal contents and then clear them out.
-
- :return: str - text from the internal contents
- """
- result = self.contents
- self.contents = ''
- return result