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
0c7081af
Kaydet (Commit)
0c7081af
authored
Eki 16, 2012
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge for issue #15744: add tests for the writelines() method of file objects.
üst
ad626807
3ed2cb55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
test_fileio.py
Lib/test/test_fileio.py
+22
-0
test_io.py
Lib/test/test_io.py
+46
-1
No files found.
Lib/test/test_fileio.py
Dosyayı görüntüle @
0c7081af
...
...
@@ -10,6 +10,7 @@ from weakref import proxy
from
functools
import
wraps
from
test.support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
from
collections
import
UserList
from
_io
import
FileIO
as
_FileIO
...
...
@@ -68,6 +69,27 @@ class AutoFileTests(unittest.TestCase):
n
=
self
.
f
.
readinto
(
a
)
self
.
assertEqual
(
array
(
'b'
,
[
1
,
2
]),
a
[:
n
])
def
testWritelinesList
(
self
):
l
=
[
b
'123'
,
b
'456'
]
self
.
f
.
writelines
(
l
)
self
.
f
.
close
()
self
.
f
=
_FileIO
(
TESTFN
,
'rb'
)
buf
=
self
.
f
.
read
()
self
.
assertEqual
(
buf
,
b
'123456'
)
def
testWritelinesUserList
(
self
):
l
=
UserList
([
b
'123'
,
b
'456'
])
self
.
f
.
writelines
(
l
)
self
.
f
.
close
()
self
.
f
=
_FileIO
(
TESTFN
,
'rb'
)
buf
=
self
.
f
.
read
()
self
.
assertEqual
(
buf
,
b
'123456'
)
def
testWritelinesError
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
f
.
writelines
,
[
1
,
2
,
3
])
self
.
assertRaises
(
TypeError
,
self
.
f
.
writelines
,
None
)
self
.
assertRaises
(
TypeError
,
self
.
f
.
writelines
,
"abc"
)
def
test_none_args
(
self
):
self
.
f
.
write
(
b
"hi
\n
bye
\n
abc"
)
self
.
f
.
close
()
...
...
Lib/test/test_io.py
Dosyayı görüntüle @
0c7081af
...
...
@@ -32,7 +32,7 @@ import time
import
unittest
import
warnings
import
weakref
from
collections
import
deque
from
collections
import
deque
,
UserList
from
itertools
import
cycle
,
count
from
test
import
support
...
...
@@ -1193,6 +1193,29 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
bufio
.
flush
()
self
.
assertEqual
(
b
"abc"
,
writer
.
_write_stack
[
0
])
def
test_writelines
(
self
):
l
=
[
b
'ab'
,
b
'cd'
,
b
'ef'
]
writer
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
writer
,
8
)
bufio
.
writelines
(
l
)
bufio
.
flush
()
self
.
assertEqual
(
b
''
.
join
(
writer
.
_write_stack
),
b
'abcdef'
)
def
test_writelines_userlist
(
self
):
l
=
UserList
([
b
'ab'
,
b
'cd'
,
b
'ef'
])
writer
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
writer
,
8
)
bufio
.
writelines
(
l
)
bufio
.
flush
()
self
.
assertEqual
(
b
''
.
join
(
writer
.
_write_stack
),
b
'abcdef'
)
def
test_writelines_error
(
self
):
writer
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
writer
,
8
)
self
.
assertRaises
(
TypeError
,
bufio
.
writelines
,
[
1
,
2
,
3
])
self
.
assertRaises
(
TypeError
,
bufio
.
writelines
,
None
)
self
.
assertRaises
(
TypeError
,
bufio
.
writelines
,
'abc'
)
def
test_destructor
(
self
):
writer
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
writer
,
8
)
...
...
@@ -2296,6 +2319,28 @@ class TextIOWrapperTest(unittest.TestCase):
reads
+=
c
self
.
assertEqual
(
reads
,
"A"
*
127
+
"
\n
B"
)
def
test_writelines
(
self
):
l
=
[
'ab'
,
'cd'
,
'ef'
]
buf
=
self
.
BytesIO
()
txt
=
self
.
TextIOWrapper
(
buf
)
txt
.
writelines
(
l
)
txt
.
flush
()
self
.
assertEqual
(
buf
.
getvalue
(),
b
'abcdef'
)
def
test_writelines_userlist
(
self
):
l
=
UserList
([
'ab'
,
'cd'
,
'ef'
])
buf
=
self
.
BytesIO
()
txt
=
self
.
TextIOWrapper
(
buf
)
txt
.
writelines
(
l
)
txt
.
flush
()
self
.
assertEqual
(
buf
.
getvalue
(),
b
'abcdef'
)
def
test_writelines_error
(
self
):
txt
=
self
.
TextIOWrapper
(
self
.
BytesIO
())
self
.
assertRaises
(
TypeError
,
txt
.
writelines
,
[
1
,
2
,
3
])
self
.
assertRaises
(
TypeError
,
txt
.
writelines
,
None
)
self
.
assertRaises
(
TypeError
,
txt
.
writelines
,
b
'abc'
)
def
test_issue1395_1
(
self
):
txt
=
self
.
TextIOWrapper
(
self
.
BytesIO
(
self
.
testdata
),
encoding
=
"ascii"
)
...
...
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