-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
38 lines (30 loc) · 1.25 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import time
from tornado import gen
from tornado.testing import AsyncTestCase, gen_test
from tornado.ioloop import IOLoop
from tonbsubprocess import NonBlockingSubprocess
class TestSubprocess(NonBlockingSubprocess):
def __init__(self, cmd):
self.datalogging = []
super(TestSubprocess, self).__init__(cmd)
def log_data(self, data):
self.datalogging.append([time.time(), data])
class TestPandaSubprocess(AsyncTestCase):
@gen_test(timeout=10)
def test_command(self):
cmd = "echo 1 && sleep 1 && echo 2"
resobj = yield gen.Task(TestSubprocess(cmd).loop)
self.assertTrue(len(resobj.datalogging) == 2)
def get_new_ioloop(self):
return IOLoop.instance()
@gen_test(timeout=10)
def test_multi_commands(self):
cmds = ['echo 1 && sleep 1 && echo 1.1',
'echo 2 && sleep 2 && echo 2.2',
'echo 3 && sleep 3 && echo 3.3']
gens = [gen.Task(TestSubprocess(i).loop)
for i in cmds]
resobjs = yield gens
self.assertEqual(len(resobjs), 3)
self.assertEqual(int(resobjs[1].datalogging[-1][0] - resobjs[0].datalogging[-1][0]), 1)
self.assertEqual(int(resobjs[2].datalogging[-1][0] - resobjs[0].datalogging[-1][0]), 2)