diff --git a/test/Makefile b/test/Makefile index 72bea477..c5ac3143 100644 --- a/test/Makefile +++ b/test/Makefile @@ -98,6 +98,16 @@ check-bytecode-2.4: check-bytecode-2.5: $(PYTHON) test_pythonlib.py --bytecode-2.5 +#: Get grammar coverage for Python 2.6 +grammar-coverage-2.6: + SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6 + SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9 + +#: Get grammar coverage for Python 2.7 +grammar-coverage-2.7: + SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pythonlib.py --bytecode-2.7 + SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pyenvlib.py --2.7.13 + #: Check deparsing Python 2.6 check-bytecode-2.6: $(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify diff --git a/test/bytecode_2.6/01_ops.pyc b/test/bytecode_2.6/01_ops.pyc new file mode 100644 index 00000000..db74d307 Binary files /dev/null and b/test/bytecode_2.6/01_ops.pyc differ diff --git a/test/bytecode_2.7/01_ops.pyc b/test/bytecode_2.7/01_ops.pyc new file mode 100644 index 00000000..15c7e005 Binary files /dev/null and b/test/bytecode_2.7/01_ops.pyc differ diff --git a/test/simple_source/bug22/01_ops.py b/test/simple_source/bug22/01_ops.py new file mode 100644 index 00000000..65f0965f --- /dev/null +++ b/test/simple_source/bug22/01_ops.py @@ -0,0 +1,10 @@ +# Statements to beef up grammar coverage rules +# Force "inplace" ops +y = +10 # UNARY_POSITIVE +y /= 1 # INPLACE_DIVIDE +y %= 4 # INPLACE_MODULO +y **= 1 # INPLACE POWER +y >>= 2 # INPLACE_RSHIFT +y <<= 2 # INPLACE_LSHIFT +y //= 1 # INPLACE_TRUE_DIVIDE +`y` # UNARY_CONVERT - No in Python 3.x diff --git a/test/test_pyenvlib.py b/test/test_pyenvlib.py index dcedf2c3..a9bb408a 100755 --- a/test/test_pyenvlib.py +++ b/test/test_pyenvlib.py @@ -30,7 +30,7 @@ from fnmatch import fnmatch TEST_VERSIONS=('2.3.7', '2.4.6', '2.5.6', '2.6.9', 'pypy-2.4.0', 'pypy-2.6.1', 'pypy-5.0.1', 'pypy-5.3.1', - '2.7.10', '2.7.11', '2.7.12', + '2.7.10', '2.7.11', '2.7.12', '2.7.13', '3.0.1', '3.1.5', '3.2.6', '3.3.5', '3.3.6', '3.4.2', '3.5.1', '3.6.0') @@ -106,28 +106,40 @@ def do_tests(src_dir, patterns, target_dir, start_with=None, do_verify=False): if __name__ == '__main__': import getopt, sys - do_verify = False + do_coverage = do_verify = False test_dirs = [] start_with = None test_options_keys = list(test_options.keys()) test_options_keys.sort() opts, args = getopt.getopt(sys.argv[1:], '', - ['start-with=', 'verify', 'weak-verify', 'all', ] \ + ['start-with=', 'verify', 'weak-verify', + 'coverage', 'all', ] \ + test_options_keys ) + vers = '' for opt, val in opts: if opt == '--verify': do_verify = True if opt == '--weak-verify': do_verify = 'weak' + if opt == '--coverage': + do_coverage = True elif opt == '--start-with': start_with = val elif opt[2:] in test_options_keys: - test_dirs.append(test_options[opt[2:]]) + triple = test_options[opt[2:]] + vers = triple[-1] + test_dirs.append(triple) elif opt == '--all': + vers = 'all' for val in test_options_keys: test_dirs.append(test_options[val]) + if do_coverage: + os.environ['SPARK_PARSER_COVERAGE'] = ( + '/tmp/spark-grammar-%s.cover' % vers + ) + for src_dir, pattern, target_dir in test_dirs: if os.path.exists(src_dir): target_dir = os.path.join(target_base, target_dir) diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index 8deb221c..fa60bf70 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -190,6 +190,7 @@ if __name__ == '__main__': test_options_keys.sort() opts, args = getopt.getopt(sys.argv[1:], '', ['start-with=', 'verify', 'weak-verify', 'all', 'compile', + 'coverage', 'no-rm'] \ + test_options_keys ) if not opts: help() @@ -198,7 +199,8 @@ if __name__ == '__main__': 'do_compile': False, 'do_verify': False, 'start_with': None, - 'rmtree' : True + 'rmtree' : True, + 'coverage' : False } for opt, val in opts: @@ -217,11 +219,18 @@ if __name__ == '__main__': elif opt == '--all': for val in test_options_keys: test_dirs.append(test_options[val]) + elif opt == '--coverage': + test_opts['coverage'] = True else: help() pass pass + if test_opts['coverage']: + os.environ['SPARK_PARSER_COVERAGE'] = ( + '/tmp/spark-grammar-%s.cover' % test_dirs[0][-1] + ) + last_compile_version = None for src_dir, pattern, target_dir, compiled_version in test_dirs: if os.path.isdir(src_dir): diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index e6b22134..0790fb1b 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -73,7 +73,7 @@ TABLE_DIRECT = { 'BINARY_MULTIPLY': ( '*' ,), 'BINARY_DIVIDE': ( '/' ,), 'BINARY_MATRIX_MULTIPLY': ( '@' ,), - 'BINARY_TRUE_DIVIDE': ( '/' ,), + 'BINARY_TRUE_DIVIDE': ( '/' ,), # Not in <= 2.1 'BINARY_FLOOR_DIVIDE': ( '//' ,), 'BINARY_MODULO': ( '%%',), 'BINARY_POWER': ( '**',), @@ -87,7 +87,7 @@ TABLE_DIRECT = { 'INPLACE_MULTIPLY': ( '*=' ,), 'INPLACE_MATRIX_MULTIPLY': ( '@=' ,), 'INPLACE_DIVIDE': ( '/=' ,), - 'INPLACE_TRUE_DIVIDE': ( '/=' ,), + 'INPLACE_TRUE_DIVIDE': ( '/=' ,), # Not in <= 2.1; 2.6 generates INPLACE_DIVIDE only? 'INPLACE_FLOOR_DIVIDE': ( '//=' ,), 'INPLACE_MODULO': ( '%%=',), 'INPLACE_POWER': ( '**=',),