-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate_doctest_generated.py
More file actions
executable file
·162 lines (115 loc) · 3.99 KB
/
update_doctest_generated.py
File metadata and controls
executable file
·162 lines (115 loc) · 3.99 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3.10
""" This script should be run each time the CPython test suite is updated.
It extracts the doctests from the objects specified manually inside this script,
and converts them into proper statements that then can be subject to real tests
with Nuitka compilation.
"""
# Find common code relative in file system. Not using packages for test stuff.
import os
import sys
sys.path.insert(
0,
os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..")
),
)
# isort:start
import test.test_cmd
import test.test_deque
import test.test_descrtut
import test.test_extcall
import test.test_generators
import test.test_genexps
import test.test_itertools
import test.test_listcomps
import test.test_metaclass
import test.test_setcomps
import test.test_unpack
import test.test_unpack_ex
import test.test_weakref
from nuitka.tools.quality.auto_format.AutoFormat import cleanupWindowsNewlines
from nuitka.tools.testing.Common import goMainDir
from nuitka.tools.testing.DocTests import convertToPython
goMainDir()
if not os.path.exists("doctest_generated"):
os.mkdir("doctest_generated")
def saveAsGeneratedDoctest(name, value, line_filter=None, prefix=""):
if prefix:
prefix = prefix + "\n"
filename = os.path.join("doctest_generated", name)
with open(filename, "w") as output:
output.write(prefix)
if type(value) in (tuple, list):
for val in value:
output.write("\n")
output.write("#" * 80)
output.write("\n")
output.write(convertToPython(val, line_filter))
else:
output.write(convertToPython(value, line_filter))
cleanupWindowsNewlines(filename)
saveAsGeneratedDoctest(
"test_cmd.py",
test.test_cmd.samplecmdclass.__doc__,
prefix="from test.test_cmd import samplecmdclass",
)
saveAsGeneratedDoctest("test_deque.py", test.test_deque.libreftest)
saveAsGeneratedDoctest(
"test_descrtut.py",
tuple(sorted(test.test_descrtut.__test__.values())),
prefix="from test.test_descrtut import defaultdict,defaultdict2,sortdict\nimport pprint",
)
saveAsGeneratedDoctest(
"test_extcall.py",
test.test_extcall.__doc__,
prefix="import test.support as support",
)
def filter_generators(line):
# Driven by returns, pylint: disable=too-many-return-statements
if line.find("(yield 21)") != -1:
return True
elif line.find("gi_frame") != -1:
return True
elif line.find("gi_code") != -1:
return True
elif line.find("dir(i)") != -1:
return True
elif line.find("(i for i in (yield) if (yield))") != -1:
return True
elif line.find("isinstance(i, types.GeneratorType)") != -1:
return True
else:
return False
saveAsGeneratedDoctest(
"test_generators.py",
tuple(sorted(test.test_generators.__test__.values())),
line_filter=filter_generators,
prefix="from test.test_generators import Knights",
)
def filter_genexps(line):
if (
line.find(
"set(attr for attr in dir(g) if not attr.startswith('__')) >= expected"
)
!= -1
):
return True
elif line.find("isinstance(g, types.GeneratorType)") != -1:
return True
else:
return False
saveAsGeneratedDoctest(
"test_genexps.py", test.test_genexps.doctests, line_filter=filter_genexps
)
saveAsGeneratedDoctest(
"test_itertools.py",
test.test_itertools.libreftest,
prefix="from itertools import *",
)
saveAsGeneratedDoctest("test_listcomps.py", test.test_listcomps.doctests)
saveAsGeneratedDoctest("test_setcomps.py", test.test_setcomps.doctests)
saveAsGeneratedDoctest("test_unpack.py", test.test_unpack.doctests)
saveAsGeneratedDoctest("test_unpack_ex.py", test.test_unpack_ex.doctests)
saveAsGeneratedDoctest("test_weakref.py", test.test_weakref.libreftest)
saveAsGeneratedDoctest("test_ieee754.py", open("test/ieee754.txt").read())
saveAsGeneratedDoctest("test_metaclass.py", test.test_metaclass.doctests)