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
78e761ea
Commit
78e761ea
authored
Oct 16, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the writelines() method of file objects.
Original patch by Felipe Cruz.
parent
ce5a56e9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+21
-0
Lib/test/test_io.py
Lib/test/test_io.py
+23
-0
No files found.
Lib/test/test_fileio.py
View file @
78e761ea
...
...
@@ -9,6 +9,7 @@ import unittest
from
array
import
array
from
weakref
import
proxy
from
functools
import
wraps
from
UserList
import
UserList
from
test.test_support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
from
test.test_support
import
py3k_bytes
as
bytes
...
...
@@ -71,6 +72,26 @@ class AutoFileTests(unittest.TestCase):
n
=
self
.
f
.
readinto
(
a
)
self
.
assertEqual
(
array
(
b'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
)
def
test_none_args
(
self
):
self
.
f
.
write
(
b"hi
\
n
bye
\
n
abc"
)
self
.
f
.
close
()
...
...
Lib/test/test_io.py
View file @
78e761ea
...
...
@@ -34,6 +34,7 @@ import signal
import
errno
from
itertools
import
cycle
,
count
from
collections
import
deque
from
UserList
import
UserList
from
test
import
test_support
as
support
import
codecs
...
...
@@ -1126,6 +1127,28 @@ 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
)
def
test_destructor
(
self
):
writer
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
writer
,
8
)
...
...
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