Skip to content
Snippets Groups Projects
Commit e8d5f6a8 authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Fix Python decompilation tests with Python 3.10+. (Closes: #278)

parent d28c2d36
No related branches found
No related tags found
No related merge requests found
Pipeline #303771 passed
......@@ -17,6 +17,7 @@
# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
import pytest
import sys
from diffoscope.comparators.python import PycFile
......@@ -33,7 +34,11 @@ def test_identification(pyc1, pyc2):
def test_no_differences(pyc1):
assert pyc1.compare(pyc1) is None
# Disassembling bytecode prior to Python 3.10 is stable when applied to
# itself, otherwise various memory offsets (or memory addresses?) are
# non-deterministic.
if sys.version_info < (3, 10):
assert pyc1.compare(pyc1) is None
@pytest.fixture
......@@ -42,4 +47,8 @@ def differences(pyc1, pyc2):
def test_diff(differences):
assert_diff(differences[0], "pyc_expected_diff")
assert_diff(
differences[0],
"pyc_expected_diff",
lambda haystack, needle: haystack.startswith(needle),
)
......@@ -56,12 +56,12 @@ def get_data(filename):
return f.read()
def assert_diff(difference, filename):
def assert_diff(difference, filename, cmp=lambda x, y: x == y):
# Assign seen and expected values to local variables to improve contextual
# information in failed tests.
seen = difference.unified_diff
expected = get_data(filename)
assert seen == expected
assert cmp(seen, expected)
# https://code.activestate.com/recipes/576620-changedirectory-context-manager/#c3
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment