Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f546e703
Kaydet (Commit)
f546e703
authored
Ara 02, 2010
tarafından
Alexander Belopolsky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue4335: Added a test for inspect.getsourcelines with a module without EOL at EOF.
üst
507e3f8d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
test_inspect.py
Lib/test/test_inspect.py
+29
-8
No files found.
Lib/test/test_inspect.py
Dosyayı görüntüle @
f546e703
...
@@ -6,9 +6,11 @@ import inspect
...
@@ -6,9 +6,11 @@ import inspect
import
linecache
import
linecache
import
datetime
import
datetime
import
collections
import
collections
import
os
import
shutil
from
os.path
import
normcase
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_fodder
as
mod
from
test
import
inspect_fodder2
as
mod2
from
test
import
inspect_fodder2
as
mod2
...
@@ -194,12 +196,12 @@ class TestInterpreterStack(IsTestBase):
...
@@ -194,12 +196,12 @@ class TestInterpreterStack(IsTestBase):
class
GetSourceBase
(
unittest
.
TestCase
):
class
GetSourceBase
(
unittest
.
TestCase
):
# Subclasses must override.
# Subclasses must override.
fodder
Fi
le
=
None
fodder
Modu
le
=
None
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
unittest
.
TestCase
.
__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
()
self
.
source
=
fp
.
read
()
def
sourcerange
(
self
,
top
,
bottom
):
def
sourcerange
(
self
,
top
,
bottom
):
...
@@ -211,7 +213,7 @@ class GetSourceBase(unittest.TestCase):
...
@@ -211,7 +213,7 @@ class GetSourceBase(unittest.TestCase):
self
.
sourcerange
(
top
,
bottom
))
self
.
sourcerange
(
top
,
bottom
))
class
TestRetrievingSourceCode
(
GetSourceBase
):
class
TestRetrievingSourceCode
(
GetSourceBase
):
fodder
Fi
le
=
mod
fodder
Modu
le
=
mod
def
test_getclasses
(
self
):
def
test_getclasses
(
self
):
classes
=
inspect
.
getmembers
(
mod
,
inspect
.
isclass
)
classes
=
inspect
.
getmembers
(
mod
,
inspect
.
isclass
)
...
@@ -297,7 +299,7 @@ class TestRetrievingSourceCode(GetSourceBase):
...
@@ -297,7 +299,7 @@ class TestRetrievingSourceCode(GetSourceBase):
inspect
.
getmodule
(
compile
(
'a=10'
,
''
,
'single'
))
inspect
.
getmodule
(
compile
(
'a=10'
,
''
,
'single'
))
class
TestDecorators
(
GetSourceBase
):
class
TestDecorators
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_wrapped_decorator
(
self
):
def
test_wrapped_decorator
(
self
):
self
.
assertSourceEqual
(
mod2
.
wrapped
,
14
,
17
)
self
.
assertSourceEqual
(
mod2
.
wrapped
,
14
,
17
)
...
@@ -306,7 +308,7 @@ class TestDecorators(GetSourceBase):
...
@@ -306,7 +308,7 @@ class TestDecorators(GetSourceBase):
self
.
assertSourceEqual
(
mod2
.
gone
,
9
,
10
)
self
.
assertSourceEqual
(
mod2
.
gone
,
9
,
10
)
class
TestOneliners
(
GetSourceBase
):
class
TestOneliners
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_oneline_lambda
(
self
):
def
test_oneline_lambda
(
self
):
# Test inspect.getsource with a one-line lambda function.
# Test inspect.getsource with a one-line lambda function.
self
.
assertSourceEqual
(
mod2
.
oll
,
25
,
25
)
self
.
assertSourceEqual
(
mod2
.
oll
,
25
,
25
)
...
@@ -348,7 +350,7 @@ class TestOneliners(GetSourceBase):
...
@@ -348,7 +350,7 @@ class TestOneliners(GetSourceBase):
self
.
assertSourceEqual
(
mod2
.
anonymous
,
55
,
55
)
self
.
assertSourceEqual
(
mod2
.
anonymous
,
55
,
55
)
class
TestBuggyCases
(
GetSourceBase
):
class
TestBuggyCases
(
GetSourceBase
):
fodder
Fi
le
=
mod2
fodder
Modu
le
=
mod2
def
test_with_comment
(
self
):
def
test_with_comment
(
self
):
self
.
assertSourceEqual
(
mod2
.
with_comment
,
58
,
59
)
self
.
assertSourceEqual
(
mod2
.
with_comment
,
58
,
59
)
...
@@ -388,6 +390,24 @@ class TestBuggyCases(GetSourceBase):
...
@@ -388,6 +390,24 @@ class TestBuggyCases(GetSourceBase):
self
.
assertEqual
(
inspect
.
findsource
(
co
),
(
lines
,
0
))
self
.
assertEqual
(
inspect
.
findsource
(
co
),
(
lines
,
0
))
self
.
assertEqual
(
inspect
.
getsource
(
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.
# Helper for testing classify_class_attrs.
def
attrs_wo_objs
(
cls
):
def
attrs_wo_objs
(
cls
):
return
[
t
[:
3
]
for
t
in
inspect
.
classify_class_attrs
(
cls
)]
return
[
t
[:
3
]
for
t
in
inspect
.
classify_class_attrs
(
cls
)]
...
@@ -945,7 +965,8 @@ def test_main():
...
@@ -945,7 +965,8 @@ def test_main():
TestDecorators
,
TestRetrievingSourceCode
,
TestOneliners
,
TestBuggyCases
,
TestDecorators
,
TestRetrievingSourceCode
,
TestOneliners
,
TestBuggyCases
,
TestInterpreterStack
,
TestClassesAndFunctions
,
TestPredicates
,
TestInterpreterStack
,
TestClassesAndFunctions
,
TestPredicates
,
TestGetcallargsFunctions
,
TestGetcallargsMethods
,
TestGetcallargsFunctions
,
TestGetcallargsMethods
,
TestGetcallargsUnboundMethods
,
TestGetattrStatic
,
TestGetGeneratorState
TestGetcallargsUnboundMethods
,
TestGetattrStatic
,
TestGetGeneratorState
,
TestNoEOL
)
)
if
__name__
==
"__main__"
:
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