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
517b7473
Commit
517b7473
authored
Feb 26, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for issue #20501.
parent
7bbd101b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
Lib/test/test_fileinput.py
Lib/test/test_fileinput.py
+36
-0
No files found.
Lib/test/test_fileinput.py
View file @
517b7473
...
...
@@ -258,6 +258,24 @@ class FileInputTests(unittest.TestCase):
fi
.
readline
()
self
.
assertTrue
(
custom_open_hook
.
invoked
,
"openhook not invoked"
)
def
test_readline
(
self
):
with
open
(
TESTFN
,
'wb'
)
as
f
:
f
.
write
(
b'A
\
n
B
\
r
\
n
C
\
r
'
)
# Fill TextIOWrapper buffer.
f
.
write
(
b'123456789
\
n
'
*
1000
)
# Issue #20501: readline() shouldn't read whole file.
f
.
write
(
b'
\
x80
'
)
self
.
addCleanup
(
safe_unlink
,
TESTFN
)
with
FileInput
(
files
=
TESTFN
,
openhook
=
hook_encoded
(
'ascii'
),
bufsize
=
8
)
as
fi
:
self
.
assertEqual
(
fi
.
readline
(),
'A
\
n
'
)
self
.
assertEqual
(
fi
.
readline
(),
'B
\
n
'
)
self
.
assertEqual
(
fi
.
readline
(),
'C
\
n
'
)
with
self
.
assertRaises
(
UnicodeDecodeError
):
# Read to the end of file.
list
(
fi
)
def
test_context_manager
(
self
):
try
:
t1
=
writeTmp
(
1
,
[
"A
\
n
B
\
n
C"
])
...
...
@@ -835,6 +853,24 @@ class Test_hook_encoded(unittest.TestCase):
self
.
assertIs
(
kwargs
.
pop
(
'encoding'
),
encoding
)
self
.
assertFalse
(
kwargs
)
def
test_modes
(
self
):
# Unlikely UTF-7 is locale encoding
with
open
(
TESTFN
,
'wb'
)
as
f
:
f
.
write
(
b'A
\
n
B
\
r
\
n
C
\
r
D+IKw-'
)
self
.
addCleanup
(
safe_unlink
,
TESTFN
)
def
check
(
mode
,
expected_lines
):
with
FileInput
(
files
=
TESTFN
,
mode
=
mode
,
openhook
=
hook_encoded
(
'utf-7'
))
as
fi
:
lines
=
list
(
fi
)
self
.
assertEqual
(
lines
,
expected_lines
)
check
(
'r'
,
[
'A
\
n
'
,
'B
\
n
'
,
'C
\
n
'
,
'D
\
u20ac
'
])
check
(
'rU'
,
[
'A
\
n
'
,
'B
\
n
'
,
'C
\
n
'
,
'D
\
u20ac
'
])
check
(
'U'
,
[
'A
\
n
'
,
'B
\
n
'
,
'C
\
n
'
,
'D
\
u20ac
'
])
with
self
.
assertRaises
(
ValueError
):
check
(
'rb'
,
[
'A
\
n
'
,
'B
\
r
\
n
'
,
'C
\
r
'
,
'D
\
u20ac
'
])
def
test_main
():
run_unittest
(
BufferSizesTests
,
...
...
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