Skip to content

Commit 8606b3c

Browse files
authored
Merge pull request #181 from rocky/test_crossversion
Crossversion Testing wip update.
2 parents 6033cee + 7c1dfbd commit 8606b3c

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

test_crossversion/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help clean get_sources setup_pyenv compile prepare test
1+
.PHONY: help clean get_sources setup_pyenv setup_uv compile prepare .prepare_msg test .mkdirs
22

33
SOURCE=./templates/source/
44
COMPILED=./templates/compiled/
@@ -29,18 +29,23 @@ clean:
2929
rm -rf $(COMPILED)/*
3030
rm -rf $(SERIALIZED)/*
3131

32+
.mkdirs:
33+
mkdir -p "$(SOURCE)" "$(COMPILED)" "$(SERIALIZED)"
34+
3235
#: copy all .py files in ./ -> ./templates/source/
3336
get_sources:
34-
cp -f *.py $(SOURCE)
37+
cp $(shell find . -name "*.py" | head -n 10 | xargs) $(SOURCE)
3538

3639
.python-version:
3740
tox --listenvs | xargs pyenv local
41+
3842
#: setup local pyenv versions to be used by tox
39-
setup_pyenv: .python-version
43+
setup_pyenv: .mkdirs .python-version
4044

4145
#: setup tox-uv so tox can use uv
42-
setup_uv:
46+
setup_uv: .mkdirs
4347
uv tool install tox --with tox-uv
48+
tox --listenvs | xargs uv python install
4449

4550
#: with each tox env, compile all sources in ./templates/source/ to ./templates/compiled/, then serialize with dis to ./templates/serialized/
4651
compile:

test_crossversion/USAGE.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Automated crossversion testing
22
This testing suite is used for automatic testing of differences found between xdis and dis.
3-
This is done by having a way to identically "serialize" important attributes in xdis and dis bytecodes.
4-
We then can check a diff between a serialized xdis and dis bytecode to find if xdis is parsing something incorrectly.
3+
This is done by having a way to identically "serialize" important attributes in bytecodes with xdis and dis.
4+
Using a diff between a bytecode serialized with xdis and dis, we can find if xdis is parsing something incorrectly.
55
Most tests should be ran using the makefile.
66

77
# Parsing results
8-
When running `make test`, tox will serialize bytecode to be put into text form. Given a bytecode compiled in 3.11 and natively disassembled, we go through each of our test versions, say 3.9 ... 3.14, and disassemble the same 3.11 bytecode.
8+
When running `make test`, two main steps take place. 1st, we compile and serialize bytecode in each target version. 2nd, we disasm the same bytecode using xdis, serialize again, and check the diff. In other words, given a bytecode compiled in 3.11 and natively disassembled (dis), we go through each of our test versions, say 3.9 ... 3.14, and disassemble the same 3.11 bytecode.
99
Given the 3.11 serialized disasembly, disassembled from 3.11, we take the diff between that and a serialized 3.11 disassembled from any of our test versions.
1010
This lets us see if there are any differences in how xdis handles native vs cross version.
1111

@@ -22,18 +22,20 @@ for native in test_vers:
2222

2323
Pytest will fail early, so not all tests may be ran.
2424

25-
# System Requirements
25+
# Usage
26+
## Requirements
2627
- `uv`
2728
- uv will handle everything on its own
29+
run `make setup_uv`
2830

2931
---OR---
3032

3133
- `pyenv` and `pyenv-virtualenv`
3234
- Each version needing to be tested should be installed with pyenv
3335
- `tox`
36+
run `make setup_pyenv`
3437

35-
# Usage
36-
## Makefile
38+
## Running tests
3739
Run `make` or `make help` to show the help menu for running and preparing tests, or with `remake`, `remake --tasks`.
3840

3941
To simply run tests, `make test` will copy some sources, prepare template files, and run tests.

test_crossversion/test_xdis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def __init__(self, pyc: Path, serialized_txt: Path) -> None:
2828
# read serialized bytecode
2929
self.serialized_dis = serialized_txt.read_text()
3030
self.serialized_xdis = serialize_pyc(pyc, use_xdis=True, output_file=None)
31-
# debug message
31+
# debug messages
3232
self.message = f"{SYS_VERSION}: Checking equivalence: {self.pyc_path} <---> {self.serialized_txt_path}"
33+
self.fail_message = f"Running version {SYS_VERSION}, failed equivalence; xdis:{self.pyc_path.name} != dis:{self.serialized_txt_path.name}"
3334

3435
def __str__(self) -> str:
3536
return self.message
@@ -64,12 +65,12 @@ def get_tests_by_version(v: str) -> Iterable[SerializedTestCase]:
6465
def test_version(version):
6566
"""Test each version in compiled template folder."""
6667
for case in get_tests_by_version(version):
67-
assert case.serialized_dis.splitlines() == case.serialized_xdis.splitlines()
68+
assert case.serialized_dis.splitlines() == case.serialized_xdis.splitlines(), case.fail_message
6869

6970

7071
### LESS VERBOSE (fail early) ###
7172
#@pytest.mark.parametrize(
7273
# "case", chain.from_iterable(get_tests_by_version(v) for v in get_versions())
7374
#)
7475
#def test_case(case: SerializedTestCase) -> None:
75-
# assert case.serialized_dis.splitlines() == case.serialized_xdis.splitlines()
76+
# assert case.serialized_dis.splitlines() == case.serialized_xdis.splitlines(), case.fail_message

0 commit comments

Comments
 (0)