summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2014-07-24 13:32:26 +0100
committerLars Wirzenius <liw@liw.fi>2014-07-31 09:12:09 +0100
commitc606976c69ebed1d623f412a1ddf3442d8b31a98 (patch)
tree6e14c2c7fc70b8ea88856e16f856ec2dc1c2adfe
parent0be9a6869c13d9e1369a4458c8e700f4684a4c56 (diff)
downloadcliapp-c606976c69ebed1d623f412a1ddf3442d8b31a98.tar.gz
Add tests for runcmd callbacks
-rw-r--r--cliapp/runcmd_tests.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/cliapp/runcmd_tests.py b/cliapp/runcmd_tests.py
index e89b73e..0e8a090 100644
--- a/cliapp/runcmd_tests.py
+++ b/cliapp/runcmd_tests.py
@@ -124,6 +124,33 @@ class RuncmdTests(unittest.TestCase):
self.assertEqual(exit, 0)
self.assertEqual(data, '')
+ def test_runcmd_calls_stdout_callback_when_msg_on_stdout(self):
+ msgs = []
+
+ def logger(s):
+ msgs.append(s)
+
+ test_input = 'hello fox'
+ exit, out, err = cliapp.runcmd_unchecked(['echo', '-n', test_input],
+ stdout_callback=logger)
+
+ self.assertEqual(test_input, out)
+ self.assertEqual(len(msgs), 1)
+ self.assertEqual(out, msgs[0])
+
+ def test_runcmd_calls_stderr_callback_when_msg_on_stderr(self):
+ msgs = []
+
+ def logger(s):
+ msgs.append(s)
+
+ exit, out, err = cliapp.runcmd_unchecked(['ls', 'nosuchthing'],
+ stderr_callback=logger)
+
+ self.assertEqual(len(msgs), 1)
+ self.assertNotEqual(err, '')
+ self.assertEqual(err, msgs[0])
+
class ShellQuoteTests(unittest.TestCase):