Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
bpo-29598 Add couple of unit tests for pdb module#218
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# A test suite for pdb; not very comprehensive at the moment. | ||
import dis | ||
import doctest | ||
import inspect | ||
import os | ||
import pdb | ||
import sys | ||
@@ -1110,6 +1112,44 @@ def test_readrc_kwarg(self): | ||
if save_home is not None: | ||
os.environ['HOME'] = save_home | ||
def test_find_function_with_invalid_filename(self): | ||
self.assertIsNone(pdb.find_function('foo', 'invalid filename')) | ||
def test_getsourcelines(self): | ||
def foo(): | ||
pass # pragma: no cover | ||
lines, lineno = inspect.findsource(foo) | ||
expected_lines = inspect.getblock(lines[lineno:]) | ||
expected_lineno = lineno + 1 | ||
actual_lines, actual_lineno = pdb.getsourcelines(foo) | ||
self.assertEqual(actual_lines, expected_lines) | ||
self.assertEqual(actual_lineno, expected_lineno) | ||
def test_getsourcelines_with_module_frame_obj(self): | ||
for frame, *unused in inspect.getouterframes(inspect.currentframe()): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't like test relying on outer frame. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. But documentation says that whitebox tests are preferred There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. "whitebox test" is relying on implementation oftest target, nottest runner. What ismodule_frame here? Isn't it relying on test runner? So I prefer creating module framein this test, not capturing from caller of this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. BTW, is there any difference between module frame and other frames from pdb's point of view? Author
| ||
if frame.f_globals is frame.f_locals: | ||
module_frame = frame | ||
break | ||
expected_lines = inspect.findsource(module_frame)[0] | ||
lines, lineno = pdb.getsourcelines(module_frame) | ||
self.assertEqual(lines, expected_lines) | ||
self.assertEqual(lineno, 1) | ||
def test_getsourcelines_with_module_obj(self): | ||
module = inspect.getmodule(inspect.currentframe()) | ||
expected_lines = inspect.findsource(module)[0] | ||
lines, lineno = pdb.getsourcelines(module) | ||
self.assertEqual(lines, expected_lines) | ||
self.assertEqual(lineno, 1) | ||
def test_lasti2lineno(self): | ||
code_obj = inspect.currentframe().f_code | ||
max_offset, max_lineno = max(dis.findlinestarts(code_obj)) | ||
min_offset, min_lineno = min(dis.findlinestarts(code_obj)) | ||
self.assertEqual(pdb.lasti2lineno(code_obj, max_offset), max_lineno) | ||
self.assertEqual(pdb.lasti2lineno(code_obj, max_offset+1), max_lineno) | ||
self.assertEqual(pdb.lasti2lineno(code_obj, min_offset-1), 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm afraid this test is relying implementation detail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. What implementation detail ? As a side note, offsets increase monotonically so min_offset is the first offset yielded by findlinestarts() and max_offset is the last one (no need to invoke min() or max()). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I didn't research deeply, I just worried. So if PyPy passes this, it's OK. I think attributes of Python's code object is implementation detail, even though PyPy follows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I have started a discussion on python-dev about attributes of Python code objects being implementation detail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @methane There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @xdegaye I didn't say "I want to do ...". I was asked to review, and leave comment what I feel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Please ignore me when my comment doesn't make sense for you. | ||
def tearDown(self): | ||
support.unlink(support.TESTFN) | ||