forked from Rust-related/RustPython
Clean test code
This commit is contained in:
20
README.md
20
README.md
@@ -30,15 +30,12 @@ Or use pip to install extra modules:
|
||||
|
||||
# Code organization
|
||||
|
||||
- parser: python lexing, parsing and ast
|
||||
- vm: python virtual machine
|
||||
- src: using the other subcrates to bring rustpython to life.
|
||||
|
||||
The files in the top level directory are from [windelbouwman/rspython][rspython] which contains an implementation of the parser and vm in `src/`
|
||||
|
||||
An alternative implementation of python virtual machine that are compatible with CPython parser are from [shinglyu/RustPython][rustpython] and is located in the `VM/` folder.
|
||||
|
||||
We are in the process of merging the two implementation to form a single implementation.
|
||||
- `parser`: python lexing, parsing and ast
|
||||
- `vm`: python virtual machine
|
||||
- `src`: using the other subcrates to bring rustpython to life.
|
||||
- `docs`: documentation (work in progress)
|
||||
- `py_code_object`: CPython bytecode to rustpython bytecode convertor (work in progress)
|
||||
- `tests`: integration test snippets
|
||||
|
||||
# Community
|
||||
|
||||
@@ -48,8 +45,6 @@ Chat with us on [gitter][gitter].
|
||||
|
||||
The initial work was based on [windelbouwman/rspython](https://github.com/windelbouwman/rspython) and [shinglyu/RustPython](https://github.com/shinglyu/RustPython)
|
||||
|
||||
[rspython]: https://github.com/windelbouwman/rspython
|
||||
[rustpython]: https://github.com/shinglyu/RustPython
|
||||
[gitter]: https://gitter.im/rustpython/Lobby
|
||||
|
||||
# Links
|
||||
@@ -57,3 +52,6 @@ The initial work was based on [windelbouwman/rspython](https://github.com/windel
|
||||
These are some useful links to related projects:
|
||||
|
||||
- https://github.com/ProgVal/pythonvm-rust
|
||||
- https://github.com/shinglyu/RustPython
|
||||
- https://github.com/windelbouwman/rspython
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
virtualenv venv --python=python3
|
||||
source venv/bin/activate
|
||||
pip install bytecode
|
||||
|
||||
source ~/.cargo/env
|
||||
rustup install nightly
|
||||
rustup default nightly
|
||||
@@ -1 +0,0 @@
|
||||
byteplay==0.2
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: test.sh <tests/test_case.py> [--bytecode|--dis]
|
||||
# --bytecode: print the bytecode
|
||||
# --dis: run dis
|
||||
|
||||
set -e
|
||||
|
||||
MODE="run"
|
||||
|
||||
case "${2}" in
|
||||
"--bytecode" )
|
||||
MODE="view_bytecode"
|
||||
;;
|
||||
"--dis" )
|
||||
MODE="run_dis"
|
||||
;;
|
||||
* )
|
||||
;;
|
||||
esac
|
||||
|
||||
TESTCASE=$(basename ${1})
|
||||
#TMP_FILE="test_${TESTCASE}.bytecode"
|
||||
TMP_FILE="${1}.bytecode"
|
||||
|
||||
python compile_code.py "${1}" > "${TMP_FILE}"
|
||||
|
||||
echo "${MODE}"
|
||||
case "${MODE}" in
|
||||
"run" )
|
||||
cd RustPython
|
||||
RUST_BACKTRACE=1 cargo run "../${TMP_FILE}"
|
||||
;;
|
||||
"view_bytecode" )
|
||||
cat "${TMP_FILE}" | python -m json.tool
|
||||
;;
|
||||
"run_dis" )
|
||||
python -m dis "${1}"
|
||||
;;
|
||||
* )
|
||||
echo "Not a valid mode!"
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
:: win bat
|
||||
|
||||
|
||||
cd tests
|
||||
|
||||
for %%i in (*.py) do python ../compile_code.py %%i >../bytes/%%i.bytecode
|
||||
cd ..
|
||||
|
||||
REM cd RustPython
|
||||
REM for %%i in (../bytes/*.vbytecode) do echo %%i
|
||||
REM cd ..
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# set -e
|
||||
|
||||
source venv/bin/activate
|
||||
#TESTCASE=tests/variables.py
|
||||
# TESTCASE=tests/variables.py
|
||||
#TESTCASE=tests/minimum.py
|
||||
unexpected_count=0
|
||||
expected_count=0
|
||||
fail_titles=$""
|
||||
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
for TESTCASE in $(find ../tests -name \*.py -print)
|
||||
do
|
||||
echo "TEST START: ${TESTCASE}"
|
||||
echo "--------------------------------"
|
||||
FILENAME="$(basename ${TESTCASE})"
|
||||
xfail=false
|
||||
if [ "${FILENAME:0:6}" = "xfail_" ]; then
|
||||
echo "Expected FAIL"
|
||||
xfail=true
|
||||
fi
|
||||
|
||||
|
||||
python compile_code.py $TESTCASE > $TESTCASE.bytecode
|
||||
cd RustPython
|
||||
cargo run ../$TESTCASE.bytecode
|
||||
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
if [ "${xfail}" = true ]; then
|
||||
echo "== FAIL as expected =="
|
||||
let expected_count=expected_count+1
|
||||
else
|
||||
printf "${RED}== FAIL, expected PASS ==${NC}\n"
|
||||
let unexpected_count=unexpected_count+1
|
||||
fail_titles=$"${fail_titles}\n${TESTCASE}\t${RED}FAIL${NC} (expected PASS)"
|
||||
fi
|
||||
else
|
||||
if [ "${xfail}" = true ]; then
|
||||
printf "${RED}== PASS, expected FAIL ==${NC}\n"
|
||||
let unexpected_count=unexpected_count+1
|
||||
let unexpected_count=unexpected_count+1
|
||||
fail_titles=$"${fail_titles}\n${TESTCASE}\t${RED}PASS${NC} (expected FAIL)"
|
||||
else
|
||||
echo "== PASS as expected =="
|
||||
let expected_count=expected_count+1
|
||||
fi
|
||||
fi
|
||||
cd ..
|
||||
echo "--------------------------------"
|
||||
|
||||
done
|
||||
|
||||
echo "Summary"
|
||||
echo "================"
|
||||
printf "${RED}${unexpected_count} unexpected${NC}, ${expected_count} expected"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "unexpected results:"
|
||||
printf "${fail_titles}"
|
||||
echo ""
|
||||
echo "================"
|
||||
@@ -83,12 +83,13 @@ def create_test_function(cls, filename, method):
|
||||
setattr(cls, test_function_name, test_function)
|
||||
|
||||
|
||||
def populate(cls):
|
||||
""" Decorator function which can populate a unittest.TestCase class """
|
||||
for method in ['cpython', 'cpython_bytecode', 'rustpython']:
|
||||
def populate(method):
|
||||
def wrapper(cls):
|
||||
""" Decorator function which can populate a unittest.TestCase class """
|
||||
for filename in get_test_files():
|
||||
create_test_function(cls, filename, method)
|
||||
return cls
|
||||
return cls
|
||||
return wrapper
|
||||
|
||||
|
||||
def get_test_files():
|
||||
@@ -102,6 +103,8 @@ def get_test_files():
|
||||
yield os.path.abspath(filepath)
|
||||
|
||||
|
||||
@populate
|
||||
@populate('cpython')
|
||||
# @populate('cpython_bytecode')
|
||||
@populate('rustpython')
|
||||
class SampleTestCase(unittest.TestCase):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user