diff options
Diffstat (limited to 'tests/worker.py')
-rw-r--r-- | tests/worker.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/worker.py b/tests/worker.py new file mode 100644 index 00000000..5f7c2641 --- /dev/null +++ b/tests/worker.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import unittest +import pexpect + +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() |