summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-09-05 20:06:11 -0700
committerGitHub <noreply@github.com>2017-09-05 20:06:11 -0700
commit6d711bcb104b5afd0bfb49cbe30410ec5b8fadd5 (patch)
tree68d6015e2db4311f7742b7140aee6b730fdea054 /tests
parent5d5675bac5a8d431fbae1e12daf9b27ca4edfe91 (diff)
parent25efdfbabeee733247a6d9cd06156b2597f65146 (diff)
downloadcmd2-git-6d711bcb104b5afd0bfb49cbe30410ec5b8fadd5.tar.gz
Merge pull request #223 from python-cmd2/poutput_falsy
Improved poutput() so that it can print falsy things
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 6e1e6ef5..4f65606d 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -1406,7 +1406,7 @@ def test_pseudo_raw_input_tty_rawinput_true():
# for the 'set' command, and once for the 'quit' command,
# that the rest of it worked
assert m_input.call_count == 2
-
+
def test_pseudo_raw_input_tty_rawinput_false():
# gin up some input like it's coming from a tty
fakein = io.StringIO(u'{}'.format('set\n'))
@@ -1414,12 +1414,12 @@ def test_pseudo_raw_input_tty_rawinput_false():
fakein.isatty = mtty
mreadline = mock.MagicMock(name='readline', wraps=fakein.readline)
fakein.readline = mreadline
-
+
# run the cmdloop, telling it where to get input from
app = cmd2.Cmd(stdin=fakein)
app.use_rawinput = False
app._cmdloop()
-
+
# because we mocked the readline() call, we won't get the prompt
# or the name of the command in the output, so we can't check
# if its there. We assume that if readline() got called twice, once
@@ -1523,3 +1523,32 @@ def test_empty_stdin_input():
line = app.pseudo_raw_input('(cmd2)')
assert line == 'eof'
+
+
+def test_poutput_string(base_app):
+ msg = 'This is a test'
+ base_app.poutput(msg)
+ out = base_app.stdout.buffer
+ expected = msg + '\n'
+ assert out == expected
+
+def test_poutput_zero(base_app):
+ msg = 0
+ base_app.poutput(msg)
+ out = base_app.stdout.buffer
+ expected = str(msg) + '\n'
+ assert out == expected
+
+def test_poutput_empty_string(base_app):
+ msg = ''
+ base_app.poutput(msg)
+ out = base_app.stdout.buffer
+ expected = msg
+ assert out == expected
+
+def test_poutput_none(base_app):
+ msg = None
+ base_app.poutput(msg)
+ out = base_app.stdout.buffer
+ expected = ''
+ assert out == expected