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