aboutsummaryrefslogtreecommitdiffstats
path: root/tests/worker.py
blob: 49d8bd1586aded467613594d754b14bf31632347 (plain) (blame)
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
39
40
41
42
43
44
45
46
#!/usr/bin/env python

import unittest
import pexpect

from re import search, escape
from os import kill
from signal import SIGINT, SIGUSR1

class PexpectTest(unittest.TestCase):

    def setUp(self):
        self.worker = pexpect.spawn('python ../worker/worker.py')
        # worker should always be very fast to span
        self.expect('#0#\r\n')

    def sendlines(self, lines):
        for line in lines:
            self.worker.sendline(line)
            self.worker.expect(line+'\r\n')

    def expect(self, v, timeout = 3):
        self.worker.expect(v, timeout)
        self.assertEqual(self.worker.before, "")

    def test_exit(self):
        self.sendlines(['exit'])
        self.expect(pexpect.EOF)

    def test_basic_noop(self):
        self.sendlines(['noop'])
        self.expect('#1#\r\n')
        self.test_exit()
    
    def test_basic_ping(self):
        self.sendlines(['ping'])
        self.expect('ALIVE\r\n#1#\r\n')
        self.test_exit()

    def test_basic_glob(self):
        self.sendlines(['glob', '/*bin'])
        self.expect('2\r\n(/bin\r\n/sbin|/sbin\r\n/bin)\r\n')
        self.test_exit()

if __name__ == '__main__':
    unittest.main()