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
f546e703
Commit
f546e703
authored
Dec 02, 2010
by
Alexander Belopolsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue4335: Added a test for inspect.getsourcelines with a module without EOL at EOF.
parent
507e3f8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+29
-8
No files found.
Lib/test/test_inspect.py
View file @
f546e703
...
...
@@ -6,9 +6,11 @@ import inspect
import
linecache
import
datetime
import
collections
import
os
import
shutil
from
os.path
import
normcase
from
test.support
import
run_unittest
from
test.support
import
run_unittest
,
TESTFN
,
DirsOnSysPath
from
test
import
inspect_fodder
as
mod
from
test
import
inspect_fodder2
as
mod2
...
...
@@ -194,12 +196,12 @@ class TestInterpreterStack(IsTestBase):
class
GetSourceBase
(
unittest
.
TestCase
):
# Subclasses must override.
fodder
Fi
le
=
None
fodder
Modu
le
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
unittest
.
TestCase
.
__init__
(
self
,
*
args
,
**
kwargs
)
with
open
(
inspect
.
getsourcefile
(
self
.
fodder
Fi
le
))
as
fp
:
with
open
(
inspect
.
getsourcefile
(
self
.
fodder
Modu
le
))
as
fp
:
self
.
source
=
fp
.
read
()
def
sourcerange
(
self
,
top
,
bottom
):
...
...
@@ -211,7 +213,7 @@ class GetSourceBase(unittest.TestCase):
self
.
sourcerange
(
top
,
bottom
))
class
TestRetrievingSourceCode
(
GetSourceBase
):
fodder
Fi
le
=
mod
fodder
Modu
le
=
mod
def
test_getclasses
(
self
):
classes
=
inspect
.
getmembers
(
mod
,
inspect
.
isclass
)
...
...
@@ -297,7 +299,7 @@ class TestRetrievingSourceCode(GetSourceBase):
inspect
.
getmodule
(
compile
(
'a=10'
,
''
,
'single'
))
class
TestDecorators
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_wrapped_decorator
(
self
):
self
.
assertSourceEqual
(
mod2
.
wrapped
,
14
,
17
)
...
...
@@ -306,7 +308,7 @@ class TestDecorators(GetSourceBase):
self
.
assertSourceEqual
(
mod2
.
gone
,
9
,
10
)
class
TestOneliners
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_oneline_lambda
(
self
):
# Test inspect.getsource with a one-line lambda function.
self
.
assertSourceEqual
(
mod2
.
oll
,
25
,
25
)
...
...
@@ -348,7 +350,7 @@ class TestOneliners(GetSourceBase):
self
.
assertSourceEqual
(
mod2
.
anonymous
,
55
,
55
)
class
TestBuggyCases
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_with_comment
(
self
):
self
.
assertSourceEqual
(
mod2
.
with_comment
,
58
,
59
)
...
...
@@ -388,6 +390,24 @@ class TestBuggyCases(GetSourceBase):
self
.
assertEqual
(
inspect
.
findsource
(
co
),
(
lines
,
0
))
self
.
assertEqual
(
inspect
.
getsource
(
co
),
lines
[
0
])
class
TestNoEOL
(
GetSourceBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
tempdir
=
TESTFN
+
'_dir'
os
.
mkdir
(
self
.
tempdir
)
with
open
(
os
.
path
.
join
(
self
.
tempdir
,
'inspect_fodder3%spy'
%
os
.
extsep
),
'w'
)
as
f
:
f
.
write
(
"class X:
\
n
pass # No EOL"
)
with
DirsOnSysPath
(
self
.
tempdir
):
import
inspect_fodder3
as
mod3
self
.
fodderModule
=
mod3
GetSourceBase
.
__init__
(
self
,
*
args
,
**
kwargs
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tempdir
)
def
test_class
(
self
):
self
.
assertSourceEqual
(
self
.
fodderModule
.
X
,
1
,
2
)
# Helper for testing classify_class_attrs.
def
attrs_wo_objs
(
cls
):
return
[
t
[:
3
]
for
t
in
inspect
.
classify_class_attrs
(
cls
)]
...
...
@@ -945,7 +965,8 @@ def test_main():
TestDecorators
,
TestRetrievingSourceCode
,
TestOneliners
,
TestBuggyCases
,
TestInterpreterStack
,
TestClassesAndFunctions
,
TestPredicates
,
TestGetcallargsFunctions
,
TestGetcallargsMethods
,
TestGetcallargsUnboundMethods
,
TestGetattrStatic
,
TestGetGeneratorState
TestGetcallargsUnboundMethods
,
TestGetattrStatic
,
TestGetGeneratorState
,
TestNoEOL
)
if
__name__
==
"__main__"
:
...
...
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