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
e8cfe521
Commit
e8cfe521
authored
Mar 15, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increased coverage of standard codec error handlers.
parent
74108dda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
30 deletions
+42
-30
Lib/test/test_codeccallbacks.py
Lib/test/test_codeccallbacks.py
+42
-30
No files found.
Lib/test/test_codeccallbacks.py
View file @
e8cfe521
...
...
@@ -441,6 +441,16 @@ class CodecCallbackTest(unittest.TestCase):
codecs
.
strict_errors
,
UnicodeEncodeError
(
"ascii"
,
u"
\
u3042
"
,
0
,
1
,
"ouch"
)
)
self
.
assertRaises
(
UnicodeDecodeError
,
codecs
.
strict_errors
,
UnicodeDecodeError
(
"ascii"
,
"
\
xff
"
,
0
,
1
,
"ouch"
)
)
self
.
assertRaises
(
UnicodeTranslateError
,
codecs
.
strict_errors
,
UnicodeTranslateError
(
u"
\
u3042
"
,
0
,
1
,
"ouch"
)
)
def
test_badandgoodignoreexceptions
(
self
):
# "ignore" complains about a non-exception passed in
...
...
@@ -531,13 +541,16 @@ class CodecCallbackTest(unittest.TestCase):
UnicodeTranslateError
(
u"
\
u3042
"
,
0
,
1
,
"ouch"
)
)
# Use the correct exception
cs
=
(
0
,
1
,
9
,
10
,
99
,
100
,
999
,
1000
,
9999
,
10000
,
0x3042
)
s
=
""
.
join
(
unichr
(
c
)
for
c
in
cs
)
cs
=
(
0
,
1
,
9
,
10
,
99
,
100
,
999
,
1000
,
9999
,
10000
)
cs
+=
(
0xdfff
,
0xd800
)
s
=
u""
.
join
(
unichr
(
c
)
for
c
in
cs
)
s
+=
u"
\
U0001869f
\
U000186a0
\
U000f423f
\
U000f4240
"
cs
+=
(
99999
,
100000
,
999999
,
1000000
)
self
.
assertEqual
(
codecs
.
xmlcharrefreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
s
,
0
,
len
(
s
),
"ouch"
)
),
(
u""
.
join
(
u"&#%d;"
%
ord
(
c
)
for
c
in
s
),
len
(
s
))
(
u""
.
join
(
u"&#%d;"
%
c
for
c
in
c
s
),
len
(
s
))
)
def
test_badandgoodbackslashreplaceexceptions
(
self
):
...
...
@@ -565,34 +578,33 @@ class CodecCallbackTest(unittest.TestCase):
UnicodeTranslateError
(
u"
\
u3042
"
,
0
,
1
,
"ouch"
)
)
# Use the correct exception
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
u3042
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
u3042"
,
1
)
)
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
x00
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
x00"
,
1
)
)
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
xff
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
xff"
,
1
)
)
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
u0100
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
u0100"
,
1
)
)
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
uffff
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
uffff"
,
1
)
)
if
sys
.
maxunicode
>
0xffff
:
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
U00010000
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
U00010000"
,
1
)
)
tests
=
[
(
u"
\
u3042
"
,
u"
\
\
u3042"
),
(
u"
\
n
"
,
u"
\
\
x0a"
),
(
u"a"
,
u"
\
\
x61"
),
(
u"
\
x00
"
,
u"
\
\
x00"
),
(
u"
\
xff
"
,
u"
\
\
xff"
),
(
u"
\
u0100
"
,
u"
\
\
u0100"
),
(
u"
\
uffff
"
,
u"
\
\
uffff"
),
# Lone surrogates
(
u"
\
ud800
"
,
u"
\
\
ud800"
),
(
u"
\
udfff
"
,
u"
\
\
udfff"
),
]
if
sys
.
maxunicode
>
0xffff
:
tests
+=
[
(
u"
\
U00010000
"
,
u"
\
\
U00010000"
),
(
u"
\
U0010ffff
"
,
u"
\
\
U0010ffff"
),
]
else
:
tests
+=
[
(
u"
\
U00010000
"
,
u"
\
\
ud800
\
\
udc00"
),
(
u"
\
U0010ffff
"
,
u"
\
\
udbff
\
\
udfff"
),
]
for
s
,
r
in
tests
:
self
.
assertEqual
(
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
u"
\
U0010ffff
"
,
0
,
1
,
"ouch"
)),
(
u"
\
\
U0010ffff"
,
1
)
codecs
.
backslashreplace_errors
(
UnicodeEncodeError
(
"ascii"
,
s
,
0
,
len
(
s
),
"ouch"
)),
(
r
,
len
(
s
))
)
def
test_badhandlerresults
(
self
):
...
...
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