summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-01-29 21:46:12 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-01-29 21:46:12 -0500
commit9c8056f03ff0e6fac515d9b8defff68a5eeef454 (patch)
tree2edde27d4b855bce7b89dd875bdd2fad688bfa6b
parentd3bab07ff700e596795b42290a17c0ec557b15da (diff)
downloadcmd2-git-9c8056f03ff0e6fac515d9b8defff68a5eeef454.tar.gz
Added a 2nd way of unit testing transcript tests which covers some additional code.
-rw-r--r--.gitignore4
-rw-r--r--tests/test_cmd2.py11
-rw-r--r--tests/test_transcript.py18
-rw-r--r--tests/transcript.txt62
4 files changed, 83 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 5a438505..01895266 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,6 @@ dist
cmd2.egg-info
.idea
.cache
-*.pyc \ No newline at end of file
+*.pyc
+.coverage
+htmlcov
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 194892f7..a6a3822e 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1,9 +1,10 @@
# coding=utf-8
-#
-# Cmd2 unit/functional testing
-#
-# Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com>
-# Released under MIT license, see LICENSE file
+"""
+Cmd2 unit/functional testing
+
+Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com>
+Released under MIT license, see LICENSE file
+"""
import mock
from conftest import run_cmd, _normalize
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index d7e40295..253b338d 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -1,13 +1,14 @@
# coding=utf-8
-#
-# Cmd2 functional testing based on transcript
-#
-# Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com>
-# Released under MIT license, see LICENSE file
+"""
+Cmd2 functional testing based on transcript
+
+Copyright 2016 Federico Ceratto <federico.ceratto@gmail.com>
+Released under MIT license, see LICENSE file
+"""
import pytest
-from cmd2 import Cmd, make_option, options
+from cmd2 import Cmd, make_option, options, Cmd2TestCase
from conftest import run_cmd, StdOut, _normalize
@@ -134,3 +135,8 @@ now: --->
for cmd, expected in _get_transcript_blocks(transcript):
out = run_cmd(app, cmd)
assert out == expected
+
+
+class TestMyAppCase(Cmd2TestCase):
+ CmdApp = CmdLineApp
+ CmdApp.testfiles = ['tests/transcript.txt']
diff --git a/tests/transcript.txt b/tests/transcript.txt
new file mode 100644
index 00000000..91f27dff
--- /dev/null
+++ b/tests/transcript.txt
@@ -0,0 +1,62 @@
+(Cmd) help
+
+Documented commands (type help <topic>):
+========================================
+_load ed history list pause run set show
+_relative_load edit l load py save shell speak
+cmdenvironment hi li orate r say shortcuts
+
+Undocumented commands:
+======================
+EOF eof exit help q quit
+
+(Cmd) help say
+Repeats what you tell me to.
+Usage: speak [options] (text to say)
+
+Options:
+ -h, --help show this help message and exit
+ -p, --piglatin atinLay
+ -s, --shout N00B EMULATION MODE
+ -r REPEAT, --repeat=REPEAT
+ output [n] times
+
+(Cmd) say goodnight, Gracie
+goodnight, Gracie
+(Cmd) say -ps --repeat=5 goodnight, Gracie
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+(Cmd) set maxrepeats 5
+maxrepeats - was: 3
+now: 5
+(Cmd) say -ps --repeat=5 goodnight, Gracie
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+(Cmd) hi
+-------------------------[1]
+help
+-------------------------[2]
+help say
+-------------------------[3]
+say goodnight, Gracie
+-------------------------[4]
+say -ps --repeat=5 goodnight, Gracie
+-------------------------[5]
+set maxrepeats 5
+-------------------------[6]
+say -ps --repeat=5 goodnight, Gracie
+(Cmd) run 4
+say -ps --repeat=5 goodnight, Gracie
+
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+OODNIGHT, GRACIEGAY
+(Cmd) set prompt "---> "
+prompt - was: (Cmd)
+now: --->