-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unrepl.py
83 lines (73 loc) · 1 KB
/
test_unrepl.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from unrepl import unrepl
import pytest
def test1():
code = """\
>>> a = 1
>>> b = 2
>>> a + b
3
"""
assert (
unrepl(code, use_print_statements=True)
== """\
a = 1
b = 2
_ = a + b; print(repr(_)) # a + b
# 3
"""
)
assert (
unrepl(code, use_print_statements=False)
== """\
a = 1
b = 2
a + b
# 3
"""
)
def test2():
code = """\
>>> for i in range(4):
... i * i
...
0
1
4
9
>>> _
9
"""
assert (
unrepl(code, use_print_statements=True)
== """\
for i in range(4):
_ = i * i; print(repr(_)) # i * i
# 0
# 1
# 4
# 9
_ = _; print(repr(_)) # _
# 9
"""
)
assert (
unrepl(code, use_print_statements=False)
== """\
for i in range(4):
i * i
# 0
# 1
# 4
# 9
_
# 9
"""
)
def test_no_repl():
with pytest.raises(ValueError):
x = unrepl("")
with pytest.raises(ValueError):
x = unrepl(">>>")
x = unrepl(">>> ")
if __name__ == "__main__":
pytest.main(["-vv", "-s", __file__])