-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_repl.py
61 lines (51 loc) · 1.39 KB
/
test_repl.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
52
53
54
55
56
57
58
59
60
61
import StringIO
import repl
def interaction(in_string, expected_output_string, expected_error_string):
istream = StringIO.StringIO(in_string)
ostream = StringIO.StringIO()
estream = StringIO.StringIO()
repl.repl(istream, ostream, estream)
assert ostream.getvalue() == expected_output_string
assert estream.getvalue() == expected_error_string
def test_variables():
in_string = """
a = 23
b = a * 2
b
"""
interaction(in_string, '46\n', '')
def test_error():
in_string = """
4 ^ 7
"""
interaction(in_string, '', 'Unrecognized:^ 7\n\n4\n')
def test_overflow_warning():
in_string = """
a = 2 *
"""
interaction(in_string, '', 'Warning: stuff unparsed on the line: [*]\n')
def test_counting():
in_string = """
counter_state = 0
cnt = 0
count ~ (counter_state, cnt=cnt+1, this)
counter_state = count
(counter_state cnt)
counter_state = count
counter_state = count
(counter_state cnt)
(counter_state cnt)
counter_state = count
(counter_state cnt)
"""
istream = StringIO.StringIO(in_string)
ostream = StringIO.StringIO()
estream = StringIO.StringIO()
repl.repl(istream, ostream, estream)
assert estream.getvalue() == ''
olines = ostream.getvalue().split('\n')
for i, ln in enumerate(olines): print i, ':', ln
assert olines[1] == '1'
assert olines[2] == '3'
assert olines[3] == '3'
assert olines[4] == '4'