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
d9c29041
Commit
d9c29041
authored
Apr 08, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #26257: Merge buffer_tests cleanup from 3.5
parents
436064bf
0268628b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
229 deletions
+54
-229
Lib/test/buffer_tests.py
Lib/test/buffer_tests.py
+0
-176
Lib/test/string_tests.py
Lib/test/string_tests.py
+40
-36
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+6
-9
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+8
-8
No files found.
Lib/test/buffer_tests.py
deleted
100644 → 0
View file @
436064bf
# Tests that work for bytearray objects. Could be merged into string_tests.
# See PEP 3137.
class
MixinBytesBufferCommonTests
(
object
):
"""Tests that work for bytearray objects.
See PEP 3137.
"""
def
marshal
(
self
,
x
):
"""Convert x into the appropriate type for these tests."""
raise
RuntimeError
(
'test class must provide a marshal method'
)
def
test_islower
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
islower
())
self
.
assertTrue
(
self
.
marshal
(
b'a'
).
islower
())
self
.
assertFalse
(
self
.
marshal
(
b'A'
).
islower
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
n
'
).
islower
())
self
.
assertTrue
(
self
.
marshal
(
b'abc'
).
islower
())
self
.
assertFalse
(
self
.
marshal
(
b'aBc'
).
islower
())
self
.
assertTrue
(
self
.
marshal
(
b'abc
\
n
'
).
islower
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
islower
,
42
)
def
test_isupper
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
isupper
())
self
.
assertFalse
(
self
.
marshal
(
b'a'
).
isupper
())
self
.
assertTrue
(
self
.
marshal
(
b'A'
).
isupper
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
n
'
).
isupper
())
self
.
assertTrue
(
self
.
marshal
(
b'ABC'
).
isupper
())
self
.
assertFalse
(
self
.
marshal
(
b'AbC'
).
isupper
())
self
.
assertTrue
(
self
.
marshal
(
b'ABC
\
n
'
).
isupper
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
isupper
,
42
)
def
test_istitle
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'a'
).
istitle
())
self
.
assertTrue
(
self
.
marshal
(
b'A'
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
n
'
).
istitle
())
self
.
assertTrue
(
self
.
marshal
(
b'A Titlecased Line'
).
istitle
())
self
.
assertTrue
(
self
.
marshal
(
b'A
\
n
Titlecased Line'
).
istitle
())
self
.
assertTrue
(
self
.
marshal
(
b'A Titlecased, Line'
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'Not a capitalized String'
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'Not
\
t
a Titlecase String'
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'Not--a Titlecase String'
).
istitle
())
self
.
assertFalse
(
self
.
marshal
(
b'NOT'
).
istitle
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
istitle
,
42
)
def
test_isspace
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
isspace
())
self
.
assertFalse
(
self
.
marshal
(
b'a'
).
isspace
())
self
.
assertTrue
(
self
.
marshal
(
b' '
).
isspace
())
self
.
assertTrue
(
self
.
marshal
(
b'
\
t
'
).
isspace
())
self
.
assertTrue
(
self
.
marshal
(
b'
\
r
'
).
isspace
())
self
.
assertTrue
(
self
.
marshal
(
b'
\
n
'
).
isspace
())
self
.
assertTrue
(
self
.
marshal
(
b'
\
t
\
r
\
n
'
).
isspace
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
t
\
r
\
n
a'
).
isspace
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
isspace
,
42
)
def
test_isalpha
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
isalpha
())
self
.
assertTrue
(
self
.
marshal
(
b'a'
).
isalpha
())
self
.
assertTrue
(
self
.
marshal
(
b'A'
).
isalpha
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
n
'
).
isalpha
())
self
.
assertTrue
(
self
.
marshal
(
b'abc'
).
isalpha
())
self
.
assertFalse
(
self
.
marshal
(
b'aBc123'
).
isalpha
())
self
.
assertFalse
(
self
.
marshal
(
b'abc
\
n
'
).
isalpha
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
isalpha
,
42
)
def
test_isalnum
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
isalnum
())
self
.
assertTrue
(
self
.
marshal
(
b'a'
).
isalnum
())
self
.
assertTrue
(
self
.
marshal
(
b'A'
).
isalnum
())
self
.
assertFalse
(
self
.
marshal
(
b'
\
n
'
).
isalnum
())
self
.
assertTrue
(
self
.
marshal
(
b'123abc456'
).
isalnum
())
self
.
assertTrue
(
self
.
marshal
(
b'a1b3c'
).
isalnum
())
self
.
assertFalse
(
self
.
marshal
(
b'aBc000 '
).
isalnum
())
self
.
assertFalse
(
self
.
marshal
(
b'abc
\
n
'
).
isalnum
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
isalnum
,
42
)
def
test_isdigit
(
self
):
self
.
assertFalse
(
self
.
marshal
(
b''
).
isdigit
())
self
.
assertFalse
(
self
.
marshal
(
b'a'
).
isdigit
())
self
.
assertTrue
(
self
.
marshal
(
b'0'
).
isdigit
())
self
.
assertTrue
(
self
.
marshal
(
b'0123456789'
).
isdigit
())
self
.
assertFalse
(
self
.
marshal
(
b'0123456789a'
).
isdigit
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
isdigit
,
42
)
def
test_capitalize
(
self
):
self
.
assertEqual
(
b' hello '
,
self
.
marshal
(
b' hello '
).
capitalize
())
self
.
assertEqual
(
b'Hello '
,
self
.
marshal
(
b'Hello '
).
capitalize
())
self
.
assertEqual
(
b'Hello '
,
self
.
marshal
(
b'hello '
).
capitalize
())
self
.
assertEqual
(
b'Aaaa'
,
self
.
marshal
(
b'aaaa'
).
capitalize
())
self
.
assertEqual
(
b'Aaaa'
,
self
.
marshal
(
b'AaAa'
).
capitalize
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'hello'
).
capitalize
,
42
)
def
test_ljust
(
self
):
self
.
assertEqual
(
b'abc '
,
self
.
marshal
(
b'abc'
).
ljust
(
10
))
self
.
assertEqual
(
b'abc '
,
self
.
marshal
(
b'abc'
).
ljust
(
6
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
ljust
(
3
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
ljust
(
2
))
self
.
assertEqual
(
b'abc*******'
,
self
.
marshal
(
b'abc'
).
ljust
(
10
,
b'*'
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
ljust
)
def
test_rjust
(
self
):
self
.
assertEqual
(
b' abc'
,
self
.
marshal
(
b'abc'
).
rjust
(
10
))
self
.
assertEqual
(
b' abc'
,
self
.
marshal
(
b'abc'
).
rjust
(
6
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
rjust
(
3
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
rjust
(
2
))
self
.
assertEqual
(
b'*******abc'
,
self
.
marshal
(
b'abc'
).
rjust
(
10
,
b'*'
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
rjust
)
def
test_center
(
self
):
self
.
assertEqual
(
b' abc '
,
self
.
marshal
(
b'abc'
).
center
(
10
))
self
.
assertEqual
(
b' abc '
,
self
.
marshal
(
b'abc'
).
center
(
6
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
center
(
3
))
self
.
assertEqual
(
b'abc'
,
self
.
marshal
(
b'abc'
).
center
(
2
))
self
.
assertEqual
(
b'***abc****'
,
self
.
marshal
(
b'abc'
).
center
(
10
,
b'*'
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
center
)
def
test_swapcase
(
self
):
self
.
assertEqual
(
b'hEllO CoMPuTErS'
,
self
.
marshal
(
b'HeLLo cOmpUteRs'
).
swapcase
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'hello'
).
swapcase
,
42
)
def
test_zfill
(
self
):
self
.
assertEqual
(
b'123'
,
self
.
marshal
(
b'123'
).
zfill
(
2
))
self
.
assertEqual
(
b'123'
,
self
.
marshal
(
b'123'
).
zfill
(
3
))
self
.
assertEqual
(
b'0123'
,
self
.
marshal
(
b'123'
).
zfill
(
4
))
self
.
assertEqual
(
b'+123'
,
self
.
marshal
(
b'+123'
).
zfill
(
3
))
self
.
assertEqual
(
b'+123'
,
self
.
marshal
(
b'+123'
).
zfill
(
4
))
self
.
assertEqual
(
b'+0123'
,
self
.
marshal
(
b'+123'
).
zfill
(
5
))
self
.
assertEqual
(
b'-123'
,
self
.
marshal
(
b'-123'
).
zfill
(
3
))
self
.
assertEqual
(
b'-123'
,
self
.
marshal
(
b'-123'
).
zfill
(
4
))
self
.
assertEqual
(
b'-0123'
,
self
.
marshal
(
b'-123'
).
zfill
(
5
))
self
.
assertEqual
(
b'000'
,
self
.
marshal
(
b''
).
zfill
(
3
))
self
.
assertEqual
(
b'34'
,
self
.
marshal
(
b'34'
).
zfill
(
1
))
self
.
assertEqual
(
b'0034'
,
self
.
marshal
(
b'34'
).
zfill
(
4
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'123'
).
zfill
)
def
test_title
(
self
):
self
.
assertEqual
(
b' Hello '
,
self
.
marshal
(
b' hello '
).
title
())
self
.
assertEqual
(
b'Hello '
,
self
.
marshal
(
b'hello '
).
title
())
self
.
assertEqual
(
b'Hello '
,
self
.
marshal
(
b'Hello '
).
title
())
self
.
assertEqual
(
b'Format This As Title String'
,
self
.
marshal
(
b'fOrMaT thIs aS titLe String'
).
title
())
self
.
assertEqual
(
b'Format,This-As*Title;String'
,
self
.
marshal
(
b'fOrMaT,thIs-aS*titLe;String'
).
title
())
self
.
assertEqual
(
b'Getint'
,
self
.
marshal
(
b'getInt'
).
title
())
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'hello'
).
title
,
42
)
def
test_splitlines
(
self
):
self
.
assertEqual
([
b'abc'
,
b'def'
,
b''
,
b'ghi'
],
self
.
marshal
(
b'abc
\
n
def
\
n
\
r
ghi'
).
splitlines
())
self
.
assertEqual
([
b'abc'
,
b'def'
,
b''
,
b'ghi'
],
self
.
marshal
(
b'abc
\
n
def
\
n
\
r
\
n
ghi'
).
splitlines
())
self
.
assertEqual
([
b'abc'
,
b'def'
,
b'ghi'
],
self
.
marshal
(
b'abc
\
n
def
\
r
\
n
ghi'
).
splitlines
())
self
.
assertEqual
([
b'abc'
,
b'def'
,
b'ghi'
],
self
.
marshal
(
b'abc
\
n
def
\
r
\
n
ghi
\
n
'
).
splitlines
())
self
.
assertEqual
([
b'abc'
,
b'def'
,
b'ghi'
,
b''
],
self
.
marshal
(
b'abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
())
self
.
assertEqual
([
b''
,
b'abc'
,
b'def'
,
b'ghi'
,
b''
],
self
.
marshal
(
b'
\
n
abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
())
self
.
assertEqual
([
b''
,
b'abc'
,
b'def'
,
b'ghi'
,
b''
],
self
.
marshal
(
b'
\
n
abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
(
False
))
self
.
assertEqual
([
b'
\
n
'
,
b'abc
\
n
'
,
b'def
\
r
\
n
'
,
b'ghi
\
n
'
,
b'
\
r
'
],
self
.
marshal
(
b'
\
n
abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
(
True
))
self
.
assertEqual
([
b''
,
b'abc'
,
b'def'
,
b'ghi'
,
b''
],
self
.
marshal
(
b'
\
n
abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
(
keepends
=
False
))
self
.
assertEqual
([
b'
\
n
'
,
b'abc
\
n
'
,
b'def
\
r
\
n
'
,
b'ghi
\
n
'
,
b'
\
r
'
],
self
.
marshal
(
b'
\
n
abc
\
n
def
\
r
\
n
ghi
\
n
\
r
'
).
splitlines
(
keepends
=
True
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'abc'
).
splitlines
,
42
,
42
)
Lib/test/string_tests.py
View file @
d9c29041
...
@@ -51,6 +51,9 @@ class BaseTest:
...
@@ -51,6 +51,9 @@ class BaseTest:
else
:
else
:
return
obj
return
obj
def
test_fixtype
(
self
):
self
.
assertIs
(
type
(
self
.
fixtype
(
"123"
)),
self
.
type2test
)
# check that obj.method(*args) returns result
# check that obj.method(*args) returns result
def
checkequal
(
self
,
result
,
obj
,
methodname
,
*
args
,
**
kwargs
):
def
checkequal
(
self
,
result
,
obj
,
methodname
,
*
args
,
**
kwargs
):
result
=
self
.
fixtype
(
result
)
result
=
self
.
fixtype
(
result
)
...
@@ -682,21 +685,6 @@ class BaseTest:
...
@@ -682,21 +685,6 @@ class BaseTest:
self
.
checkraises
(
OverflowError
,
A2_16
,
"replace"
,
"A"
,
A2_16
)
self
.
checkraises
(
OverflowError
,
A2_16
,
"replace"
,
"A"
,
A2_16
)
self
.
checkraises
(
OverflowError
,
A2_16
,
"replace"
,
"AA"
,
A2_16
+
A2_16
)
self
.
checkraises
(
OverflowError
,
A2_16
,
"replace"
,
"AA"
,
A2_16
+
A2_16
)
class
CommonTest
(
BaseTest
):
# This testcase contains tests that can be used in all
# stringlike classes. Currently this is str and UserString.
def
test_hash
(
self
):
# SF bug 1054139: += optimization was not invalidating cached hash value
a
=
self
.
type2test
(
'DNSSEC'
)
b
=
self
.
type2test
(
''
)
for
c
in
a
:
b
+=
c
hash
(
b
)
self
.
assertEqual
(
hash
(
a
),
hash
(
b
))
def
test_capitalize
(
self
):
def
test_capitalize
(
self
):
self
.
checkequal
(
' hello '
,
' hello '
,
'capitalize'
)
self
.
checkequal
(
' hello '
,
' hello '
,
'capitalize'
)
self
.
checkequal
(
'Hello '
,
'Hello '
,
'capitalize'
)
self
.
checkequal
(
'Hello '
,
'Hello '
,
'capitalize'
)
...
@@ -704,23 +692,6 @@ class CommonTest(BaseTest):
...
@@ -704,23 +692,6 @@ class CommonTest(BaseTest):
self
.
checkequal
(
'Aaaa'
,
'aaaa'
,
'capitalize'
)
self
.
checkequal
(
'Aaaa'
,
'aaaa'
,
'capitalize'
)
self
.
checkequal
(
'Aaaa'
,
'AaAa'
,
'capitalize'
)
self
.
checkequal
(
'Aaaa'
,
'AaAa'
,
'capitalize'
)
# check that titlecased chars are lowered correctly
# \u1ffc is the titlecased char
self
.
checkequal
(
'
\
u03a9
\
u0399
\
u1ff3
\
u1ff3
\
u1ff3
'
,
'
\
u1ff3
\
u1ff3
\
u1ffc
\
u1ffc
'
,
'capitalize'
)
# check with cased non-letter chars
self
.
checkequal
(
'
\
u24c5
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'
\
u24c5
\
u24ce
\
u24c9
\
u24bd
\
u24c4
\
u24c3
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u24c5
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'
\
u24df
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u2160
\
u2171
\
u2172
'
,
'
\
u2160
\
u2161
\
u2162
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u2160
\
u2171
\
u2172
'
,
'
\
u2170
\
u2171
\
u2172
'
,
'capitalize'
)
# check with Ll chars with no upper - nothing changes here
self
.
checkequal
(
'
\
u019b
\
u1d00
\
u1d86
\
u0221
\
u1fb7
'
,
'
\
u019b
\
u1d00
\
u1d86
\
u0221
\
u1fb7
'
,
'capitalize'
)
self
.
checkraises
(
TypeError
,
'hello'
,
'capitalize'
,
42
)
self
.
checkraises
(
TypeError
,
'hello'
,
'capitalize'
,
42
)
def
test_additional_split
(
self
):
def
test_additional_split
(
self
):
...
@@ -854,10 +825,6 @@ class CommonTest(BaseTest):
...
@@ -854,10 +825,6 @@ class CommonTest(BaseTest):
self
.
checkraises
(
TypeError
,
'123'
,
'zfill'
)
self
.
checkraises
(
TypeError
,
'123'
,
'zfill'
)
class
MixinStrUnicodeUserStringTest
:
# additional tests that only work for
# stringlike objects, i.e. str, UserString
def
test_islower
(
self
):
def
test_islower
(
self
):
self
.
checkequal
(
False
,
''
,
'islower'
)
self
.
checkequal
(
False
,
''
,
'islower'
)
self
.
checkequal
(
True
,
'a'
,
'islower'
)
self
.
checkequal
(
True
,
'a'
,
'islower'
)
...
@@ -960,6 +927,43 @@ class MixinStrUnicodeUserStringTest:
...
@@ -960,6 +927,43 @@ class MixinStrUnicodeUserStringTest:
self
.
checkraises
(
TypeError
,
'abc'
,
'splitlines'
,
42
,
42
)
self
.
checkraises
(
TypeError
,
'abc'
,
'splitlines'
,
42
,
42
)
class
CommonTest
(
BaseTest
):
# This testcase contains tests that can be used in all
# stringlike classes. Currently this is str and UserString.
def
test_hash
(
self
):
# SF bug 1054139: += optimization was not invalidating cached hash value
a
=
self
.
type2test
(
'DNSSEC'
)
b
=
self
.
type2test
(
''
)
for
c
in
a
:
b
+=
c
hash
(
b
)
self
.
assertEqual
(
hash
(
a
),
hash
(
b
))
def
test_capitalize_nonascii
(
self
):
# check that titlecased chars are lowered correctly
# \u1ffc is the titlecased char
self
.
checkequal
(
'
\
u03a9
\
u0399
\
u1ff3
\
u1ff3
\
u1ff3
'
,
'
\
u1ff3
\
u1ff3
\
u1ffc
\
u1ffc
'
,
'capitalize'
)
# check with cased non-letter chars
self
.
checkequal
(
'
\
u24c5
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'
\
u24c5
\
u24ce
\
u24c9
\
u24bd
\
u24c4
\
u24c3
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u24c5
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'
\
u24df
\
u24e8
\
u24e3
\
u24d7
\
u24de
\
u24dd
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u2160
\
u2171
\
u2172
'
,
'
\
u2160
\
u2161
\
u2162
'
,
'capitalize'
)
self
.
checkequal
(
'
\
u2160
\
u2171
\
u2172
'
,
'
\
u2170
\
u2171
\
u2172
'
,
'capitalize'
)
# check with Ll chars with no upper - nothing changes here
self
.
checkequal
(
'
\
u019b
\
u1d00
\
u1d86
\
u0221
\
u1fb7
'
,
'
\
u019b
\
u1d00
\
u1d86
\
u0221
\
u1fb7
'
,
'capitalize'
)
class
MixinStrUnicodeUserStringTest
:
# additional tests that only work for
# stringlike objects, i.e. str, UserString
def
test_startswith
(
self
):
def
test_startswith
(
self
):
self
.
checkequal
(
True
,
'hello'
,
'startswith'
,
'he'
)
self
.
checkequal
(
True
,
'hello'
,
'startswith'
,
'he'
)
self
.
checkequal
(
True
,
'hello'
,
'startswith'
,
'hello'
)
self
.
checkequal
(
True
,
'hello'
,
'startswith'
,
'hello'
)
...
...
Lib/test/test_bytes.py
View file @
d9c29041
"""Unit tests for the bytes and bytearray types.
"""Unit tests for the bytes and bytearray types.
XXX This is a mess. Common tests should be moved to buffer_tests.py,
XXX This is a mess. Common tests should be unified with string_tests.py (and
which itself ought to be unified with string_tests.py (and the latter
the latter should be modernized).
should be modernized).
"""
"""
import
os
import
os
...
@@ -16,7 +15,6 @@ import unittest
...
@@ -16,7 +15,6 @@ import unittest
import
test.support
import
test.support
import
test.string_tests
import
test.string_tests
import
test.buffer_tests
import
test.list_tests
import
test.list_tests
from
test.support
import
bigaddrspacetest
,
MAX_Py_ssize_t
from
test.support
import
bigaddrspacetest
,
MAX_Py_ssize_t
...
@@ -1575,8 +1573,7 @@ class AssortedBytesTest(unittest.TestCase):
...
@@ -1575,8 +1573,7 @@ class AssortedBytesTest(unittest.TestCase):
# the rest that make sense (the code can be cleaned up to use modern
# the rest that make sense (the code can be cleaned up to use modern
# unittest methods at the same time).
# unittest methods at the same time).
class BytearrayPEP3137Test(unittest.TestCase,
class BytearrayPEP3137Test(unittest.TestCase):
test.buffer_tests.MixinBytesBufferCommonTests):
def marshal(self, x):
def marshal(self, x):
return bytearray(x)
return bytearray(x)
...
@@ -1606,16 +1603,16 @@ class BytearrayPEP3137Test(unittest.TestCase,
...
@@ -1606,16 +1603,16 @@ class BytearrayPEP3137Test(unittest.TestCase,
class FixedStringTest(test.string_tests.BaseTest):
class FixedStringTest(test.string_tests.BaseTest):
def fixtype(self, obj):
def fixtype(self, obj):
if isinstance(obj, str):
if isinstance(obj, str):
return
obj.encode("utf-8"
)
return
self.type2test(obj.encode("utf-8")
)
return super().fixtype(obj)
return super().fixtype(obj)
contains_bytes = True
class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase):
class ByteArrayAsStringTest(FixedStringTest, unittest.TestCase):
type2test = bytearray
type2test = bytearray
contains_bytes = True
class BytesAsStringTest(FixedStringTest, unittest.TestCase):
class BytesAsStringTest(FixedStringTest, unittest.TestCase):
type2test = bytes
type2test = bytes
contains_bytes = True
class SubclassTest:
class SubclassTest:
...
...
Lib/test/test_unicode.py
View file @
d9c29041
...
@@ -565,7 +565,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -565,7 +565,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertTrue
(
'
\
ud800
\
udc02
'
<
'
\
ud84d
\
udc56
'
)
self
.
assertTrue
(
'
\
ud800
\
udc02
'
<
'
\
ud84d
\
udc56
'
)
def
test_islower
(
self
):
def
test_islower
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_islower
(
self
)
s
uper
().
test_islower
(
)
self
.
checkequalnofix
(
False
,
'
\
u1FFc
'
,
'islower'
)
self
.
checkequalnofix
(
False
,
'
\
u1FFc
'
,
'islower'
)
self
.
assertFalse
(
'
\
u2167
'
.
islower
())
self
.
assertFalse
(
'
\
u2167
'
.
islower
())
self
.
assertTrue
(
'
\
u2177
'
.
islower
())
self
.
assertTrue
(
'
\
u2177
'
.
islower
())
...
@@ -580,7 +580,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -580,7 +580,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertFalse
(
'
\
U0001F46F
'
.
islower
())
self
.
assertFalse
(
'
\
U0001F46F
'
.
islower
())
def
test_isupper
(
self
):
def
test_isupper
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_isupper
(
self
)
s
uper
().
test_isupper
(
)
if
not
sys
.
platform
.
startswith
(
'java'
):
if
not
sys
.
platform
.
startswith
(
'java'
):
self
.
checkequalnofix
(
False
,
'
\
u1FFc
'
,
'isupper'
)
self
.
checkequalnofix
(
False
,
'
\
u1FFc
'
,
'isupper'
)
self
.
assertTrue
(
'
\
u2167
'
.
isupper
())
self
.
assertTrue
(
'
\
u2167
'
.
isupper
())
...
@@ -596,7 +596,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -596,7 +596,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertFalse
(
'
\
U0001F46F
'
.
isupper
())
self
.
assertFalse
(
'
\
U0001F46F
'
.
isupper
())
def
test_istitle
(
self
):
def
test_istitle
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_istitle
(
self
)
s
uper
().
test_istitle
(
)
self
.
checkequalnofix
(
True
,
'
\
u1FFc
'
,
'istitle'
)
self
.
checkequalnofix
(
True
,
'
\
u1FFc
'
,
'istitle'
)
self
.
checkequalnofix
(
True
,
'Greek
\
u1FFc
itlecases ...'
,
'istitle'
)
self
.
checkequalnofix
(
True
,
'Greek
\
u1FFc
itlecases ...'
,
'istitle'
)
...
@@ -608,7 +608,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -608,7 +608,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertFalse
(
ch
.
istitle
(),
'{!a} is not title'
.
format
(
ch
))
self
.
assertFalse
(
ch
.
istitle
(),
'{!a} is not title'
.
format
(
ch
))
def
test_isspace
(
self
):
def
test_isspace
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_isspace
(
self
)
s
uper
().
test_isspace
(
)
self
.
checkequalnofix
(
True
,
'
\
u2000
'
,
'isspace'
)
self
.
checkequalnofix
(
True
,
'
\
u2000
'
,
'isspace'
)
self
.
checkequalnofix
(
True
,
'
\
u200a
'
,
'isspace'
)
self
.
checkequalnofix
(
True
,
'
\
u200a
'
,
'isspace'
)
self
.
checkequalnofix
(
False
,
'
\
u2014
'
,
'isspace'
)
self
.
checkequalnofix
(
False
,
'
\
u2014
'
,
'isspace'
)
...
@@ -618,13 +618,13 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -618,13 +618,13 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertFalse
(
ch
.
isspace
(),
'{!a} is not space.'
.
format
(
ch
))
self
.
assertFalse
(
ch
.
isspace
(),
'{!a} is not space.'
.
format
(
ch
))
def
test_isalnum
(
self
):
def
test_isalnum
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_isalnum
(
self
)
s
uper
().
test_isalnum
(
)
for
ch
in
[
'
\
U00010401
'
,
'
\
U00010427
'
,
'
\
U00010429
'
,
'
\
U0001044E
'
,
for
ch
in
[
'
\
U00010401
'
,
'
\
U00010427
'
,
'
\
U00010429
'
,
'
\
U0001044E
'
,
'
\
U0001D7F6
'
,
'
\
U00011066
'
,
'
\
U000104A0
'
,
'
\
U0001F107
'
]:
'
\
U0001D7F6
'
,
'
\
U00011066
'
,
'
\
U000104A0
'
,
'
\
U0001F107
'
]:
self
.
assertTrue
(
ch
.
isalnum
(),
'{!a} is alnum.'
.
format
(
ch
))
self
.
assertTrue
(
ch
.
isalnum
(),
'{!a} is alnum.'
.
format
(
ch
))
def
test_isalpha
(
self
):
def
test_isalpha
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_isalpha
(
self
)
s
uper
().
test_isalpha
(
)
self
.
checkequalnofix
(
True
,
'
\
u1FFc
'
,
'isalpha'
)
self
.
checkequalnofix
(
True
,
'
\
u1FFc
'
,
'isalpha'
)
# non-BMP, cased
# non-BMP, cased
self
.
assertTrue
(
'
\
U00010401
'
.
isalpha
())
self
.
assertTrue
(
'
\
U00010401
'
.
isalpha
())
...
@@ -654,7 +654,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -654,7 +654,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertTrue
(
ch
.
isdecimal
(),
'{!a} is decimal.'
.
format
(
ch
))
self
.
assertTrue
(
ch
.
isdecimal
(),
'{!a} is decimal.'
.
format
(
ch
))
def
test_isdigit
(
self
):
def
test_isdigit
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_isdigit
(
self
)
s
uper
().
test_isdigit
(
)
self
.
checkequalnofix
(
True
,
'
\
u2460
'
,
'isdigit'
)
self
.
checkequalnofix
(
True
,
'
\
u2460
'
,
'isdigit'
)
self
.
checkequalnofix
(
False
,
'
\
xbc
'
,
'isdigit'
)
self
.
checkequalnofix
(
False
,
'
\
xbc
'
,
'isdigit'
)
self
.
checkequalnofix
(
True
,
'
\
u0660
'
,
'isdigit'
)
self
.
checkequalnofix
(
True
,
'
\
u0660
'
,
'isdigit'
)
...
@@ -807,7 +807,7 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -807,7 +807,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
'A
\
u0345
\
u03a3
'
.
capitalize
(),
'A
\
u0345
\
u03c2
'
)
self
.
assertEqual
(
'A
\
u0345
\
u03a3
'
.
capitalize
(),
'A
\
u0345
\
u03c2
'
)
def
test_title
(
self
):
def
test_title
(
self
):
s
tring_tests
.
MixinStrUnicodeUserStringTest
.
test_title
(
self
)
s
uper
().
test_title
(
)
self
.
assertEqual
(
'
\
U0001044F
'
.
title
(),
'
\
U00010427
'
)
self
.
assertEqual
(
'
\
U0001044F
'
.
title
(),
'
\
U00010427
'
)
self
.
assertEqual
(
'
\
U0001044F
\
U0001044F
'
.
title
(),
self
.
assertEqual
(
'
\
U0001044F
\
U0001044F
'
.
title
(),
'
\
U00010427
\
U0001044F
'
)
'
\
U00010427
\
U0001044F
'
)
...
...
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