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
631a35c7
Kaydet (Commit)
631a35c7
authored
Agu 19, 2015
tarafından
Robert Collins
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #24054: decouple linecache tests from inspect tests
Patch from David D. Riddle
üst
572183cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
11 deletions
+63
-11
test_linecache.py
Lib/test/test_linecache.py
+63
-11
No files found.
Lib/test/test_linecache.py
Dosyayı görüntüle @
631a35c7
...
...
@@ -3,6 +3,7 @@
import
linecache
import
unittest
import
os.path
import
tempfile
from
test
import
support
...
...
@@ -10,8 +11,6 @@ FILENAME = linecache.__file__
NONEXISTENT_FILENAME
=
FILENAME
+
'.missing'
INVALID_NAME
=
'!@$)(!@#_1'
EMPTY
=
''
TESTS
=
'inspect_fodder inspect_fodder2 mapping_tests'
TESTS
=
TESTS
.
split
()
TEST_PATH
=
os
.
path
.
dirname
(
__file__
)
MODULES
=
"linecache abc"
.
split
()
MODULE_PATH
=
os
.
path
.
dirname
(
FILENAME
)
...
...
@@ -37,6 +36,65 @@ def f():
return 3'''
# No ending newline
class
TempFile
:
def
setUp
(
self
):
super
()
.
setUp
()
with
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
as
fp
:
self
.
file_name
=
fp
.
name
fp
.
write
(
self
.
file_byte_string
)
self
.
addCleanup
(
support
.
unlink
,
self
.
file_name
)
class
GetLineTestsGoodData
(
TempFile
):
# file_list = ['list\n', 'of\n', 'good\n', 'strings\n']
def
setUp
(
self
):
self
.
file_byte_string
=
''
.
join
(
self
.
file_list
)
.
encode
(
'utf-8'
)
super
()
.
setUp
()
def
test_getline
(
self
):
with
open
(
self
.
file_name
)
as
fp
:
for
index
,
line
in
enumerate
(
fp
):
if
not
line
.
endswith
(
'
\n
'
):
line
+=
'
\n
'
cached_line
=
linecache
.
getline
(
self
.
file_name
,
index
+
1
)
self
.
assertEqual
(
line
,
cached_line
)
def
test_getlines
(
self
):
lines
=
linecache
.
getlines
(
self
.
file_name
)
self
.
assertEqual
(
lines
,
self
.
file_list
)
class
GetLineTestsBadData
(
TempFile
):
# file_byte_string = b'Bad data goes here'
def
test_getline
(
self
):
self
.
assertRaises
((
SyntaxError
,
UnicodeDecodeError
),
linecache
.
getline
,
self
.
file_name
,
1
)
def
test_getlines
(
self
):
self
.
assertRaises
((
SyntaxError
,
UnicodeDecodeError
),
linecache
.
getlines
,
self
.
file_name
)
class
EmptyFile
(
GetLineTestsGoodData
,
unittest
.
TestCase
):
file_list
=
[]
class
SingleEmptyLine
(
GetLineTestsGoodData
,
unittest
.
TestCase
):
file_list
=
[
'
\n
'
]
class
GoodUnicode
(
GetLineTestsGoodData
,
unittest
.
TestCase
):
file_list
=
[
'á
\n
'
,
'b
\n
'
,
'abcdef
\n
'
,
'ááááá
\n
'
]
class
BadUnicode
(
GetLineTestsBadData
,
unittest
.
TestCase
):
file_byte_string
=
b
'
\x80
abc'
class
LineCacheTests
(
unittest
.
TestCase
):
def
test_getline
(
self
):
...
...
@@ -53,13 +111,6 @@ class LineCacheTests(unittest.TestCase):
self
.
assertEqual
(
getline
(
EMPTY
,
1
),
EMPTY
)
self
.
assertEqual
(
getline
(
INVALID_NAME
,
1
),
EMPTY
)
# Check whether lines correspond to those from file iteration
for
entry
in
TESTS
:
filename
=
os
.
path
.
join
(
TEST_PATH
,
entry
)
+
'.py'
with
open
(
filename
)
as
file
:
for
index
,
line
in
enumerate
(
file
):
self
.
assertEqual
(
line
,
getline
(
filename
,
index
+
1
))
# Check module loading
for
entry
in
MODULES
:
filename
=
os
.
path
.
join
(
MODULE_PATH
,
entry
)
+
'.py'
...
...
@@ -80,12 +131,13 @@ class LineCacheTests(unittest.TestCase):
def
test_clearcache
(
self
):
cached
=
[]
for
entry
in
TEST
S
:
filename
=
os
.
path
.
join
(
TEST
_PATH
,
entry
)
+
'.py'
for
entry
in
MODULE
S
:
filename
=
os
.
path
.
join
(
MODULE
_PATH
,
entry
)
+
'.py'
cached
.
append
(
filename
)
linecache
.
getline
(
filename
,
1
)
# Are all files cached?
self
.
assertNotEqual
(
cached
,
[])
cached_empty
=
[
fn
for
fn
in
cached
if
fn
not
in
linecache
.
cache
]
self
.
assertEqual
(
cached_empty
,
[])
...
...
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