@@ -68,38 +68,16 @@ def getmsg(f, extra_ns=None, must_pass=False):
68
68
pytest .fail ("function didn't raise at all" )
69
69
70
70
71
- def adjust_body_for_new_docstring_in_module_node (m ):
72
- """Module docstrings in 3.8 are part of Module node.
73
- This was briefly in 3.7 as well but got reverted in beta 5.
74
-
75
- It's not in the body so we remove it so the following body items have
76
- the same indexes on all Python versions:
77
-
78
- TODO:
79
-
80
- We have a complicated sys.version_info if in here to ease testing on
81
- various Python 3.7 versions, but we should remove the 3.7 check after
82
- 3.7 is released as stable to make this check more straightforward.
83
- """
84
- if sys .version_info < (3 , 8 ) and not (
85
- (3 , 7 ) <= sys .version_info <= (3 , 7 , 0 , "beta" , 4 )
86
- ):
87
- assert len (m .body ) > 1
88
- assert isinstance (m .body [0 ], ast .Expr )
89
- assert isinstance (m .body [0 ].value , ast .Str )
90
- del m .body [0 ]
91
-
92
-
93
71
class TestAssertionRewrite (object ):
94
72
def test_place_initial_imports (self ):
95
73
s = """'Doc string'\n other = stuff"""
96
74
m = rewrite (s )
97
- adjust_body_for_new_docstring_in_module_node ( m )
98
- for imp in m .body [0 : 2 ]:
75
+ assert isinstance ( m . body [ 0 ], ast . Expr )
76
+ for imp in m .body [1 : 3 ]:
99
77
assert isinstance (imp , ast .Import )
100
78
assert imp .lineno == 2
101
79
assert imp .col_offset == 0
102
- assert isinstance (m .body [2 ], ast .Assign )
80
+ assert isinstance (m .body [3 ], ast .Assign )
103
81
s = """from __future__ import division\n other_stuff"""
104
82
m = rewrite (s )
105
83
assert isinstance (m .body [0 ], ast .ImportFrom )
@@ -110,24 +88,24 @@ def test_place_initial_imports(self):
110
88
assert isinstance (m .body [3 ], ast .Expr )
111
89
s = """'doc string'\n from __future__ import division"""
112
90
m = rewrite (s )
113
- adjust_body_for_new_docstring_in_module_node ( m )
114
- assert isinstance (m .body [0 ], ast .ImportFrom )
115
- for imp in m .body [1 : 3 ]:
91
+ assert isinstance ( m . body [ 0 ], ast . Expr )
92
+ assert isinstance (m .body [1 ], ast .ImportFrom )
93
+ for imp in m .body [2 : 4 ]:
116
94
assert isinstance (imp , ast .Import )
117
95
assert imp .lineno == 2
118
96
assert imp .col_offset == 0
119
97
s = """'doc string'\n from __future__ import division\n other"""
120
98
m = rewrite (s )
121
- adjust_body_for_new_docstring_in_module_node ( m )
122
- assert isinstance (m .body [0 ], ast .ImportFrom )
123
- for imp in m .body [1 : 3 ]:
99
+ assert isinstance ( m . body [ 0 ], ast . Expr )
100
+ assert isinstance (m .body [1 ], ast .ImportFrom )
101
+ for imp in m .body [2 : 4 ]:
124
102
assert isinstance (imp , ast .Import )
125
103
assert imp .lineno == 3
126
104
assert imp .col_offset == 0
127
- assert isinstance (m .body [3 ], ast .Expr )
105
+ assert isinstance (m .body [4 ], ast .Expr )
128
106
s = """from . import relative\n other_stuff"""
129
107
m = rewrite (s )
130
- for imp in m .body [0 :2 ]:
108
+ for imp in m .body [:2 ]:
131
109
assert isinstance (imp , ast .Import )
132
110
assert imp .lineno == 1
133
111
assert imp .col_offset == 0
@@ -136,9 +114,8 @@ def test_place_initial_imports(self):
136
114
def test_dont_rewrite (self ):
137
115
s = """'PYTEST_DONT_REWRITE'\n assert 14"""
138
116
m = rewrite (s )
139
- adjust_body_for_new_docstring_in_module_node (m )
140
- assert len (m .body ) == 1
141
- assert m .body [0 ].msg is None
117
+ assert len (m .body ) == 2
118
+ assert m .body [1 ].msg is None
142
119
143
120
def test_dont_rewrite_plugin (self , testdir ):
144
121
contents = {
0 commit comments