Skip to content

Commit

Permalink
Module docstrings in 3.7 are not part of Module node anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok committed Jun 4, 2018
1 parent d609b63 commit bdec682
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/3530.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix if in tests to support 3.7.0b5, where a docstring handling in AST got reverted.
27 changes: 22 additions & 5 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,18 @@ class TestAssertionRewrite(object):
def test_place_initial_imports(self):
s = """'Doc string'\nother = stuff"""
m = rewrite(s)
# Module docstrings in 3.7 are part of Module node, it's not in the body
# Module docstrings in 3.8 are part of Module node, it's not in the body
# so we remove it so the following body items have the same indexes on
# all Python versions
if sys.version_info < (3, 7):
# This was briefly in 3.7 as well but got reverted in beta 5
# TODO:
# We have a complicated sys.version_info if in here to ease testing on
# various Python 3.7 versions, but we should remove the 3.7 check after
# 3.7 is released as stable
if (
sys.version_info < (3, 8)
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
):
assert isinstance(m.body[0], ast.Expr)
assert isinstance(m.body[0].value, ast.Str)
del m.body[0]
Expand All @@ -92,7 +100,10 @@ def test_place_initial_imports(self):
assert isinstance(m.body[3], ast.Expr)
s = """'doc string'\nfrom __future__ import with_statement"""
m = rewrite(s)
if sys.version_info < (3, 7):
if (
sys.version_info < (3, 8)
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
):
assert isinstance(m.body[0], ast.Expr)
assert isinstance(m.body[0].value, ast.Str)
del m.body[0]
Expand All @@ -103,7 +114,10 @@ def test_place_initial_imports(self):
assert imp.col_offset == 0
s = """'doc string'\nfrom __future__ import with_statement\nother"""
m = rewrite(s)
if sys.version_info < (3, 7):
if (
sys.version_info < (3, 8)
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
):
assert isinstance(m.body[0], ast.Expr)
assert isinstance(m.body[0].value, ast.Str)
del m.body[0]
Expand All @@ -124,7 +138,10 @@ def test_place_initial_imports(self):
def test_dont_rewrite(self):
s = """'PYTEST_DONT_REWRITE'\nassert 14"""
m = rewrite(s)
if sys.version_info < (3, 7):
if (
sys.version_info < (3, 8)
or (3, 7) <= sys.version_info <= (3, 7, 0, "beta", 4)
):
assert len(m.body) == 2
assert isinstance(m.body[0], ast.Expr)
assert isinstance(m.body[0].value, ast.Str)
Expand Down

0 comments on commit bdec682

Please sign in to comment.