validation now uses xdis for python2 support

This commit is contained in:
Daniel Bradburn
2017-03-04 20:23:39 +01:00
parent d1e118afa3
commit cb3c5e7119
2 changed files with 11 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
# std
import string
# 3rd party
from hypothesis import given, assume, settings, example, strategies as st
from hypothesis import given, assume, strategies as st
import pytest
# uncompyle
from validate import validate_uncompyle

View File

@@ -2,18 +2,23 @@
from __future__ import print_function
# std
import os
import dis
import difflib
import subprocess
import tempfile
import functools
# compatability
import six
# uncompyle6 / xdis
from uncompyle6 import PYTHON_VERSION, deparse_code
from uncompyle6 import PYTHON_VERSION, IS_PYPY, deparse_code
# TODO : I think we can get xdis to support the dis api (python 3 version) by doing something like this there
from xdis.bytecode import Bytecode
from xdis.main import get_opcode
opc = get_opcode(PYTHON_VERSION, IS_PYPY)
Bytecode = functools.partial(Bytecode, opc=opc)
def _dis_to_text(co):
return dis.Bytecode(co).dis()
return Bytecode(co).dis()
def print_diff(original, uncompyled):
@@ -99,9 +104,8 @@ def are_code_objects_equal(co1, co2):
:return: True if the two code objects are approximately equal, otherwise False.
"""
# TODO : Use xdis for python2 compatability
instructions1 = dis.Bytecode(co1)
instructions2 = dis.Bytecode(co2)
instructions1 = Bytecode(co1)
instructions2 = Bytecode(co2)
for opcode1, opcode2 in zip(instructions1, instructions2):
if not are_instructions_equal(opcode1, opcode2):
return False