| 1 |
""" |
| 2 |
Some of the files in this repo are used also by PyPy tests, which run on |
| 3 |
python2.7. |
| 4 |
|
| 5 |
This script tries to import all of them: it does not check any behavior, just |
| 6 |
that they are importable and thus are not using any py3-specific syntax. |
| 7 |
|
| 8 |
This script assumes that pathlib and pytest are installed (because the modules |
| 9 |
try to import them). |
| 10 |
""" |
| 11 |
|
| 12 |
from __future__ import print_function |
| 13 |
import sys |
| 14 |
import traceback |
| 15 |
import py |
| 16 |
|
| 17 |
ROOT = py.path.local(__file__).join('..', '..') |
| 18 |
TEST_DIRS = [ROOT / 'test', ROOT / 'test' / 'debug'] |
| 19 |
|
| 20 |
|
| 21 |
PY3_ONLY = ['test_support.py', |
| 22 |
'test_handles_invalid.py', |
| 23 |
'test_handles_leak.py', |
| 24 |
'test_builder_invalid.py'] |
| 25 |
|
| 26 |
def try_import(name): |
| 27 |
try: |
| 28 |
if isinstance(name, py.path.local): |
| 29 |
print('Trying to import %s... ' % ROOT.bestrelpath(name), end='') |
| 30 |
name.pyimport() |
| 31 |
else: |
| 32 |
print('Trying to import %s... ' % name, end='') |
| 33 |
__import__(name) |
| 34 |
except: |
| 35 |
print('ERROR!') |
| 36 |
print() |
| 37 |
traceback.print_exc(file=sys.stdout) |
| 38 |
print() |
| 39 |
return False |
| 40 |
else: |
| 41 |
print('OK') |
| 42 |
return True |
| 43 |
|
| 44 |
def try_import_hpy_devel(): |
| 45 |
""" |
| 46 |
To import hpy.devel we need to create an empty hpy/__init__.py, because |
| 47 |
python2.7 does not support namespace packages. |
| 48 |
|
| 49 |
Return the number of failed imports. |
| 50 |
""" |
| 51 |
failed = 0 |
| 52 |
init_py = ROOT.join('hpy', '__init__.py') |
| 53 |
assert init_py.check(exists=False) |
| 54 |
try: |
| 55 |
init_py.write('') |
| 56 |
if not try_import('hpy.devel'): |
| 57 |
failed += 1 |
| 58 |
finally: |
| 59 |
init_py.remove() |
| 60 |
return failed |
| 61 |
|
| 62 |
def try_import_tests(dirs): |
| 63 |
failed = 0 |
| 64 |
for d in dirs: |
| 65 |
for t in d.listdir('test_*.py'): |
| 66 |
if t.basename in PY3_ONLY: |
| 67 |
continue |
| 68 |
if not try_import(t): |
| 69 |
failed += 1 |
| 70 |
return failed |
| 71 |
|
| 72 |
|
| 73 |
def main(): |
| 74 |
if sys.version_info[:2] != (2, 7): |
| 75 |
print('ERROR: this script should be run on top of python 2.7') |
| 76 |
sys.exit(1) |
| 77 |
|
| 78 |
sys.path.insert(0, str(ROOT)) |
| 79 |
failed = 0 |
| 80 |
failed += try_import_hpy_devel() |
| 81 |
failed += try_import_tests(TEST_DIRS) |
| 82 |
print() |
| 83 |
if failed == 0: |
| 84 |
print('Everything ok!') |
| 85 |
else: |
| 86 |
print('%d failed imports :(' % failed) |
| 87 |
sys.exit(1) |
| 88 |
|
| 89 |
if __name__ == '__main__': |
| 90 |
main() |