Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6e22055e
Commit
6e22055e
authored
Oct 13, 2013
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pdb: modernize find_function() and add tests for it.
Closes #18714.
parent
7ff45205
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
12 deletions
+37
-12
Lib/pdb.py
Lib/pdb.py
+5
-12
Lib/test/test_pdb.py
Lib/test/test_pdb.py
+30
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/pdb.py
View file @
6e22055e
...
...
@@ -95,18 +95,11 @@ def find_function(funcname, filename):
except
OSError
:
return
None
# consumer of this info expects the first line to be 1
lineno
=
1
answer
=
None
while
True
:
line
=
fp
.
readline
()
if
line
==
''
:
break
if
cre
.
match
(
line
):
answer
=
funcname
,
filename
,
lineno
break
lineno
+=
1
fp
.
close
()
return
answer
with
fp
:
for
lineno
,
line
in
enumerate
(
fp
,
start
=
1
):
if
cre
.
match
(
line
):
return
funcname
,
filename
,
lineno
return
None
def
getsourcelines
(
obj
):
lines
,
lineno
=
inspect
.
findsource
(
obj
)
...
...
Lib/test/test_pdb.py
View file @
6e22055e
...
...
@@ -620,6 +620,36 @@ class PdbTestCase(unittest.TestCase):
stderr
=
stderr
and
bytes
.
decode
(
stderr
)
return
stdout
,
stderr
def
_assert_find_function
(
self
,
file_content
,
func_name
,
expected
):
file_content
=
textwrap
.
dedent
(
file_content
)
with
open
(
support
.
TESTFN
,
'w'
)
as
f
:
f
.
write
(
file_content
)
expected
=
None
if
not
expected
else
(
expected
[
0
],
support
.
TESTFN
,
expected
[
1
])
self
.
assertEqual
(
expected
,
pdb
.
find_function
(
func_name
,
support
.
TESTFN
))
def
test_find_function_empty_file
(
self
):
self
.
_assert_find_function
(
''
,
'foo'
,
None
)
def
test_find_function_found
(
self
):
self
.
_assert_find_function
(
"""
\
def foo():
pass
def bar():
pass
def quux():
pass
"""
,
'bar'
,
(
'bar'
,
4
),
)
def
test_issue7964
(
self
):
# open the file as binary so we can force \r\n newline
with
open
(
support
.
TESTFN
,
'wb'
)
as
f
:
...
...
Misc/NEWS
View file @
6e22055e
...
...
@@ -114,6 +114,8 @@ Tests
- Issue #18919: Unified and extended tests for audio modules: aifc, sunau and
wave.
- Issue #18714: Added tests for ``pdb.find_function()``.
Documentation
-------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment