Skip to content

Commit 21e890d

Browse files
Merge pull request RustPython#802 from andrew-ld/master
use a code generator for not implemented tests
2 parents 7910c95 + 3aa110a commit 21e890d

File tree

6 files changed

+57
-875
lines changed

6 files changed

+57
-875
lines changed

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
snippets/whats_left_to_implement.py

tests/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
21
# Test snippets
32

43
This directory contains two sets of test snippets which can be run in
54
Python. The `snippets/` directory contains functional tests, and the
65
`benchmarks/` directory contains snippets for use in benchmarking
76
RustPython's performance.
87

8+
## Generates the test for not implemented methods
9+
10+
run using cpython not_impl_gen.py it automatically generate a
11+
test snippet to check not yet implemented methods
912

1013
## Running with CPython + RustPython
1114

@@ -15,4 +18,3 @@ compilation to bytecode. When this is done, run the bytecode with rustpython.
1518
## Running with RustPython
1619

1720
The other option is to run all snippets with RustPython.
18-

tests/generator/not_impl_footer.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
not_implemented = [(name, method)
2+
for name, (val, methods) in expected_methods.items()
3+
for method in methods
4+
if not hasattr(val, method)]
5+
6+
for r in not_implemented:
7+
print(r[0], ".", r[1], sep="")
8+
if not not_implemented:
9+
print("Not much \\o/")
10+
11+
if platform.python_implementation() == "CPython":
12+
assert len(not_implemented) == 0, "CPython should have all the methods"

tests/generator/not_impl_header.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# WARNING: THIS IS AN AUTOMATICALLY GENERATED FILE
2+
# EDIT tests/not_impl_gen.py, NOT THIS FILE.
3+
# RESULTS OF THIS TEST DEPEND ON THE CPYTHON
4+
# VERSION USED TO RUN not_impl_gen.py
5+
6+
import platform
7+

tests/not_impl_gen.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
objects = [
2+
bool,
3+
bytearray,
4+
bytes,
5+
complex,
6+
dict,
7+
float,
8+
frozenset,
9+
int,
10+
iter,
11+
list,
12+
memoryview,
13+
range,
14+
set,
15+
str,
16+
tuple,
17+
object
18+
]
19+
20+
header = open("generator/not_impl_header.txt")
21+
footer = open("generator/not_impl_footer.txt")
22+
output = open("snippets/whats_left_to_implement.py", "w")
23+
24+
output.write(header.read())
25+
output.write("expected_methods = {\n")
26+
27+
for obj in objects:
28+
output.write(f" '{obj.__name__}': ({obj.__name__}, [\n")
29+
output.write("\n".join(f" '{attr}'," for attr in dir(obj)))
30+
output.write("\n ])," + ("\n" if objects[-1] == obj else "\n\n"))
31+
32+
output.write("}\n\n")
33+
output.write(footer.read())

0 commit comments

Comments
 (0)