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
518d261f
Kaydet (Commit)
518d261f
authored
Nis 14, 2002
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Test suite for universal newline support.
üst
7b8c7546
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
0 deletions
+114
-0
test_univnewlines.py
Lib/test/test_univnewlines.py
+114
-0
No files found.
Lib/test/test_univnewlines.py
0 → 100644
Dosyayı görüntüle @
518d261f
# Tests universal newline support for both reading and parsing files.
import
unittest
import
test_support
import
os
import
sys
DATA_TEMPLATE
=
[
"line1=1"
,
"line2='this is a very long line designed to go past the magic "
+
"hundred character limit that is inside fileobject.c and which "
+
"is meant to speed up the common case, but we also want to test "
+
"the uncommon case, naturally.'"
,
"def line3():pass"
]
DATA_LF
=
"
\n
"
.
join
(
DATA_TEMPLATE
)
+
"
\n
"
DATA_CR
=
"
\r
"
.
join
(
DATA_TEMPLATE
)
+
"
\r
"
DATA_CRLF
=
"
\r\n
"
.
join
(
DATA_TEMPLATE
)
+
"
\r\n
"
# Note that DATA_MIXED also tests the ability to recognize a lone \r
# before end-of-file.
DATA_MIXED
=
"
\n
"
.
join
(
DATA_TEMPLATE
)
+
"
\r
"
DATA_SPLIT
=
map
(
lambda
x
:
x
+
"
\n
"
,
DATA_TEMPLATE
)
if
not
hasattr
(
sys
.
stdin
,
'newlines'
):
raise
test_support
.
TestSkipped
,
\
"This Python does not have universal newline support"
class
TestGenericUnivNewlines
(
unittest
.
TestCase
):
# use a class variable DATA to define the data to write to the file
# and a class variable NEWLINE to set the expected newlines value
READMODE
=
'U'
WRITEMODE
=
'wb'
def
setUp
(
self
):
fp
=
open
(
test_support
.
TESTFN
,
self
.
WRITEMODE
)
fp
.
write
(
self
.
DATA
)
fp
.
close
()
def
tearDown
(
self
):
try
:
os
.
unlink
(
test_support
.
TESTFN
)
except
:
pass
def
test_read
(
self
):
fp
=
open
(
test_support
.
TESTFN
,
self
.
READMODE
)
data
=
fp
.
read
()
self
.
assertEqual
(
data
,
DATA_LF
)
self
.
assertEqual
(
`fp.newlines`
,
`self.NEWLINE`
)
def
test_readlines
(
self
):
fp
=
open
(
test_support
.
TESTFN
,
self
.
READMODE
)
data
=
fp
.
readlines
()
self
.
assertEqual
(
data
,
DATA_SPLIT
)
self
.
assertEqual
(
`fp.newlines`
,
`self.NEWLINE`
)
def
test_readline
(
self
):
fp
=
open
(
test_support
.
TESTFN
,
self
.
READMODE
)
data
=
[]
d
=
fp
.
readline
()
while
d
:
data
.
append
(
d
)
d
=
fp
.
readline
()
self
.
assertEqual
(
data
,
DATA_SPLIT
)
self
.
assertEqual
(
`fp.newlines`
,
`self.NEWLINE`
)
def
test_seek
(
self
):
fp
=
open
(
test_support
.
TESTFN
,
self
.
READMODE
)
fp
.
readline
()
pos
=
fp
.
tell
()
data
=
fp
.
readlines
()
self
.
assertEqual
(
data
,
DATA_SPLIT
[
1
:])
fp
.
seek
(
pos
)
data
=
fp
.
readlines
()
self
.
assertEqual
(
data
,
DATA_SPLIT
[
1
:])
def
test_execfile
(
self
):
dict
=
{}
execfile
(
test_support
.
TESTFN
,
dict
)
func
=
dict
[
'line3'
]
self
.
assertEqual
(
func
.
func_code
.
co_firstlineno
,
3
)
class
TestNativeNewlines
(
TestGenericUnivNewlines
):
NEWLINE
=
None
DATA
=
DATA_LF
READMODE
=
'r'
WRITEMODE
=
'w'
class
TestCRNewlines
(
TestGenericUnivNewlines
):
NEWLINE
=
'
\r
'
DATA
=
DATA_CR
class
TestLFNewlines
(
TestGenericUnivNewlines
):
NEWLINE
=
'
\n
'
DATA
=
DATA_LF
class
TestCRLFNewlines
(
TestGenericUnivNewlines
):
NEWLINE
=
'
\r\n
'
DATA
=
DATA_CRLF
class
TestMixedNewlines
(
TestGenericUnivNewlines
):
NEWLINE
=
(
'
\r
'
,
'
\n
'
)
DATA
=
DATA_MIXED
def
test_main
():
test_support
.
run_unittest
(
TestNativeNewlines
)
test_support
.
run_unittest
(
TestCRNewlines
)
test_support
.
run_unittest
(
TestLFNewlines
)
test_support
.
run_unittest
(
TestCRLFNewlines
)
test_support
.
run_unittest
(
TestMixedNewlines
)
if
__name__
==
'__main__'
:
test_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