-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-32416: Refactor tests for the f_lineno setter and add new tests. #4991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. A couple small comments are inline.
@@ -5,6 +5,18 @@ | |||
import sys | |||
import difflib | |||
import gc | |||
from functools import wraps | |||
|
|||
class tracecontext: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a docstring here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertionError
perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a docstring perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Lib/test/test_sys_settrace.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why +1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To compensate a decorator line.
Lib/test/test_sys_settrace.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this forbidden even though test_jump_between_except_blocks
is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Lib/test/test_sys_settrace.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two tests should go after the @jump_test
functions, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jump_test
doesn't support non-integer arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean this test should go after the tests decorated with @jump_test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @serhiy-storchaka !
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