# HG changeset patch # User Gregory Szorc # Date 1458342912 25200 # Node ID 260ce2eed951abd696715bf9e32a9855cbc26f5a # Parent cdbc253066965347205f7d9b94e334d775495036 tests: perform an ast parse with Python 3 Previously, test-check-py3-compat.t parsed Python files with Python 2 and looked for known patterns that are incompatible with Python 3. Now that we have a mechanism for invoking Python 3 interpreters from tests, we can expand check-py3-compat.py and its corresponding .t test to perform an additional AST parse using Python 3. As the test output shows, we identify a number of new parse failures on Python 3. There are some redundant warnings for missing parentheses for the print function. Given the recent influx of patches around fixing these, the redundancy shouldn't last for too long. diff -r cdbc25306696 -r 260ce2eed951 contrib/check-py3-compat.py --- a/contrib/check-py3-compat.py Fri Mar 18 16:17:56 2016 -0700 +++ b/contrib/check-py3-compat.py Fri Mar 18 16:15:12 2016 -0700 @@ -12,8 +12,8 @@ import ast import sys -def check_compat(f): - """Check Python 3 compatibility for a file.""" +def check_compat_py2(f): + """Check Python 3 compatibility for a file with Python 2""" with open(f, 'rb') as fh: content = fh.read() root = ast.parse(content) @@ -36,8 +36,24 @@ if haveprint and 'print_function' not in futures: print('%s requires print_function' % f) +def check_compat_py3(f): + """Check Python 3 compatibility of a file with Python 3.""" + with open(f, 'rb') as fh: + content = fh.read() + + try: + ast.parse(content) + except SyntaxError as e: + print('%s: invalid syntax: %s' % (f, e)) + return + if __name__ == '__main__': + if sys.version_info[0] == 2: + fn = check_compat_py2 + else: + fn = check_compat_py3 + for f in sys.argv[1:]: - check_compat(f) + fn(f) sys.exit(0) diff -r cdbc25306696 -r 260ce2eed951 tests/test-check-py3-compat.t --- a/tests/test-check-py3-compat.t Fri Mar 18 16:17:56 2016 -0700 +++ b/tests/test-check-py3-compat.t Fri Mar 18 16:15:12 2016 -0700 @@ -118,3 +118,46 @@ tests/test-walkrepo.py requires print_function tests/test-wireproto.py requires print_function tests/tinyproxy.py requires print_function + +#if py3exe + $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py + contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position 18-19: malformed \N character escape (, line 106) + contrib/import-checker.py: invalid syntax: Missing parentheses in call to 'print' (, line 569) + contrib/revsetbenchmarks.py: invalid syntax: invalid syntax (, line 186) + doc/hgmanpage.py: invalid syntax: invalid syntax (, line 286) + hgext/color.py: invalid syntax: invalid syntax (, line 551) + mercurial/archival.py: invalid syntax: invalid syntax (, line 234) + mercurial/bundle2.py: invalid syntax: invalid syntax (, line 977) + mercurial/commands.py: invalid syntax: invalid syntax (, line 3324) + tests/filterpyflakes.py: invalid syntax: Missing parentheses in call to 'print' (, line 61) + tests/generate-working-copy-states.py: invalid syntax: Missing parentheses in call to 'print' (, line 69) + tests/get-with-headers.py: invalid syntax: Missing parentheses in call to 'print' (, line 44) + tests/readlink.py: invalid syntax: invalid syntax (, line 7) + tests/seq.py: invalid syntax: Missing parentheses in call to 'print' (, line 23) + tests/silenttestrunner.py: invalid syntax: Missing parentheses in call to 'print' (, line 11) + tests/test-ancestor.py: invalid syntax: Missing parentheses in call to 'print' (, line 187) + tests/test-batching.py: invalid syntax: invalid syntax (, line 34) + tests/test-bdiff.py: invalid syntax: invalid syntax (, line 10) + tests/test-context.py: invalid syntax: invalid syntax (, line 21) + tests/test-demandimport.py: invalid syntax: invalid syntax (, line 26) + tests/test-duplicateoptions.py: invalid syntax: invalid syntax (, line 34) + tests/test-filecache.py: invalid syntax: Missing parentheses in call to 'print' (, line 23) + tests/test-filelog.py: invalid syntax: Missing parentheses in call to 'print' (, line 33) + tests/test-hg-parseurl.py: invalid syntax: invalid syntax (, line 4) + tests/test-hgweb-auth.py: invalid syntax: invalid syntax (, line 24) + tests/test-hybridencode.py: invalid syntax: invalid syntax (, line 5) + tests/test-lrucachedict.py: invalid syntax: invalid syntax (, line 6) + tests/test-minirst.py: invalid syntax: Missing parentheses in call to 'print' (, line 6) + tests/test-parseindex2.py: invalid syntax: Missing parentheses in call to 'print' (, line 173) + tests/test-propertycache.py: invalid syntax: Missing parentheses in call to 'print' (, line 50) + tests/test-revlog-ancestry.py: invalid syntax: Missing parentheses in call to 'print' (, line 49) + tests/test-status-inprocess.py: invalid syntax: Missing parentheses in call to 'print' (, line 8) + tests/test-trusted.py: invalid syntax: invalid syntax (, line 60) + tests/test-ui-color.py: invalid syntax: invalid syntax (, line 11) + tests/test-ui-config.py: invalid syntax: invalid syntax (, line 32) + tests/test-ui-verbosity.py: invalid syntax: Missing parentheses in call to 'print' (, line 9) + tests/test-walkrepo.py: invalid syntax: invalid syntax (, line 37) + tests/test-wireproto.py: invalid syntax: invalid syntax (, line 55) + tests/tinyproxy.py: invalid syntax: Missing parentheses in call to 'print' (, line 53) + +#endif