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
b5e348b3
Commit
b5e348b3
authored
Dec 20, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing tests for PyArg_Parse* with format 'h'
parent
1c2353b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+18
-1
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+10
-0
No files found.
Lib/test/test_getargs2.py
View file @
b5e348b3
...
...
@@ -48,7 +48,8 @@ LARGE = 0x7FFFFFFF
VERY_LARGE
=
0xFF0000121212121212121242
L
from
_testcapi
import
UCHAR_MAX
,
USHRT_MAX
,
UINT_MAX
,
ULONG_MAX
,
INT_MAX
,
\
INT_MIN
,
LONG_MIN
,
LONG_MAX
,
PY_SSIZE_T_MIN
,
PY_SSIZE_T_MAX
INT_MIN
,
LONG_MIN
,
LONG_MAX
,
PY_SSIZE_T_MIN
,
PY_SSIZE_T_MAX
,
\
SHRT_MIN
,
SHRT_MAX
# fake, they are not defined in Python's header files
LLONG_MAX
=
2
**
63
-
1
...
...
@@ -150,6 +151,22 @@ class Unsigned_TestCase(unittest.TestCase):
self
.
assertEqual
(
VERY_LARGE
&
ULONG_MAX
,
getargs_k
(
VERY_LARGE
))
class
Signed_TestCase
(
unittest
.
TestCase
):
def
test_h
(
self
):
from
_testcapi
import
getargs_h
# h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
self
.
assertEqual
(
3
,
getargs_h
(
3.14
))
self
.
assertEqual
(
99
,
getargs_h
(
Long
()))
self
.
assertEqual
(
99
,
getargs_h
(
Int
()))
self
.
assertRaises
(
OverflowError
,
getargs_h
,
SHRT_MIN
-
1
)
self
.
assertEqual
(
SHRT_MIN
,
getargs_h
(
SHRT_MIN
))
self
.
assertEqual
(
SHRT_MAX
,
getargs_h
(
SHRT_MAX
))
self
.
assertRaises
(
OverflowError
,
getargs_h
,
SHRT_MAX
+
1
)
self
.
assertEqual
(
42
,
getargs_h
(
42
))
self
.
assertEqual
(
42
,
getargs_h
(
42L
))
self
.
assertRaises
(
OverflowError
,
getargs_h
,
VERY_LARGE
)
def
test_i
(
self
):
from
_testcapi
import
getargs_i
# i returns 'int', and does range checking (INT_MIN ... INT_MAX)
...
...
Modules/_testcapimodule.c
View file @
b5e348b3
...
...
@@ -453,6 +453,15 @@ getargs_B(PyObject *self, PyObject *args)
return
PyLong_FromUnsignedLong
((
unsigned
long
)
value
);
}
static
PyObject
*
getargs_h
(
PyObject
*
self
,
PyObject
*
args
)
{
short
value
;
if
(
!
PyArg_ParseTuple
(
args
,
"h"
,
&
value
))
return
NULL
;
return
PyLong_FromLong
((
long
)
value
);
}
static
PyObject
*
getargs_H
(
PyObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -1045,6 +1054,7 @@ static PyMethodDef TestMethods[] = {
METH_VARARGS
|
METH_KEYWORDS
},
{
"getargs_b"
,
getargs_b
,
METH_VARARGS
},
{
"getargs_B"
,
getargs_B
,
METH_VARARGS
},
{
"getargs_h"
,
getargs_h
,
METH_VARARGS
},
{
"getargs_H"
,
getargs_H
,
METH_VARARGS
},
{
"getargs_I"
,
getargs_I
,
METH_VARARGS
},
{
"getargs_k"
,
getargs_k
,
METH_VARARGS
},
...
...
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