berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
803 stars 102 forks source link

Several tests failed under Python 3.7 #131

Closed rpisarev closed 5 years ago

rpisarev commented 5 years ago

I wanted to build RPM package but I found some tests are failed on 3.7 (Fedora)

check_astunparse (unittest.loader._FailedTest) ... ERROR
test_fast_compare (tests.test_misc.FastCompareTestCase) ... ok
test_get_mat_mult (tests.test_misc.GetSymbolTestCase) ... ok
test_aliases (tests.test_misc.PublicAPITestCase) ... ok
test_codegen_as_submodule (tests.test_misc.PublicAPITestCase) ... FAIL
test_codegen_from_root (tests.test_misc.PublicAPITestCase) ... ok
test_convert_stdlib (tests.test_rtrip.RtripTestCase) ... WARNING:root:    calculating dump -- bad
WARNING:root:    calculating dump -- bad
WARNING:root:    calculating dump -- bad
WARNING:root:    calculating dump -- bad
WARNING:root:    calculating dump -- bad
WARNING:root:
Files failed to round-trip to AST:
WARNING:root:    /usr/lib64/python3.7/dataclasses.py
WARNING:root:    /usr/lib64/python3.7/netrc.py
WARNING:root:    /usr/lib64/python3.7/warnings.py
WARNING:root:    /usr/lib64/python3.7/asyncio/base_events.py
WARNING:root:    /usr/lib64/python3.7/test/support/testresult.py
FAIL
check_expressions (unittest.loader._FailedTest) ... ERROR

======================================================================
ERROR: check_astunparse (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: check_astunparse
Traceback (most recent call last):
  File "/usr/lib64/python3.7/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "/builddir/build/BUILD/astor-0.7.1/tests/check_astunparse.py", line 8, in <module>
    import test_code_gen
ModuleNotFoundError: No module named 'test_code_gen'

======================================================================
ERROR: check_expressions (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: check_expressions
Traceback (most recent call last):
  File "/builddir/build/BUILD/astor-0.7.1/tests/check_expressions.py", line 44, in <module>
    mymod = importlib.import_module(mymodname)
  File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'all_expr_3_7'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.7/unittest/loader.py", line 154, in loadTestsFromName
    module = __import__(module_name)
  File "/builddir/build/BUILD/astor-0.7.1/tests/check_expressions.py", line 47, in <module>
    import build_expressions
ModuleNotFoundError: No module named 'build_expressions'

======================================================================
FAIL: test_codegen_as_submodule (tests.test_misc.PublicAPITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/astor-0.7.1/tests/test_misc.py", line 40, in test_codegen_as_submodule
    import astor.codegen
AssertionError: DeprecationWarning not triggered

======================================================================
FAIL: test_convert_stdlib (tests.test_rtrip.RtripTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILD/astor-0.7.1/tests/test_rtrip.py", line 24, in test_convert_stdlib
    self.assertEqual(result, [])
AssertionError: Lists differ: ['/usr/lib64/python3.7/dataclasses.py', '/[159 chars].py'] != []

First list contains 5 additional elements.
First extra element 0:
'/usr/lib64/python3.7/dataclasses.py'

+ []
- ['/usr/lib64/python3.7/dataclasses.py',
-  '/usr/lib64/python3.7/netrc.py',
-  '/usr/lib64/python3.7/warnings.py',
-  '/usr/lib64/python3.7/asyncio/base_events.py',
-  '/usr/lib64/python3.7/test/support/testresult.py']

----------------------------------------------------------------------
Ran 44 tests in 14.885s

FAILED (failures=2, errors=2)
Test failed: <unittest.runner.TextTestResult run=44 errors=2 failures=2>
Expression list does not exist -- building
error: Test failed: <unittest.runner.TextTestResult run=44 errors=2 failures=2>
error: Bad exit status from /var/tmp/rpm-tmp.ZeKR6g (%check)

See more on builder-live.log in https://copr-be.cloud.fedoraproject.org/results/rpisarev/tensorflow/fedora-30-x86_64/00869299-python-astor/

berkerpeksag commented 5 years ago

Thank you for your report! check_ files shouldn't run by the test suite. Could you please share the command you've used to run the test suite?

We've recently fixed some bugs in our code generation code, so test_convert_stdlib might be pass on current master. Could you please run the test suite with current master?

test_codegen_as_submodule can be explained by your Python version and which method did you choose to run the test suite. Of course, we should make that test more robust and I'm open to any suggestions and PRs :)

rpisarev commented 5 years ago

Yes, a command I've used to run tests is /usr/bin/python3 setup.py test (is it correct?). I've already checked the current master (just now). The result is the same.

berkerpeksag commented 5 years ago

This is the command we've been using to run the test suite:

https://github.com/berkerpeksag/astor/blob/ea0dec38526b6f984e40da7e79d7492b4fa0af53/tox.ini#L7

I never used setup.py test myself, so I doubt it will work properly (we probably need to set 'nose.collector' as the test runner in setup.py)