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
5cfc79de
Commit
5cfc79de
authored
Feb 07, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20532: Tests which use _testcapi now are marked as CPython only.
parent
fe4ef392
Changes
25
Hide whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
237 additions
and
104 deletions
+237
-104
Lib/test/string_tests.py
Lib/test/string_tests.py
+15
-8
Lib/test/support/__init__.py
Lib/test/support/__init__.py
+1
-1
Lib/test/test_capi.py
Lib/test/test_capi.py
+2
-1
Lib/test/test_code.py
Lib/test/test_code.py
+3
-2
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+54
-31
Lib/test/test_descr.py
Lib/test/test_descr.py
+1
-0
Lib/test/test_devpoll.py
Lib/test/test_devpoll.py
+12
-3
Lib/test/test_exceptions.py
Lib/test/test_exceptions.py
+2
-0
Lib/test/test_fcntl.py
Lib/test/test_fcntl.py
+28
-19
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+5
-2
Lib/test/test_format.py
Lib/test/test_format.py
+16
-6
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+2
-0
Lib/test/test_io.py
Lib/test/test_io.py
+3
-2
Lib/test/test_poll.py
Lib/test/test_poll.py
+12
-3
Lib/test/test_posix.py
Lib/test/test_posix.py
+5
-1
Lib/test/test_socket.py
Lib/test/test_socket.py
+30
-6
Lib/test/test_structmembers.py
Lib/test/test_structmembers.py
+5
-3
Lib/test/test_sys.py
Lib/test/test_sys.py
+1
-0
Lib/test/test_tcl.py
Lib/test/test_tcl.py
+8
-4
Lib/test/test_threading.py
Lib/test/test_threading.py
+2
-1
Lib/test/test_time.py
Lib/test/test_time.py
+3
-0
Lib/test/test_traceback.py
Lib/test/test_traceback.py
+5
-2
Lib/test/test_ucn.py
Lib/test/test_ucn.py
+10
-8
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+10
-1
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/string_tests.py
View file @
5cfc79de
...
...
@@ -5,7 +5,6 @@ Common tests shared by test_str, test_unicode, test_userstring and test_string.
import
unittest
,
string
,
sys
,
struct
from
test
import
support
from
collections
import
UserList
import
_testcapi
class
Sequence
:
def
__init__
(
self
,
seq
=
'wxyz'
):
self
.
seq
=
seq
...
...
@@ -1185,19 +1184,27 @@ class MixinStrUnicodeUserStringTest:
# Outrageously large width or precision should raise ValueError.
self
.
checkraises
(
ValueError
,
'%%%df'
%
(
2
**
64
),
'__mod__'
,
(
3.2
))
self
.
checkraises
(
ValueError
,
'%%.%df'
%
(
2
**
64
),
'__mod__'
,
(
3.2
))
self
.
checkraises
(
OverflowError
,
'%*s'
,
'__mod__'
,
(
sys
.
maxsize
+
1
,
''
))
self
.
checkraises
(
OverflowError
,
'%.*f'
,
'__mod__'
,
(
sys
.
maxsize
+
1
,
1.
/
7
))
class
X
(
object
):
pass
self
.
checkraises
(
TypeError
,
'abc'
,
'__mod__'
,
X
())
@
support
.
cpython_only
def
test_formatting_c_limits
(
self
):
from
_testcapi
import
PY_SSIZE_T_MAX
,
INT_MAX
,
UINT_MAX
SIZE_MAX
=
(
1
<<
(
PY_SSIZE_T_MAX
.
bit_length
()
+
1
))
-
1
self
.
checkraises
(
OverflowError
,
'%*s'
,
'__mod__'
,
(
_testcapi
.
PY_SSIZE_T_MAX
+
1
,
''
))
(
PY_SSIZE_T_MAX
+
1
,
''
))
self
.
checkraises
(
OverflowError
,
'%.*f'
,
'__mod__'
,
(
_testcapi
.
INT_MAX
+
1
,
1.
/
7
))
(
INT_MAX
+
1
,
1.
/
7
))
# Issue 15989
self
.
checkraises
(
OverflowError
,
'%*s'
,
'__mod__'
,
(
1
<<
(
_testcapi
.
PY_SSIZE_T_MAX
.
bit_length
()
+
1
)
,
''
))
(
SIZE_MAX
+
1
,
''
))
self
.
checkraises
(
OverflowError
,
'%.*f'
,
'__mod__'
,
(
_testcapi
.
UINT_MAX
+
1
,
1.
/
7
))
class
X
(
object
):
pass
self
.
checkraises
(
TypeError
,
'abc'
,
'__mod__'
,
X
())
(
UINT_MAX
+
1
,
1.
/
7
))
def
test_floatformatting
(
self
):
# float formatting
...
...
Lib/test/support/__init__.py
View file @
5cfc79de
...
...
@@ -25,7 +25,6 @@ import fnmatch
import
logging.handlers
import
struct
import
tempfile
import
_testcapi
try
:
import
_thread
,
threading
...
...
@@ -1349,6 +1348,7 @@ _TPFLAGS_HAVE_GC = 1<<14
_TPFLAGS_HEAPTYPE
=
1
<<
9
def
check_sizeof
(
test
,
o
,
size
):
import
_testcapi
result
=
sys
.
getsizeof
(
o
)
# add GC header size
if
((
type
(
o
)
==
type
)
and
(
o
.
__flags__
&
_TPFLAGS_HEAPTYPE
)
or
\
...
...
Lib/test/test_capi.py
View file @
5cfc79de
...
...
@@ -17,7 +17,8 @@ try:
import
threading
except
ImportError
:
threading
=
None
import
_testcapi
# Skip this test if the _testcapi module isn't available.
_testcapi
=
support
.
import_module
(
'_testcapi'
)
def
testfunction
(
self
):
...
...
Lib/test/test_code.py
View file @
5cfc79de
...
...
@@ -104,7 +104,7 @@ consts: ('None',)
import
unittest
import
weakref
import
_testcapi
from
test.support
import
run_doctest
,
run_unittest
,
cpython_only
def
consts
(
t
):
...
...
@@ -126,7 +126,9 @@ def dump(co):
class
CodeTest
(
unittest
.
TestCase
):
@
cpython_only
def
test_newempty
(
self
):
import
_testcapi
co
=
_testcapi
.
code_newempty
(
"filename"
,
"funcname"
,
15
)
self
.
assertEqual
(
co
.
co_filename
,
"filename"
)
self
.
assertEqual
(
co
.
co_name
,
"funcname"
)
...
...
@@ -159,7 +161,6 @@ class CodeWeakRefTest(unittest.TestCase):
def
test_main
(
verbose
=
None
):
from
test.support
import
run_doctest
,
run_unittest
from
test
import
test_code
run_doctest
(
test_code
,
verbose
)
run_unittest
(
CodeTest
,
CodeWeakRefTest
)
...
...
Lib/test/test_codecs.py
View file @
5cfc79de
import
_testcapi
import
codecs
import
io
import
locale
...
...
@@ -1710,7 +1709,7 @@ broken_incremental_coders = broken_unicode_with_streams + [
class
BasicUnicodeTest
(
unittest
.
TestCase
,
MixInCheckStateHandling
):
def
test_basics
(
self
):
s
=
"abc123"
# all codecs should be able to encode these
s
=
"abc123"
# all codecs should be able to encode these
for
encoding
in
all_unicode_encodings
:
name
=
codecs
.
lookup
(
encoding
).
name
if
encoding
.
endswith
(
"_codec"
):
...
...
@@ -1722,9 +1721,9 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
with
support
.
check_warnings
():
# unicode-internal has been deprecated
(
b
,
size
)
=
codecs
.
getencoder
(
encoding
)(
s
)
self
.
assertEqual
(
size
,
len
(
s
),
"
%r != %r (encoding=%r)"
%
(
size
,
len
(
s
),
encoding
)
)
self
.
assertEqual
(
size
,
len
(
s
),
"
encoding=%r"
%
encoding
)
(
chars
,
size
)
=
codecs
.
getdecoder
(
encoding
)(
b
)
self
.
assertEqual
(
chars
,
s
,
"
%r != %r (encoding=%r)"
%
(
chars
,
s
,
encoding
)
)
self
.
assertEqual
(
chars
,
s
,
"
encoding=%r"
%
encoding
)
if
encoding
not
in
broken_unicode_with_streams
:
# check stream reader/writer
...
...
@@ -1742,15 +1741,13 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
for
c
in
encodedresult
:
q
.
write
(
bytes
([
c
]))
decodedresult
+=
reader
.
read
()
self
.
assertEqual
(
decodedresult
,
s
,
"
%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
)
)
self
.
assertEqual
(
decodedresult
,
s
,
"
encoding=%r"
%
encoding
)
if
encoding
not
in
broken_incremental_coders
:
# check incremental decoder/encoder (fetched via the Python
# and C API) and iterencode()/iterdecode()
# check incremental decoder/encoder and iterencode()/iterdecode()
try
:
encoder
=
codecs
.
getincrementalencoder
(
encoding
)()
cencoder
=
_testcapi
.
codec_incrementalencoder
(
encoding
)
except
LookupError
:
# no IncrementalEncoder
except
LookupError
:
# no IncrementalEncoder
pass
else
:
# check incremental decoder/encoder
...
...
@@ -1763,45 +1760,71 @@ class BasicUnicodeTest(unittest.TestCase, MixInCheckStateHandling):
for
c
in
encodedresult
:
decodedresult
+=
decoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
decoder
.
decode
(
b""
,
True
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
self
.
assertEqual
(
decodedresult
,
s
,
"encoding=%r"
%
encoding
)
# check iterencode()/iterdecode()
result
=
""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
s
,
encoding
),
encoding
))
self
.
assertEqual
(
result
,
s
,
"encoding=%r"
%
encoding
)
# check iterencode()/iterdecode() with empty string
result
=
""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
""
,
encoding
),
encoding
))
self
.
assertEqual
(
result
,
""
)
if
encoding
not
in
(
"idna"
,
"mbcs"
):
# check incremental decoder/encoder with errors argument
try
:
encoder
=
codecs
.
getincrementalencoder
(
encoding
)(
"ignore"
)
except
LookupError
:
# no IncrementalEncoder
pass
else
:
encodedresult
=
b""
.
join
(
encoder
.
encode
(
c
)
for
c
in
s
)
decoder
=
codecs
.
getincrementaldecoder
(
encoding
)(
"ignore"
)
decodedresult
=
""
.
join
(
decoder
.
decode
(
bytes
([
c
]))
for
c
in
encodedresult
)
self
.
assertEqual
(
decodedresult
,
s
,
"encoding=%r"
%
encoding
)
@
support
.
cpython_only
def
test_basics_capi
(
self
):
from
_testcapi
import
codec_incrementalencoder
,
codec_incrementaldecoder
s
=
"abc123"
# all codecs should be able to encode these
for
encoding
in
all_unicode_encodings
:
if
encoding
not
in
broken_incremental_coders
:
# check incremental decoder/encoder (fetched via the C API)
try
:
cencoder
=
codec_incrementalencoder
(
encoding
)
except
LookupError
:
# no IncrementalEncoder
pass
else
:
# check C API
encodedresult
=
b""
for
c
in
s
:
encodedresult
+=
cencoder
.
encode
(
c
)
encodedresult
+=
cencoder
.
encode
(
""
,
True
)
cdecoder
=
_testcapi
.
codec_incrementaldecoder
(
encoding
)
cdecoder
=
codec_incrementaldecoder
(
encoding
)
decodedresult
=
""
for
c
in
encodedresult
:
decodedresult
+=
cdecoder
.
decode
(
bytes
([
c
]))
decodedresult
+=
cdecoder
.
decode
(
b""
,
True
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check iterencode()/iterdecode()
result
=
""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
s
,
encoding
),
encoding
))
self
.
assertEqual
(
result
,
s
,
"%r != %r (encoding=%r)"
%
(
result
,
s
,
encoding
))
# check iterencode()/iterdecode() with empty string
result
=
""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
""
,
encoding
),
encoding
))
self
.
assertEqual
(
result
,
""
)
self
.
assertEqual
(
decodedresult
,
s
,
"encoding=%r"
%
encoding
)
if
encoding
not
in
(
"idna"
,
"mbcs"
):
# check incremental decoder/encoder with errors argument
try
:
encoder
=
codecs
.
getincrementalencoder
(
encoding
)(
"ignore"
)
cencoder
=
_testcapi
.
codec_incrementalencoder
(
encoding
,
"ignore"
)
except
LookupError
:
# no IncrementalEncoder
cencoder
=
codec_incrementalencoder
(
encoding
,
"ignore"
)
except
LookupError
:
# no IncrementalEncoder
pass
else
:
encodedresult
=
b""
.
join
(
encoder
.
encode
(
c
)
for
c
in
s
)
decoder
=
codecs
.
getincrementaldecoder
(
encoding
)(
"ignore"
)
decodedresult
=
""
.
join
(
decoder
.
decode
(
bytes
([
c
]))
for
c
in
encodedresult
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
encodedresult
=
b""
.
join
(
cencoder
.
encode
(
c
)
for
c
in
s
)
cdecoder
=
_testcapi
.
codec_incrementaldecoder
(
encoding
,
"ignore"
)
decodedresult
=
""
.
join
(
cdecoder
.
decode
(
bytes
([
c
]))
for
c
in
encodedresult
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
cdecoder
=
codec_incrementaldecoder
(
encoding
,
"ignore"
)
decodedresult
=
""
.
join
(
cdecoder
.
decode
(
bytes
([
c
]))
for
c
in
encodedresult
)
self
.
assertEqual
(
decodedresult
,
s
,
"encoding=%r"
%
encoding
)
def
test_seek
(
self
):
# all codecs should be able to encode these
...
...
Lib/test/test_descr.py
View file @
5cfc79de
...
...
@@ -2046,6 +2046,7 @@ order (MRO) for bases """
prop2
=
property
(
fset
=
setter
)
self
.
assertEqual
(
prop2
.
__doc__
,
None
)
@
support
.
cpython_only
def
test_testcapi_no_segfault
(
self
):
# this segfaulted in 2.5b2
try
:
...
...
Lib/test/test_devpoll.py
View file @
5cfc79de
...
...
@@ -3,8 +3,7 @@
# Initial tests are copied as is from "test_poll.py"
import
os
,
select
,
random
,
unittest
,
sys
from
test.support
import
TESTFN
,
run_unittest
from
_testcapi
import
USHRT_MAX
from
test.support
import
TESTFN
,
run_unittest
,
cpython_only
try
:
select
.
devpoll
...
...
@@ -94,8 +93,18 @@ class DevPollTests(unittest.TestCase):
pollster
.
register
(
w
)
# Issue #17919
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
-
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
USHRT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
1
<<
64
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
-
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
1
<<
64
)
@
cpython_only
def
test_events_mask_overflow_c_limits
(
self
):
from
_testcapi
import
USHRT_MAX
pollster
=
select
.
devpoll
()
w
,
r
=
os
.
pipe
()
pollster
.
register
(
w
)
# Issue #17919
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
USHRT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
USHRT_MAX
+
1
)
...
...
Lib/test/test_exceptions.py
View file @
5cfc79de
...
...
@@ -832,6 +832,7 @@ class ExceptionTests(unittest.TestCase):
self
.
assertIn
(
"maximum recursion depth exceeded"
,
str
(
v
))
@
cpython_only
def
test_MemoryError
(
self
):
# PyErr_NoMemory always raises the same exception instance.
# Check that the traceback is not doubled.
...
...
@@ -890,6 +891,7 @@ class ExceptionTests(unittest.TestCase):
self
.
assertEqual
(
error5
.
a
,
1
)
self
.
assertEqual
(
error5
.
__doc__
,
""
)
@
cpython_only
def
test_memory_error_cleanup
(
self
):
# Issue #5437: preallocated MemoryError instances should not keep
# traceback objects alive.
...
...
Lib/test/test_fcntl.py
View file @
5cfc79de
...
...
@@ -7,9 +7,9 @@ import platform
import
os
import
struct
import
sys
import
_testcapi
import
unittest
from
test.support
import
verbose
,
TESTFN
,
unlink
,
run_unittest
,
import_module
from
test.support
import
(
verbose
,
TESTFN
,
unlink
,
run_unittest
,
import_module
,
cpython_only
)
# Skip test if no fcntl module.
fcntl
=
import_module
(
'fcntl'
)
...
...
@@ -50,6 +50,12 @@ def get_lockdata():
lockdata
=
get_lockdata
()
class
BadFile
:
def
__init__
(
self
,
fn
):
self
.
fn
=
fn
def
fileno
(
self
):
return
self
.
fn
class
TestFcntl
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -81,24 +87,27 @@ class TestFcntl(unittest.TestCase):
self
.
f
.
close
()
def
test_fcntl_bad_file
(
self
):
class
F
:
def
__init__
(
self
,
fn
):
self
.
fn
=
fn
def
fileno
(
self
):
return
self
.
fn
self
.
assertRaises
(
ValueError
,
fcntl
.
fcntl
,
-
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
ValueError
,
fcntl
.
fcntl
,
F
(
-
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
TypeError
,
fcntl
.
fcntl
,
'spam'
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
TypeError
,
fcntl
.
fcntl
,
F
(
'spam'
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
ValueError
):
fcntl
.
fcntl
(
-
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
ValueError
):
fcntl
.
fcntl
(
BadFile
(
-
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
TypeError
):
fcntl
.
fcntl
(
'spam'
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
TypeError
):
fcntl
.
fcntl
(
BadFile
(
'spam'
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
@
cpython_only
def
test_fcntl_bad_file_overflow
(
self
):
from
_testcapi
import
INT_MAX
,
INT_MIN
# Issue 15989
self
.
assertRaises
(
OverflowError
,
fcntl
.
fcntl
,
_testcapi
.
INT_MAX
+
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
OverflowError
,
fcntl
.
fcntl
,
F
(
_testcapi
.
INT_MAX
+
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
OverflowError
,
fcntl
.
fcntl
,
_testcapi
.
INT_MIN
-
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
self
.
assertRaises
(
OverflowError
,
fcntl
.
fcntl
,
F
(
_testcapi
.
INT_MIN
-
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
OverflowError
):
fcntl
.
fcntl
(
INT_MAX
+
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
OverflowError
):
fcntl
.
fcntl
(
BadFile
(
INT_MAX
+
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
OverflowError
):
fcntl
.
fcntl
(
INT_MIN
-
1
,
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
with
self
.
assertRaises
(
OverflowError
):
fcntl
.
fcntl
(
BadFile
(
INT_MIN
-
1
),
fcntl
.
F_SETFL
,
os
.
O_NONBLOCK
)
@
unittest
.
skipIf
(
platform
.
machine
().
startswith
(
'arm'
)
and
platform
.
system
()
==
'Linux'
,
...
...
Lib/test/test_fileio.py
View file @
5cfc79de
...
...
@@ -8,9 +8,8 @@ import unittest
from
array
import
array
from
weakref
import
proxy
from
functools
import
wraps
import
_testcapi
from
test.support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
from
test.support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
,
cpython_only
from
collections
import
UserList
from
_io
import
FileIO
as
_FileIO
...
...
@@ -362,7 +361,11 @@ class OtherFileTests(unittest.TestCase):
if
sys
.
platform
==
'win32'
:
import
msvcrt
self
.
assertRaises
(
IOError
,
msvcrt
.
get_osfhandle
,
make_bad_fd
())
@
cpython_only
def
testInvalidFd_overflow
(
self
):
# Issue 15989
import
_testcapi
self
.
assertRaises
(
TypeError
,
_FileIO
,
_testcapi
.
INT_MAX
+
1
)
self
.
assertRaises
(
TypeError
,
_FileIO
,
_testcapi
.
INT_MIN
-
1
)
...
...
Lib/test/test_format.py
View file @
5cfc79de
...
...
@@ -313,22 +313,32 @@ def test_main():
support
.
run_unittest
(
FormatTest
)
def
test_precision
(
self
):
INT_MAX
=
2147483647
f
=
1.2
self
.
assertEqual
(
format
(
f
,
".0f"
),
"1"
)
self
.
assertEqual
(
format
(
f
,
".3f"
),
"1.200"
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
f
,
".%sf"
%
(
INT_MAX
+
1
))
format
(
f
,
".%sf"
%
(
sys
.
maxsize
+
1
))
self
.
assertEqual
(
str
(
cm
.
exception
),
"precision too big"
)
c
=
complex
(
f
)
self
.
assertEqual
(
format
(
f
,
".0f"
),
"1
"
)
self
.
assertEqual
(
format
(
f
,
".3f"
),
"1.200
"
)
self
.
assertEqual
(
format
(
c
,
".0f"
),
"1+0j
"
)
self
.
assertEqual
(
format
(
c
,
".3f"
),
"1.200+0.000j
"
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
f
,
".%sf"
%
(
INT_MAX
+
1
))
format
(
c
,
".%sf"
%
(
sys
.
maxsize
+
1
))
self
.
assertEqual
(
str
(
cm
.
exception
),
"precision too big"
)
@
support
.
cpython_only
def
test_precision_c_limits
(
self
):
from
_testcapi
import
INT_MAX
f
=
1.2
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
f
,
".%sf"
%
(
INT_MAX
+
1
))
c
=
complex
(
f
)
with
self
.
assertRaises
(
ValueError
)
as
cm
:
format
(
c
,
".%sf"
%
(
INT_MAX
+
1
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/test/test_getargs2.py
View file @
5cfc79de
import
unittest
from
test
import
support
# Skip this test if the _testcapi module isn't available.
support
.
import_module
(
'_testcapi'
)
from
_testcapi
import
getargs_keywords
,
getargs_keyword_only
"""
...
...
Lib/test/test_io.py
View file @
5cfc79de
...
...
@@ -32,7 +32,6 @@ import time
import
unittest
import
warnings
import
weakref
import
_testcapi
from
collections
import
deque
,
UserList
from
itertools
import
cycle
,
count
from
test
import
support
...
...
@@ -1977,8 +1976,10 @@ class TextIOWrapperTest(unittest.TestCase):
os
.
environ
.
clear
()
os
.
environ
.
update
(
old_environ
)
# Issue 15989
@
support
.
cpython_only
def
test_device_encoding
(
self
):
# Issue 15989
import
_testcapi
b
=
self
.
BytesIO
()
b
.
fileno
=
lambda
:
_testcapi
.
INT_MAX
+
1
self
.
assertRaises
(
OverflowError
,
self
.
TextIOWrapper
,
b
)
...
...
Lib/test/test_poll.py
View file @
5cfc79de
...
...
@@ -3,14 +3,13 @@
import
os
import
random
import
select
from
_testcapi
import
USHRT_MAX
,
INT_MAX
,
UINT_MAX
try
:
import
threading
except
ImportError
:
threading
=
None
import
time
import
unittest
from
test.support
import
TESTFN
,
run_unittest
,
reap_threads
from
test.support
import
TESTFN
,
run_unittest
,
reap_threads
,
cpython_only
try
:
select
.
poll
...
...
@@ -161,8 +160,18 @@ class PollTests(unittest.TestCase):
# Issues #15989, #17919
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
-
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
USHRT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
1
<<
64
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
-
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
1
<<
64
)
@
cpython_only
def
test_poll_c_limits
(
self
):
from
_testcapi
import
USHRT_MAX
,
INT_MAX
,
UINT_MAX
pollster
=
select
.
poll
()
pollster
.
register
(
1
)
# Issues #15989, #17919
self
.
assertRaises
(
OverflowError
,
pollster
.
register
,
0
,
USHRT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
modify
,
1
,
USHRT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
poll
,
INT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
pollster
.
poll
,
UINT_MAX
+
1
)
...
...
Lib/test/test_posix.py
View file @
5cfc79de
...
...
@@ -17,7 +17,6 @@ import stat
import
tempfile
import
unittest
import
warnings
import
_testcapi
_DUMMY_SYMLINK
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
support
.
TESTFN
+
'-dummy-symlink'
)
...
...
@@ -615,7 +614,12 @@ class PosixTester(unittest.TestCase):
except
OSError
:
pass
@
support
.
cpython_only
@
unittest
.
skipUnless
(
hasattr
(
os
,
'pipe2'
),
"test needs os.pipe2()"
)
@
support
.
requires_linux_version
(
2
,
6
,
27
)
def
test_pipe2_c_limits
(
self
):
# Issue 15989
import
_testcapi
self
.
assertRaises
(
OverflowError
,
os
.
pipe2
,
_testcapi
.
INT_MAX
+
1
)
self
.
assertRaises
(
OverflowError
,
os
.
pipe2
,
_testcapi
.
UINT_MAX
+
1
)
...
...
Lib/test/test_socket.py
View file @
5cfc79de
...
...
@@ -7,7 +7,6 @@ import io
import
socket
import
select
import
tempfile
import
_testcapi
import
time
import
traceback
import
queue
...
...
@@ -1274,7 +1273,10 @@ class GeneralModuleTests(unittest.TestCase):
srv
.
listen
(
backlog
)
srv
.
close
()
@
support
.
cpython_only
def
test_listen_backlog_overflow
(
self
):
# Issue 15989
import
_testcapi
srv
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
srv
.
bind
((
HOST
,
0
))
self
.
assertRaises
(
OverflowError
,
srv
.
listen
,
_testcapi
.
INT_MAX
+
1
)
...
...
@@ -1592,6 +1594,14 @@ class BasicTCPTest(SocketConnectedTest):
self
.
done
.
wait
()
def
_testShutdown
(
self
):
self
.
serv_conn
.
send
(
MSG
)
self
.
serv_conn
.
shutdown
(
2
)
testShutdown_overflow
=
support
.
cpython_only
(
testShutdown
)
@
support
.
cpython_only
def
_testShutdown_overflow
(
self
):
import
_testcapi
self
.
serv_conn
.
send
(
MSG
)
# Issue 15989
self
.
assertRaises
(
OverflowError
,
self
.
serv_conn
.
shutdown
,
...
...
@@ -2361,7 +2371,12 @@ class CmsgMacroTests(unittest.TestCase):
# code with these functions.
# Match the definition in socketmodule.c
socklen_t_limit
=
min
(
0x7fffffff
,
_testcapi
.
INT_MAX
)
try
:
import
_testcapi
except
ImportError
:
socklen_t_limit
=
0x7fffffff
else
:
socklen_t_limit
=
min
(
0x7fffffff
,
_testcapi
.
INT_MAX
)
@
requireAttrs
(
socket
,
"CMSG_LEN"
)
def
testCMSG_LEN
(
self
):
...
...
@@ -3586,14 +3601,23 @@ class NonBlockingTCPTests(ThreadedTCPSocketTest):
pass
end
=
time
.
time
()
self
.
assertTrue
((
end
-
start
)
<
1.0
,
"Error setting non-blocking mode."
)
# Issue 15989
if
_testcapi
.
UINT_MAX
<
_testcapi
.
ULONG_MAX
:
self
.
serv
.
setblocking
(
_testcapi
.
UINT_MAX
+
1
)
self
.
assertIsNone
(
self
.
serv
.
gettimeout
())
def
_testSetBlocking
(
self
):
pass
@
support
.
cpython_only
def
testSetBlocking_overflow
(
self
):
# Issue 15989
import
_testcapi
if
_testcapi
.
UINT_MAX
>=
_testcapi
.
ULONG_MAX
:
self
.
skipTest
(
'needs UINT_MAX < ULONG_MAX'
)
self
.
serv
.
setblocking
(
False
)
self
.
assertEqual
(
self
.
serv
.
gettimeout
(),
0.0
)
self
.
serv
.
setblocking
(
_testcapi
.
UINT_MAX
+
1
)
self
.
assertIsNone
(
self
.
serv
.
gettimeout
())
_testSetBlocking_overflow
=
support
.
cpython_only
(
_testSetBlocking
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'SOCK_NONBLOCK'
),
'test needs socket.SOCK_NONBLOCK'
)
@
support
.
requires_linux_version
(
2
,
6
,
28
)
...
...
Lib/test/test_structmembers.py
View file @
5cfc79de
import
unittest
from
test
import
support
# Skip this test if the _testcapi module isn't available.
support
.
import_module
(
'_testcapi'
)
from
_testcapi
import
_test_structmembersType
,
\
CHAR_MAX
,
CHAR_MIN
,
UCHAR_MAX
,
\
SHRT_MAX
,
SHRT_MIN
,
USHRT_MAX
,
\
...
...
@@ -6,9 +11,6 @@ from _testcapi import _test_structmembersType, \
LLONG_MAX
,
LLONG_MIN
,
ULLONG_MAX
,
\
PY_SSIZE_T_MAX
,
PY_SSIZE_T_MIN
import
unittest
from
test
import
support
ts
=
_test_structmembersType
(
False
,
# T_BOOL
1
,
# T_BYTE
2
,
# T_UBYTE
...
...
Lib/test/test_sys.py
View file @
5cfc79de
...
...
@@ -610,6 +610,7 @@ class SysModuleTest(unittest.TestCase):
ret
,
out
,
err
=
assert_python_ok
(
*
args
)
self
.
assertIn
(
b"free PyDictObjects"
,
err
)
@
test
.
support
.
cpython_only
class
SizeofTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Lib/test/test_tcl.py
View file @
5cfc79de
import
unittest
import
sys
import
os
import
_testcapi
from
test
import
support
# Skip this test if the _tkinter module wasn't built.
...
...
@@ -13,6 +12,11 @@ support.import_fresh_module('tkinter')
from
tkinter
import
Tcl
from
_tkinter
import
TclError
try
:
from
_testcapi
import
INT_MAX
,
PY_SSIZE_T_MAX
except
ImportError
:
INT_MAX
=
PY_SSIZE_T_MAX
=
sys
.
maxsize
tcl_version
=
_tkinter
.
TCL_VERSION
.
split
(
'.'
)
try
:
for
i
in
range
(
len
(
tcl_version
)):
...
...
@@ -539,9 +543,9 @@ class BigmemTclTest(unittest.TestCase):
def setUp(self):
self.interp = Tcl()
@
unittest.skipUnless(_testcapi.INT_MAX < _testcapi.PY_SSIZE_T_MAX,
"needs UINT_MAX < SIZE_MAX")
@support.bigmemtest(size=
_testcapi.
INT_MAX + 1, memuse=5, dry_run=False)
@
support.cpython_only
@unittest.skipUnless(INT_MAX < PY_SSIZE_T_MAX,
"needs UINT_MAX < SIZE_MAX")
@support.bigmemtest(size=INT_MAX + 1, memuse=5, dry_run=False)
def test_huge_string(self, size):
value = '
' * size
self.assertRaises(OverflowError, self.interp.call, '
set
', '
_
', value)
...
...
Lib/test/test_threading.py
View file @
5cfc79de
...
...
@@ -3,7 +3,7 @@ Tests for the threading module.
"""
import
test.support
from
test.support
import
verbose
,
strip_python_stderr
,
import_module
from
test.support
import
verbose
,
strip_python_stderr
,
import_module
,
cpython_only
from
test.script_helper
import
assert_python_ok
import
random
...
...
@@ -773,6 +773,7 @@ class ThreadJoinOnShutdown(BaseTestCase):
for
t
in
threads
:
t
.
join
()
@
cpython_only
@
unittest
.
skipIf
(
_testcapi
is
None
,
"need _testcapi module"
)
def
test_frame_tstate_tracing
(
self
):
# Issue #14432: Crash when a generator is created in a C thread that is
...
...
Lib/test/test_time.py
View file @
5cfc79de
...
...
@@ -573,6 +573,7 @@ class TestPytime(unittest.TestCase):
-
(
2.0
**
100.0
),
2.0
**
100.0
,
)
@
support
.
cpython_only
def
test_time_t
(
self
):
from
_testcapi
import
pytime_object_to_time_t
for
obj
,
time_t
in
(
...
...
@@ -588,6 +589,7 @@ class TestPytime(unittest.TestCase):
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
pytime_object_to_time_t
,
invalid
)
@
support
.
cpython_only
def
test_timeval
(
self
):
from
_testcapi
import
pytime_object_to_timeval
for
obj
,
timeval
in
(
...
...
@@ -607,6 +609,7 @@ class TestPytime(unittest.TestCase):
for
invalid
in
self
.
invalid_values
:
self
.
assertRaises
(
OverflowError
,
pytime_object_to_timeval
,
invalid
)
@
support
.
cpython_only
def
test_timespec
(
self
):
from
_testcapi
import
pytime_object_to_timespec
for
obj
,
timespec
in
(
...
...
Lib/test/test_traceback.py
View file @
5cfc79de
"""Test cases for traceback module"""
from
_testcapi
import
traceback_print
,
exception_print
from
io
import
StringIO
import
sys
import
unittest
import
re
from
test.support
import
run_unittest
,
Error
,
captured_output
from
test.support
import
TESTFN
,
unlink
from
test.support
import
TESTFN
,
unlink
,
cpython_only
import
traceback
...
...
@@ -173,7 +172,9 @@ class SyntaxTracebackCases(unittest.TestCase):
class
TracebackFormatTests
(
unittest
.
TestCase
):
@
cpython_only
def
test_traceback_format
(
self
):
from
_testcapi
import
traceback_print
try
:
raise
KeyError
(
'blah'
)
except
KeyError
:
...
...
@@ -360,7 +361,9 @@ class CExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
# This checks built-in reporting by the interpreter.
#
@
cpython_only
def
get_report
(
self
,
e
):
from
_testcapi
import
exception_print
e
=
self
.
get_exception
(
e
)
with
captured_output
(
"stderr"
)
as
s
:
exception_print
(
e
)
...
...
Lib/test/test_ucn.py
View file @
5cfc79de
...
...
@@ -9,12 +9,16 @@ Modified for Python 2.0 by Fredrik Lundh (fredrik@pythonware.com)
import
unittest
import
unicodedata
import
_testcapi
from
test
import
support
from
http.client
import
HTTPException
from
test.test_normalization
import
check_version
try
:
from
_testcapi
import
INT_MAX
,
PY_SSIZE_T_MAX
,
UINT_MAX
except
ImportError
:
INT_MAX
=
PY_SSIZE_T_MAX
=
UINT_MAX
=
2
**
64
-
1
class
UnicodeNamesTest
(
unittest
.
TestCase
):
def
checkletter
(
self
,
name
,
code
):
...
...
@@ -216,15 +220,13 @@ class UnicodeNamesTest(unittest.TestCase):
str
,
b"
\
\
NSPACE"
,
'unicode-escape'
,
'strict'
)
@
unittest
.
skipUnless
(
_testcapi
.
INT_MAX
<
_testcapi
.
PY_SSIZE_T_MAX
,
"needs UINT_MAX < SIZE_MAX"
)
@
support
.
bigmemtest
(
size
=
_testcapi
.
UINT_MAX
+
1
,
memuse
=
2
+
1
,
dry_run
=
False
)
@
support
.
cpython_only
@
unittest
.
skipUnless
(
INT_MAX
<
PY_SSIZE_T_MAX
,
"needs UINT_MAX < SIZE_MAX"
)
@
support
.
bigmemtest
(
size
=
UINT_MAX
+
1
,
memuse
=
2
+
1
,
dry_run
=
False
)
def
test_issue16335
(
self
,
size
):
# very very long bogus character name
x
=
b'
\
\
N{SPACE'
+
b'x'
*
(
_testcapi
.
UINT_MAX
+
1
)
+
b'}'
self
.
assertEqual
(
len
(
x
),
len
(
b'
\
\
N{SPACE}'
)
+
(
_testcapi
.
UINT_MAX
+
1
))
x
=
b'
\
\
N{SPACE'
+
b'x'
*
(
UINT_MAX
+
1
)
+
b'}'
self
.
assertEqual
(
len
(
x
),
len
(
b'
\
\
N{SPACE}'
)
+
(
UINT_MAX
+
1
))
self
.
assertRaisesRegex
(
UnicodeError
,
'unknown Unicode character name'
,
x
.
decode
,
'unicode-escape'
...
...
Lib/test/test_unicode.py
View file @
5cfc79de
...
...
@@ -1108,8 +1108,13 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
'%.1s'
%
"a
\
xe9
\
u20ac
"
,
'a'
)
self
.
assertEqual
(
'%.2s'
%
"a
\
xe9
\
u20ac
"
,
'a
\
xe9
'
)
@
support
.
cpython_only
def
test_formatting_huge_precision
(
self
):
format_string
=
"%.{}f"
.
format
(
sys
.
maxsize
+
1
)
with
self
.
assertRaises
(
ValueError
):
result
=
format_string
%
2.34
@
support
.
cpython_only
def
test_formatting_huge_precision_c_limits
(
self
):
from
_testcapi
import
INT_MAX
format_string
=
"%.{}f"
.
format
(
INT_MAX
+
1
)
with
self
.
assertRaises
(
ValueError
):
...
...
@@ -2090,6 +2095,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
PyUnicode_FromFormat
(
b'%.%s'
,
b'abc'
),
'%.%s'
)
# Test PyUnicode_AsWideChar()
@
support
.
cpython_only
def
test_aswidechar
(
self
):
from
_testcapi
import
unicode_aswidechar
support
.
import_module
(
'ctypes'
)
...
...
@@ -2127,6 +2133,7 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
wchar
,
nonbmp
+
'
\
0
'
)
# Test PyUnicode_AsWideCharString()
@
support
.
cpython_only
def
test_aswidecharstring
(
self
):
from
_testcapi
import
unicode_aswidecharstring
support
.
import_module
(
'ctypes'
)
...
...
@@ -2161,6 +2168,7 @@ class UnicodeTest(string_tests.CommonTest,
s
+=
"4"
self
.
assertEqual
(
s
,
"3"
)
@
support
.
cpython_only
def
test_encode_decimal
(
self
):
from
_testcapi
import
unicode_encodedecimal
self
.
assertEqual
(
unicode_encodedecimal
(
'123'
),
...
...
@@ -2176,6 +2184,7 @@ class UnicodeTest(string_tests.CommonTest,
"^'decimal' codec can't encode character"
,
unicode_encodedecimal
,
"123
\
u20ac
"
,
"replace"
)
@
support
.
cpython_only
def
test_transform_decimal
(
self
):
from
_testcapi
import
unicode_transformdecimaltoascii
as
transform_decimal
self
.
assertEqual
(
transform_decimal
(
'123'
),
...
...
Misc/NEWS
View file @
5cfc79de
...
...
@@ -324,6 +324,8 @@ IDLE
Tests
-----
- Issue #20532: Tests which use _testcapi are now marked as CPython only.
- Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok.
- Issue #19990: Added tests for the imghdr module. Based on patch by
...
...
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