From 8653d24bc84d19d890efdd1fea0f56adcc2a60f5 Mon Sep 17 00:00:00 2001 From: TedSinger Date: Tue, 13 Nov 2012 15:00:44 -0500 Subject: [PATCH] Update test_envoy.py Added some basic tests for connect --- test_envoy.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test_envoy.py b/test_envoy.py index 1c2c050..2395bbb 100644 --- a/test_envoy.py +++ b/test_envoy.py @@ -1,5 +1,6 @@ import unittest import envoy +import time class SimpleTest(unittest.TestCase): @@ -18,6 +19,7 @@ class SimpleTest(unittest.TestCase): self.assertEqual(r.std_out, 'y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n') self.assertEqual(r.status_code, 0) + # THIS TEST FAILS BECAUSE expand_args DOESN'T HANDLE QUOTES PROPERLY def test_quoted_args(self): sentinel = 'quoted_args' * 3 r = envoy.run("python -c 'print \"%s\"'" % sentinel) @@ -26,9 +28,25 @@ class SimpleTest(unittest.TestCase): class ConnectedCommandTests(unittest.TestCase): - def test_status_code(self): + def test_status_code_none(self): c = envoy.connect("sleep 5") self.assertEqual(c.status_code, None) + def test_status_code_success(self): + c = envoy.connect("sleep 1") + time.sleep(2) + self.assertEqual(c.status_code, 0) + + def test_status_code_failure(self): + c = envoy.connect("sleeep 1") + self.assertEqual(c.status_code, 127) + + def test_input(self): + test_string = 'asdfQWER' + r = envoy.connect("cat | tr [:lower:] [:upper:]") + r.send(test_string) + self.assertEqual(r.std_out, test_string.upper()) + self.assertEqual(r.status_code, 0) + if __name__ == "__main__": - unittest.main() + unittest.main() \ No newline at end of file