Skip to content
Merged
Show file tree
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
30 changes: 18 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ jobs:
':benches/**' \
':example_projects/**' \
':extra_tests/snippets/**' \
':extra_tests/test_snippets.py' \
':extra_tests/rustpython_wasi.sh' \
':extra_tests/requirements.txt' \
':.github/workflows/ci.yaml' \
; then
echo "changed=false" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -1055,7 +1058,6 @@ jobs:
builtin_memoryview
builtin_open
builtin_posixshmem
builtin_slice
builtin_str
builtin_thread
cli_int_max_str_digits
Expand Down Expand Up @@ -1179,19 +1181,23 @@ jobs:
- name: build rustpython
if: env.RUN_WASM_WASI == 'true'
run: cargo build --locked --profile wasm-release --target wasm32-wasip1 --no-default-features --features freeze-stdlib,stdlib,stdio,importlib,host_env,doc,ucd_3_2_0 --verbose
- name: Setup Python for the snippet harness
if: env.RUN_WASM_WASI == 'true'
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version-file: .python-version

- name: Install snippet harness dependencies
if: env.RUN_WASM_WASI == 'true'
run: python -m pip install -r extra_tests/requirements.txt

- name: run snippets
if: env.RUN_WASM_WASI == 'true'
run: |
exclude=" $WASM_WASI_SNIPPET_EXCLUDE "
for path in extra_tests/snippets/*.py; do
name=$(basename "$path" .py)
case "$exclude" in
*" $name "*) continue ;;
esac
echo "::group::${path}"
wasmer run --volume "$(pwd)" target/wasm32-wasip1/wasm-release/rustpython.wasm -- "$(pwd)/${path}"
echo "::endgroup::"
done
working-directory: extra_tests
env:
RUSTPYTHON: ${{ github.workspace }}/extra_tests/rustpython_wasi.sh
RUSTPYTHON_SNIPPET_EXCLUDE: ${{ env.WASM_WASI_SNIPPET_EXCLUDE }}
run: pytest -v test_snippets.py -k test_rustpython_
- name: run cpython unittest
if: env.RUN_WASM_WASI == 'true'
run: |
Expand Down
7 changes: 7 additions & 0 deletions extra_tests/rustpython_wasi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail

repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
exec wasmer run --volume "$repo_root" \
--env "RUSTPYTHONPATH=$repo_root/Lib" \
"$repo_root/target/wasm32-wasip1/wasm-release/rustpython.wasm" -- "$@"
33 changes: 33 additions & 0 deletions extra_tests/test_snippet_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from unittest.mock import patch

import test_snippets


class SnippetSelectionTests(unittest.TestCase):
def make_test(self, method, name):
class Tests:
pass

test_snippets.create_test_function(Tests, f"snippets/{name}.py", method, None)
return getattr(Tests, f"test_{method}_{name}")

def test_exclusion_matches_the_whole_snippet_name(self):
with patch.object(test_snippets, "RUSTPYTHON_SNIPPET_EXCLUDE", {"builtin_str"}):
excluded = self.make_test("rustpython", "builtin_str")
sibling = self.make_test("rustpython", "builtin_str_add")

self.assertTrue(excluded.__unittest_skip__)
self.assertFalse(getattr(sibling, "__unittest_skip__", False))

def test_exclusion_does_not_change_cpython_reference_tests(self):
with patch.object(test_snippets, "RUSTPYTHON_SNIPPET_EXCLUDE", {"builtin_str"}):
reference = self.make_test("cpython", "builtin_str")

self.assertFalse(getattr(reference, "__unittest_skip__", False))

def test_no_exclusions_keeps_the_native_default(self):
with patch.object(test_snippets, "RUSTPYTHON_SNIPPET_EXCLUDE", set()):
test = self.make_test("rustpython", "builtin_str")

self.assertFalse(getattr(test, "__unittest_skip__", False))
11 changes: 11 additions & 0 deletions extra_tests/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def run_via_cpython(filename):
ROOT_DIR, "target/release/rustpython"
)
RUSTPYTHON_BINARY = os.path.abspath(RUSTPYTHON_BINARY)
RUSTPYTHON_SNIPPET_EXCLUDE = set(
os.environ.get("RUSTPYTHON_SNIPPET_EXCLUDE", "").split()
)


def run_via_rustpython(filename, test_type):
Expand All @@ -71,6 +74,14 @@ def create_test_function(cls, filename, method, test_type):
def test_function(self):
perform_test(filename, method, test_type)

if (
method == "rustpython"
and os.path.splitext(snippet_filename)[0] in RUSTPYTHON_SNIPPET_EXCLUDE
):
test_function = unittest.skip("excluded by RUSTPYTHON_SNIPPET_EXCLUDE")(
test_function
)

if hasattr(cls, test_function_name):
raise ValueError("Duplicate test case {}".format(test_function_name))
setattr(cls, test_function_name, test_function)
Expand Down
Loading