-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_functional.py
51 lines (40 loc) · 1.68 KB
/
test_functional.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import logging
from unittest import TestCase
from interactive_cmd import InteractiveCommand
class BashTests(TestCase):
def setUp(self):
self.ic = InteractiveCommand('bash')
self.ic.start()
logging.disable(logging.CRITICAL)
def tearDown(self):
logging.disable(logging.NOTSET)
self.ic.kill()
def test_echo_smoke(self):
self.ic.writeline('echo foo')
match = self.ic.wait_until_matched(r'foo', timeout=1)
self.assertEqual(match.group(), 'foo')
def test_echo_fail(self):
self.ic.writeline('echo bar')
self.assertIsNone(self.ic.wait_until_matched(r'foo', timeout=0.1))
def test_echo_delayed(self):
self.ic.writeline('echo bar; sleep 1; echo foo')
match = self.ic.wait_until_matched(r'foo', timeout=2)
self.assertEqual(match.group(), 'foo')
def test_echo_delayed_fail(self):
self.ic.writeline('echo bar; sleep 1; echo foo')
self.assertIsNone(self.ic.wait_until_matched(r'foo', timeout=0.5))
def test_echo_after_exit_raises(self):
self.ic.writeline('exit')
with self.assertRaises(BrokenPipeError):
self.ic.writeline('echo hello')
self.assertTrue(self.ic.is_running)
def test_echo_to_closed_stdin_raises(self):
with self.assertRaises(BrokenPipeError):
self.ic.writeline('exec 0<&-')
self.ic.writeline('echo hello')
def test_write_repeated_smoke(self):
self.ic.writeline('true') # make sure $? is 0
match = self.ic.write_repeated(
command='test $? -eq 1 && echo "yay"',
pattern='yay', attempts=3, timeout=0.1)
self.assertEqual(match.group(), 'yay')