8000 Add bash script to autotest cpython lib by MegasKomnenos · Pull Request #4870 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Add bash script to autotest cpython lib #4870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
8000 Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scripts/autocheck/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
To use, open cmd and run run_autotest.py

The script assumes that the script is being run from RustPython/scripts/clib,
and that both RustPython and cpython project directories are located under a same parent directory, aka that they are siblings

If either of those assumptions are false, then you must provide a correct path when running run_autotest.py

The script will try to test every component in targets.txt
137 changes: 137 additions & 0 deletions scripts/autocheck/autocheck.py
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import argparse
import os
import shutil
import subprocess
import sys

from dataclasses import dataclass
from pathlib import Path
from typing import List

def subprocess_run(*args, **kwargs):
# print('Process run:', *args, kwargs, file=sys.stderr)
return subprocess.run(*args, **kwargs)

@dataclass
class LibEntry:
name: str
lib_exist: bool # Checks whether the library file existed in RustPython/Lib prior to testing
test_exist: bool # Checks whether the test file existed in RustPython/Lib/test prior to testing
test_do: bool # Checks if both the library file and the test file existed in cpython and therefore is possible to test
test_ok: bool # Checks if the test returned OK or not
path_cpython_lib: str
path_cpython_test: str
path_rpython_lib: str
path_rpython_test: str
path_tpython_lib: str
path_tpython_test: str

def __init__(self, name: str, CPYTHON_PATH: str, RPYTHON_PATH: str):
self.name = name

self.path_cpython_lib = os.path.join(CPYTHON_PATH, "Lib", f"{self.name}.py")
self.path_rpython_lib = os.path.join(RPYTHON_PATH, "Lib", f"{self.name}.py")
self.path_tpython_lib = os.path.join(RPYTHON_PATH, "LibTest", f"{self.name}.py")

self.path_cpython_test = os.path.join(CPYTHON_PATH, "Lib", "test", f"test_{self.name}.py")
self.path_rpython_test = os.path.join(RPYTHON_PATH, "Lib", "test", f"test_{self.name}.py")
self.path_tpython_test = os.path.join(RPYTHON_PATH, "LibTest", "test", f"test_{self.name}.py")

self.lib_exist = os.path.isfile(self.path_tpython_lib)
self.test_exist = os.path.isfile(self.path_tpython_test)
self.test_do = os.path.isfile(self.path_cpython_lib) and os.path.isfile(self.path_cpython_test)

def run(self, RUSTEXECPATH: str):
if self.test_do:
shutil.copyfile(self.path_cpython_lib, self.path_tpython_lib)
shutil.copyfile(self.path_cpython_test, self.path_tpython_test)

result = subprocess_run(
[RUSTEXECPATH, "-q", self.path_tpython_test],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env={"RUSTPYTHONPATH": "LibTest"}
)
result = result.stdout.decode("utf-8")

self.test_ok = "OK" in result

if self.lib_exist:
shutil.copyfile(self.path_rpython_lib, self.path_tpython_lib)
else:
os.remove(self.path_tpython_lib)

if self.test_exist:
shutil.copyfile(self.path_rpython_test, self.path_tpython_test)
else:
os.remove(self.path_tpython_test)

def to_string(self):
message = [f"{self.name}:"]

if self.test_do:
if self.test_ok:
message.append("OK")
else:
message.append("Failed")
else:
message.append("No cpython lib or test file")

return ' '.join(message)

def main():
CURRENT_PATH = Path(__file__)

parser = argparse.ArgumentParser(description="Test cpython library")
parser.add_argument(
"--cpython",
nargs=1,
default=os.path.join(
CURRENT_PATH.parents[3],
"cpython"
),
required=False,
help="Local cpython path."
)
parser.add_argument(
"--rustpython",
nargs=1,
default=CURRENT_PATH.parents[2],
required=False,
help="Local RustPython path."
)
args = vars(parser.parse_args())
CPYTHON_PATH = args["cpython"]
RPYTHON_PATH = args["rustpython"]

if isinstance(CPYTHON_PATH, list):
CPYTHON_PATH = CPYTHON_PATH[0]
if isinstance(RPYTHON_PATH, list):
RPYTHON_PATH = RPYTHON_PATH[0]

shutil.copytree(
os.path.join(RPYTHON_PATH, "Lib"),
os.path.join(RPYTHON_PATH, "LibTest")
)

library_list: List[LibEntry] = []

with open(os.path.join(CURRENT_PATH.parent, "targets.txt"), 'r') as f:
for line in f:
line = line.split('#')[0]
line = line.strip()
if line:
library_list.append(LibEntry(line, CPYTHON_PATH, RPYTHON_PATH))

subprocess_run(["cargo", "build", "--release", "-q"])
REXECPATH = os.path.join(CURRENT_PATH.parents[2], "target", "release", "rustpython")

try:
for entry in library_list:
entry.run(REXECPATH)
print(entry.to_strin 8000 g())
finally:
shutil.rmtree(os.path.join(RPYTHON_PATH, "LibTest"))

if __name__ == "__main__":
main()
156 changes: 156 additions & 0 deletions scripts/autocheck/targets.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#__future__
__hello__
_collections_abc
_compat_pickle
_compression
_markupbase
_osx_support
_py_abc
_pycodecs
_pydecimal
_pyio
_sitebuiltins
_threading_local
_weakrefset
abc
aifc
antigravity
argparse
ast
asynchat
asyncore
base64
bdb
binhex
bisect
bz2
calendar
cgi
cgitb
chunk
cmd
code
codecs
codeop
colorsys
compileall
configparser
contextlib
contextvars
copy
copyreg
csv
dataclasses
datetime
decimal
difflib
dis
doctest
enum
filecmp
fileinput
fnmatch
formatter
fractions
ftplib
functools
gc
genericpath
getopt
getpass
gettext
glob
graphlib
gzip
hashlib
heapq
hmac
imghdr
imp
inspect
io
ipaddress
keyword
linecache
locale
mailbox
mimetypes
netrc
nntplib
ntpath
nturl2path
numbers
opcode
operator
optparse
os
pathlib
pdb
pickle
pickletools
pkgutil
platform
plistlib
posixpath
pprint
pty
py_compile
pydoc
queue
quopri
random
re
reprlib
rlcompleter
runpy
sched
secrets
selectors
shelve
shlex
shutil
#signal
site
smtpd
smtplib
sndhdr
socket
socketserver
sre_compile
sre_constants
sre_parse
ssl
stat
statistics
string
stringprep
struct
subprocess
sunau
sysconfig
tabnanny
tarfile
telnetlib
tempfile
textwrap
this
threading
timeit
token
tokenize
trace
traceback
tty
types
typing
uu
uuid 4C9D
warnings
weakref
webbrowser
xdrlib
zipapp
zipfile
zipimport

# Make sure file ends with empty space
0