1 |
idella4 13/06/05 19:18:34 |
2 |
|
3 |
Added: test_envoy.py |
4 |
Log: |
5 |
revbump, migrate -> distutils-r1 |
6 |
|
7 |
(Portage version: 2.1.11.63/cvs/Linux x86_64, signed Manifest commit with key 0xB8072B0D) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 dev-python/envoy/files/test_envoy.py |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/envoy/files/test_envoy.py?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/envoy/files/test_envoy.py?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: test_envoy.py |
16 |
=================================================================== |
17 |
import unittest |
18 |
import envoy |
19 |
import time |
20 |
|
21 |
class SimpleTest(unittest.TestCase): |
22 |
|
23 |
def test_input(self): |
24 |
r = envoy.run("sed s/i/I/g", "Hi") |
25 |
self.assertEqual(r.std_out.rstrip(), "HI") |
26 |
self.assertEqual(r.status_code, 0) |
27 |
|
28 |
def test_pipe(self): |
29 |
r = envoy.run("echo -n 'hi'| tr [:lower:] [:upper:]") |
30 |
self.assertEqual(r.std_out, "HI") |
31 |
self.assertEqual(r.status_code, 0) |
32 |
|
33 |
def test_timeout(self): |
34 |
r = envoy.run('yes | head', timeout=1) |
35 |
self.assertEqual(r.std_out, 'y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n') |
36 |
self.assertEqual(r.status_code, 0) |
37 |
|
38 |
# THIS TEST FAILS BECAUSE expand_args DOESN'T HANDLE QUOTES PROPERLY |
39 |
def test_quoted_args(self): |
40 |
sentinel = 'quoted_args' * 3 |
41 |
r = envoy.run("python -c 'print \"%s\"'" % sentinel) |
42 |
self.assertEqual(r.std_out.rstrip(), sentinel) |
43 |
self.assertEqual(r.status_code, 0) |
44 |
|
45 |
class ConnectedCommandTests(unittest.TestCase): |
46 |
|
47 |
def test_status_code_none(self): |
48 |
c = envoy.connect("sleep 5") |
49 |
self.assertEqual(c.status_code, None) |
50 |
|
51 |
def test_status_code_success(self): |
52 |
c = envoy.connect("sleep 1") |
53 |
time.sleep(2) |
54 |
self.assertEqual(c.status_code, 0) |
55 |
|
56 |
def test_status_code_failure(self): |
57 |
c = envoy.connect("sleeep 1") |
58 |
self.assertEqual(c.status_code, 127) |
59 |
|
60 |
def test_input(self): |
61 |
test_string = 'asdfQWER' |
62 |
r = envoy.connect("cat | tr [:lower:] [:upper:]") |
63 |
r.send(test_string) |
64 |
self.assertEqual(r.std_out, test_string.upper()) |
65 |
self.assertEqual(r.status_code, 0) |
66 |
|
67 |
if __name__ == "__main__": |
68 |
unittest.main() |