bpo-32416: Refactor tests for the f_lineno setter and add new tests.#4991
bpo-32416: Refactor tests for the f_lineno setter and add new tests.#4991serhiy-storchaka merged 5 commits intopython:masterpython/cpython:masterfrom
Conversation
pitrou
left a comment
There was a problem hiding this comment.
Very nice. A couple small comments are inline.
| import gc | ||
| from functools import wraps | ||
|
|
||
| class tracecontext: |
Lib/test/test_sys_settrace.py
Outdated
| raise | ||
| else: | ||
| # Something's wrong - the expected exception wasn't raised. | ||
| raise RuntimeError("Trace-function-less jump failed to fail") |
There was a problem hiding this comment.
I didn't touched this function. Agreed, AssertionError looks more appropriate here.
| sys.settrace(None) | ||
| self.compare_jump_output(expected, output) | ||
|
|
||
| def jump_test(jumpFrom, jumpTo, expected, error=None): |
There was a problem hiding this comment.
Could you add a docstring perhaps?
| def decorator(func): | ||
| @wraps(func) | ||
| def test(self): | ||
| self.run_test(func, jumpFrom+1, jumpTo+1, expected, error) |
There was a problem hiding this comment.
To compensate a decorator line.
| pass | ||
| jump_across_with.jump = (1, 3) | ||
| jump_across_with.output = [] | ||
| @jump_test(5, 7, [4], (ValueError, 'into')) |
There was a problem hiding this comment.
Why is this forbidden even though test_jump_between_except_blocks is ok?
There was a problem hiding this comment.
Because except with a variable creates an implicit finally block.
Lib/test/test_sys_settrace.py
Outdated
| else: | ||
| # Something's wrong - the expected exception wasn't raised. | ||
| raise RuntimeError("Trace-function-less jump failed to fail") | ||
| @jump_test(3, 5, [2, 5], (ValueError, 'finally')) |
There was a problem hiding this comment.
If jumping is forbidden, then I'm curious why output.append(3) is not executed?
Edit: oh, I see... the jump raises ValueError so still jumps to the finally block. Perhaps add a comment?
| output.append(5) | ||
|
|
||
| @jump_test(3, 5, [1, 2, -2], (ValueError, 'into')) | ||
| def test_jump_across_with_2(output): |
There was a problem hiding this comment.
It's really the jumping into a with block that's forbidden, right? Jumping out of it seems ok...
There was a problem hiding this comment.
Right. There was test_jump_across_with which looked strangely so I have added test_jump_across_with_2 just for the case of an error in the former.
Actually test_jump_across_with may be working as intended. Once it caught a bug in my code when most of other tests were passed.
test_jump_across_with_2 itself can catch other bug. Both source and destination have the same level of nesting. Just they are nested in different blocks.
Thus I'll keep both tests.
Lib/test/test_sys_settrace.py
Outdated
| self.fail( "Outputs don't match:\n" + | ||
| "Expected: " + repr(expected) + "\n" + | ||
| "Received: " + repr(received)) | ||
| def test_no_jump_to_non_integers(self): |
There was a problem hiding this comment.
Those two tests should go after the @jump_test functions, no?
There was a problem hiding this comment.
jump_test doesn't support non-integer arguments.
There was a problem hiding this comment.
Yes, I mean this test should go after the tests decorated with @jump_test.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 2.7, 3.6. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
…ests. (pythonGH-4991). (cherry picked from commit 53f9135)
|
GH-5016 is a backport of this pull request to the 3.6 branch. |
|
GH-5017 is a backport of this pull request to the 2.7 branch. |
…ests. (pythonGH-4991). (cherry picked from commit 53f9135)
https://bugs.python.org/issue32416