Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure in Python 3.6.3 #89

Closed
felixonmars opened this issue Nov 17, 2017 · 8 comments · Fixed by #103
Closed

Test failure in Python 3.6.3 #89

felixonmars opened this issue Nov 17, 2017 · 8 comments · Fixed by #103

Comments

@felixonmars
Copy link
Contributor

Looks like a test-only failure, though.

======================================================================
FAIL: test_convert_stdlib (tests.test_rtrip.RtripTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6/tests/test_rtrip.py", line 24, in test_convert_stdlib
    self.assertEqual(result, [])
AssertionError: Lists differ: ['/usr/lib/python3.6/test/test_fstring.py'[34 chars].py'] != []

First list contains 2 additional elements.
First extra element 0:
'/usr/lib/python3.6/test/test_fstring.py'

+ []
- ['/usr/lib/python3.6/test/test_fstring.py',
-  '/usr/lib/python3.6/idlelib/grep.py']
@berkerpeksag
Copy link
Owner

Thanks for the report. I think the cause of both failures is f-strings. We probably miss some cases when we implement it. Also, did you get any output from astor.rtrip? It should normally prints out broken nodes:

astor/astor/rtrip.py

Lines 150 to 151 in 68fbf65

if bad_nodes:
logging.error('\nERROR -- UNKNOWN NODES STRIPPED: %s' % bad_nodes)

@felixonmars
Copy link
Contributor Author

felixonmars commented Nov 17, 2017

Hrm, didn't see that.

root: INFO: Converting /usr/lib/python3.6/idlelib/grep.py
root: WARNING:     calculating dump -- bad
root: INFO: Converting /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     calculating dump -- bad
Files failed to round-trip to AST:
root: WARNING:     /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     /usr/lib/python3.6/idlelib/grep.py

That's all I found besides other INFO entries.

@berkerpeksag
Copy link
Owner

Thanks! I'll check what's wrong with 3.6.3 this weekend.

@radomirbosak
Copy link
Contributor

How do I reproduce this? For me all tests pass

$ python3.6 -m nose -v
test_annassign (tests.test_code_gen.CodegenTestCase) ... ok
[...]
test_codegen_from_root (tests.test_misc.PublicAPITestCase) ... ok
test_convert_stdlib (tests.test_rtrip.RtripTestCase) ... ok

----------------------------------------------------------------------
Ran 34 tests in 18.100s

OK

The same happens when running via tox:

$ tox -e py36
py36 develop-inst-noop: /home/lukoa/repos/astor
py36 installed: -e git+git@github.com:radomirbosak/astor.git@b47718fa095e456c064d3d222f296fccfe36266b#egg=astor,nose==1.3.7
py36 runtests: PYTHONHASHSEED='2587239569'
py36 runtests: commands[0] | nosetests -v --nocapture
test_annassign (tests.test_code_gen.CodegenTestCase) ... ok
[...]
test_codegen_from_root (tests.test_misc.PublicAPITestCase) ... ok
test_convert_stdlib (tests.test_rtrip.RtripTestCase) ... ok

----------------------------------------------------------------------
Ran 34 tests in 16.442s

OK
__________________________________ summary ___________________________________
  py36: commands succeeded
  congratulations :)

@berkerpeksag
Copy link
Owner

@radomirbosak, thank you for trying to reproduce this! Do you have the latest 3.6 release? (If you have 3.6.5 installed with stdlib tests and IDLE installed, I think we can close this as outdated)

Note that almost all distros don't include stdlib tests and don't install IDLE by default. So you may want to check whether test/test_fstring.py and idlelib/grep.py tested by test_convert_stdlib.

@felixonmars
Copy link
Contributor Author

I'm still getting this in 3.6.5 - besides one more missing item:

======================================================================
FAIL: test_convert_stdlib (tests.test_rtrip.RtripTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/python-astor/src/astor-0.6.2/tests/test_rtrip.py", line 24, in test_convert_stdlib
    self.assertEqual(result, [])
AssertionError: Lists differ: ['/usr/lib/python3.6/netrc.py', '/usr/lib/[65 chars].py'] != []

First list contains 3 additional elements.
First extra element 0:
'/usr/lib/python3.6/netrc.py'

+ []
- ['/usr/lib/python3.6/netrc.py',
-  '/usr/lib/python3.6/test/test_fstring.py',
-  '/usr/lib/python3.6/idlelib/grep.py']
Files failed to round-trip to AST:
root: WARNING:     /usr/lib/python3.6/netrc.py
root: WARNING:     /usr/lib/python3.6/test/test_fstring.py
root: WARNING:     /usr/lib/python3.6/idlelib/grep.py

@berkerpeksag
Copy link
Owner

The only change that we made to Lib/netrc.py in the 3.6 branch is python/cpython@5fbe5e1.

I think there is an escaping issue here. Here's a simple test case:

def test_issue_89(self):
    source = """
    x = f'{host}\\n\\t{port}\\n'
    """
    self.assertSrcRoundtripsGtVer(source, (3, 6))

Test result:

======================================================================
FAIL: test_issue_89 (tests.test_code_gen.CodegenTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 414, in test_issue_89
    self.assertSrcRoundtripsGtVer(source, (3, 6))
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 74, in assertSrcRoundtripsGtVer
    self.assertSrcRoundtrips(source)
  File "/home/berker/projects/astor/tests/test_code_gen.py", line 62, in assertSrcRoundtrips
    self.assertEqual(self.to_source(ast.parse(srctxt)).rstrip(), srctxt)
AssertionError: "x = \nf'{host}\\n\\t{port}'" != "x = f'{host}\\n\\t{port}\\n'"

Also, if I drop the trailing \n, the test will pass:

source = """
x = f'{host}\\n\\t{port}'
"""

@radomirbosak would you like to work on this?

@radomirbosak
Copy link
Contributor

@berkerpeksag I can take a look.

After installing the stdlib tests and idle packages I was able to reproduce the issue (on python 3.6.5).

radomirbosak added a commit to radomirbosak/astor that referenced this issue May 4, 2018
If an f-string was ended with a newline character (more precisely, if
the last element of a JoinedStr node was just a newline character), its
round-trip source code representation would have an extra newline on a
wrong place, resulting in invalid syntax.

The bug affects only python>=3.6 (f-strings weren't supported before)

This commit fixes the aforementioned bug.

Fixes berkerpeksag#89.
radomirbosak added a commit to radomirbosak/astor that referenced this issue May 5, 2018
If an f-string was ended with a newline character (more precisely, if
the last element of a JoinedStr node was just a newline character), its
round-trip source code representation would have an extra newline on a
wrong place, resulting in invalid syntax.

The bug affects only python>=3.6 (f-strings weren't supported before)

This commit fixes the aforementioned bug.

Fixes berkerpeksag#89.
radomirbosak added a commit to radomirbosak/astor that referenced this issue May 5, 2018
If an f-string was ended with a newline character (more precisely, if
the last element of a JoinedStr node was just a newline character), its
round-trip source code representation would have an extra newline on a
wrong place, resulting in invalid syntax.

The bug affects only python>=3.6 (f-strings weren't supported before)

This commit fixes the aforementioned bug.

Fixes berkerpeksag#89.
radomirbosak added a commit to radomirbosak/astor that referenced this issue May 7, 2018
If an f-string was ended with a newline character (more precisely, if
the last element of a JoinedStr node was just a newline character), its
round-trip source code representation would have an extra newline on a
wrong place, resulting in invalid syntax.

The bug affects only python>=3.6 (f-strings weren't supported before)

This commit fixes the aforementioned bug.

Fixes berkerpeksag#89.
berkerpeksag pushed a commit that referenced this issue May 7, 2018
If an f-string was ended with a newline character (more precisely, if
the last element of a JoinedStr node was just a newline character), its
round-trip source code representation would have an extra newline on
a wrong place, resulting in invalid syntax.

The bug affects only python>=3.6 (f-strings weren't supported before)

This commit fixes the aforementioned bug.

This commit also replaces pypy3.3-5.2-alpha1 tox/travis with pypy3.5.

The former PyPy version has a bug causing the tests to fail:

https://bitbucket.org/pypy/pypy/issues/2316/osget_terminal_size-is-missing-on-pypy3-hg

Fixes #89.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants