-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdoctest.py
More file actions
executable file
·49 lines (43 loc) · 858 Bytes
/
testdoctest.py
File metadata and controls
executable file
·49 lines (43 loc) · 858 Bytes
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
def add(a, b):
"""
>>> add(1,2)
3
>>> add(1,1)
2
"""
return a + b
def divide(a, b):
"""
>>> divide(4,2)
2
>>> divide(4,0)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "testdoctest.py", line 12, in divide
return a / b
ZeroDivisionError: integer division or modulo by zero
"""
return a / b
__test__ = {
'compose add(divide())':
"""
>>> divide(add(2,2),2)
2
""",
'compose add(divide()) (built to fail)':
"""
>>> divide(add(2,2),2)
22
""",
}
def _hidden():
"""
>>> _hidden()
"You can't see me, doctest!"
"""
return "You can't see me, doctest!"
def _test():
import doctest
return doctest.testmod()
if __name__ == "__main__":
_test()