summaryrefslogtreecommitdiff
path: root/tests/test_transcript.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-16 22:36:51 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-03-16 22:36:51 -0400
commita5632e06cba42a26bb7d628631071d5cf0236e6f (patch)
tree09eb09272c30fa90995af675ca2383788dc669e1 /tests/test_transcript.py
parent2d4b43a4901122d7918af4030c440a3c93892a4f (diff)
downloadcmd2-git-a5632e06cba42a26bb7d628631071d5cf0236e6f.tar.gz
Added example of using a regular expression in a transcript test.
Also added a unit test for this feature.
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r--tests/test_transcript.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index c0966d03..89f2ea7c 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -310,3 +310,29 @@ def test_invalid_syntax(_cmdline_app, capsys):
out, err = capsys.readouterr()
expected = normalize("""ERROR: Invalid syntax: No closing quotation""")
assert normalize(str(err)) == expected
+
+
+def test_regex_transcript(request, capsys):
+ # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
+ app = CmdLineApp()
+
+ # Get location of the transcript
+ test_dir = os.path.dirname(request.module.__file__)
+ transcript_file = os.path.join(test_dir, 'transcript_regex.txt')
+
+ # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
+ testargs = ['prog', '-t', transcript_file]
+ with mock.patch.object(sys, 'argv', testargs):
+ # Run the command loop
+ app.cmdloop()
+
+ # Check for the unittest "OK" condition for the 1 test which ran
+ expected_start = ".\n----------------------------------------------------------------------\nRan 1 test in"
+ expected_end = "s\n\nOK\n\n"
+ out, err = capsys.readouterr()
+ if six.PY3:
+ assert err.startswith(expected_start)
+ assert err.endswith(expected_end)
+ else:
+ assert err == ''
+ assert out == ''