Show More
@@ -5,6 +5,7 b' Should only trigger on python 3.5+ or will have syntax errors.' | |||||
5 | """ |
|
5 | """ | |
6 |
|
6 | |||
7 | import sys |
|
7 | import sys | |
|
8 | from itertools import chain, repeat | |||
8 | import nose.tools as nt |
|
9 | import nose.tools as nt | |
9 | from textwrap import dedent, indent |
|
10 | from textwrap import dedent, indent | |
10 | from unittest import TestCase |
|
11 | from unittest import TestCase | |
@@ -155,18 +156,22 b' if sys.version_info > (3, 5):' | |||||
155 | # detection isn't *too* aggressive, and works inside a function |
|
156 | # detection isn't *too* aggressive, and works inside a function | |
156 | func_contexts = [] |
|
157 | func_contexts = [] | |
157 |
|
158 | |||
158 | func_contexts.append(('func', dedent(""" |
|
159 | func_contexts.append(('func', False, dedent(""" | |
159 | def f():"""))) |
|
160 | def f():"""))) | |
160 |
|
161 | |||
161 | func_contexts.append(('method', dedent(""" |
|
162 | func_contexts.append(('method', False, dedent(""" | |
162 | class MyClass: |
|
163 | class MyClass: | |
163 | def __init__(self): |
|
164 | def __init__(self): | |
164 | """))) |
|
165 | """))) | |
165 |
|
166 | |||
166 | func_contexts.append(('async-func', dedent(""" |
|
167 | func_contexts.append(('async-func', True, dedent(""" | |
167 | async def f():"""))) |
|
168 | async def f():"""))) | |
168 |
|
169 | |||
169 |
func_contexts.append((' |
|
170 | func_contexts.append(('async-method', True, dedent(""" | |
|
171 | class MyClass: | |||
|
172 | async def f(self):"""))) | |||
|
173 | ||||
|
174 | func_contexts.append(('closure', False, dedent(""" | |||
170 | def f(): |
|
175 | def f(): | |
171 | def g(): |
|
176 | def g(): | |
172 | """))) |
|
177 | """))) | |
@@ -184,28 +189,41 b' if sys.version_info > (3, 5):' | |||||
184 | return context + '\n' + indented_case |
|
189 | return context + '\n' + indented_case | |
185 |
|
190 | |||
186 | # Gather and run the tests |
|
191 | # Gather and run the tests | |
187 | vals = ('return', 'yield') |
|
|||
188 |
|
192 | |||
189 | success_tests = self._get_top_level_cases() |
|
193 | # yield is allowed in async functions, starting in Python 3.6, | |
190 | failure_tests = self._get_ry_syntax_errors() |
|
194 | # and yield from is not allowed in any version | |
|
195 | vals = ('return', 'yield', 'yield from (_ for _ in range(3))') | |||
|
196 | async_safe = (True, | |||
|
197 | sys.version_info >= (3, 6), | |||
|
198 | False) | |||
|
199 | vals = tuple(zip(vals, async_safe)) | |||
191 |
|
200 | |||
192 | for context_name, context in func_contexts: |
|
201 | success_tests = zip(self._get_top_level_cases(), repeat(False)) | |
193 | # These tests should now successfully run |
|
202 | failure_tests = zip(self._get_ry_syntax_errors(), repeat(True)) | |
194 | for test_name, test_case in success_tests: |
|
|||
195 | nested_case = nest_case(context, test_case) |
|
|||
196 |
|
203 | |||
197 | for val in vals: |
|
204 | tests = chain(success_tests, failure_tests) | |
198 | with self.subTest((test_name, context_name, val)): |
|
|||
199 | iprc(nested_case.format(val=val)) |
|
|||
200 |
|
205 | |||
201 | # These tests should still raise a SyntaxError |
|
206 | for context_name, async_func, context in func_contexts: | |
202 |
for test_name, test_case in |
|
207 | for (test_name, test_case), should_fail in tests: | |
203 | nested_case = nest_case(context, test_case) |
|
208 | nested_case = nest_case(context, test_case) | |
204 |
|
209 | |||
205 | for val in vals: |
|
210 | for val, async_safe in vals: | |
206 | with self.subTest((test_name, context_name, val)): |
|
211 | val_should_fail = (should_fail or | |
207 | with self.assertRaises(SyntaxError): |
|
212 | (async_func and not async_safe)) | |
208 | iprc(nested_case.format(val=val)) |
|
213 | ||
|
214 | test_id = (context_name, test_name, val) | |||
|
215 | cell = nested_case.format(val=val) | |||
|
216 | ||||
|
217 | with self.subTest(test_id): | |||
|
218 | if val_should_fail: | |||
|
219 | msg = ("SyntaxError not raised for %s" % | |||
|
220 | str(test_id)) | |||
|
221 | with self.assertRaises(SyntaxError, msg=msg): | |||
|
222 | iprc(cell) | |||
|
223 | ||||
|
224 | print(cell) | |||
|
225 | else: | |||
|
226 | iprc(cell) | |||
209 |
|
227 | |||
210 |
|
228 | |||
211 | def test_execute(self): |
|
229 | def test_execute(self): |
General Comments 0
You need to be logged in to leave comments.
Login now