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
c6a7c96a
Commit
c6a7c96a
authored
May 16, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backported tests for issue #18531.
parent
6904ca3a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
Lib/test/test_getargs2.py
Lib/test/test_getargs2.py
+56
-0
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+22
-0
No files found.
Lib/test/test_getargs2.py
View file @
c6a7c96a
...
@@ -64,6 +64,12 @@ class Int:
...
@@ -64,6 +64,12 @@ class Int:
def
__int__
(
self
):
def
__int__
(
self
):
return
99
return
99
class
TupleSubclass
(
tuple
):
pass
class
DictSubclass
(
dict
):
pass
class
Unsigned_TestCase
(
unittest
.
TestCase
):
class
Unsigned_TestCase
(
unittest
.
TestCase
):
def
test_b
(
self
):
def
test_b
(
self
):
from
_testcapi
import
getargs_b
from
_testcapi
import
getargs_b
...
@@ -268,6 +274,33 @@ class LongLong_TestCase(unittest.TestCase):
...
@@ -268,6 +274,33 @@ class LongLong_TestCase(unittest.TestCase):
class
Tuple_TestCase
(
unittest
.
TestCase
):
class
Tuple_TestCase
(
unittest
.
TestCase
):
def
test_args
(
self
):
from
_testcapi
import
get_args
ret
=
get_args
(
1
,
2
)
self
.
assertEqual
(
ret
,
(
1
,
2
))
self
.
assertIs
(
type
(
ret
),
tuple
)
ret
=
get_args
(
1
,
*
(
2
,
3
))
self
.
assertEqual
(
ret
,
(
1
,
2
,
3
))
self
.
assertIs
(
type
(
ret
),
tuple
)
ret
=
get_args
(
*
[
1
,
2
])
self
.
assertEqual
(
ret
,
(
1
,
2
))
self
.
assertIs
(
type
(
ret
),
tuple
)
ret
=
get_args
(
*
TupleSubclass
([
1
,
2
]))
self
.
assertEqual
(
ret
,
(
1
,
2
))
self
.
assertIsInstance
(
ret
,
tuple
)
ret
=
get_args
()
self
.
assertIn
(
ret
,
((),
None
))
self
.
assertIn
(
type
(
ret
),
(
tuple
,
type
(
None
)))
ret
=
get_args
(
*
())
self
.
assertIn
(
ret
,
((),
None
))
self
.
assertIn
(
type
(
ret
),
(
tuple
,
type
(
None
)))
def
test_tuple
(
self
):
def
test_tuple
(
self
):
from
_testcapi
import
getargs_tuple
from
_testcapi
import
getargs_tuple
...
@@ -283,6 +316,29 @@ class Tuple_TestCase(unittest.TestCase):
...
@@ -283,6 +316,29 @@ class Tuple_TestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
getargs_tuple
,
1
,
seq
())
self
.
assertRaises
(
TypeError
,
getargs_tuple
,
1
,
seq
())
class
Keywords_TestCase
(
unittest
.
TestCase
):
class
Keywords_TestCase
(
unittest
.
TestCase
):
def
test_kwargs
(
self
):
from
_testcapi
import
get_kwargs
ret
=
get_kwargs
(
a
=
1
,
b
=
2
)
self
.
assertEqual
(
ret
,
{
'a'
:
1
,
'b'
:
2
})
self
.
assertIs
(
type
(
ret
),
dict
)
ret
=
get_kwargs
(
a
=
1
,
**
{
'b'
:
2
,
'c'
:
3
})
self
.
assertEqual
(
ret
,
{
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
self
.
assertIs
(
type
(
ret
),
dict
)
ret
=
get_kwargs
(
**
DictSubclass
({
'a'
:
1
,
'b'
:
2
}))
self
.
assertEqual
(
ret
,
{
'a'
:
1
,
'b'
:
2
})
self
.
assertIsInstance
(
ret
,
dict
)
ret
=
get_kwargs
()
self
.
assertIn
(
ret
,
({},
None
))
self
.
assertIn
(
type
(
ret
),
(
dict
,
type
(
None
)))
ret
=
get_kwargs
(
**
{})
self
.
assertIn
(
ret
,
({},
None
))
self
.
assertIn
(
type
(
ret
),
(
dict
,
type
(
None
)))
def
test_positional_args
(
self
):
def
test_positional_args
(
self
):
# using all positional args
# using all positional args
self
.
assertEqual
(
self
.
assertEqual
(
...
...
Modules/_testcapimodule.c
View file @
c6a7c96a
...
@@ -930,6 +930,26 @@ test_L_code(PyObject *self)
...
@@ -930,6 +930,26 @@ test_L_code(PyObject *self)
#endif
/* ifdef HAVE_LONG_LONG */
#endif
/* ifdef HAVE_LONG_LONG */
static
PyObject
*
get_args
(
PyObject
*
self
,
PyObject
*
args
)
{
if
(
args
==
NULL
)
{
args
=
Py_None
;
}
Py_INCREF
(
args
);
return
args
;
}
static
PyObject
*
get_kwargs
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwargs
)
{
if
(
kwargs
==
NULL
)
{
kwargs
=
Py_None
;
}
Py_INCREF
(
kwargs
);
return
kwargs
;
}
/* Test tuple argument processing */
/* Test tuple argument processing */
static
PyObject
*
static
PyObject
*
getargs_tuple
(
PyObject
*
self
,
PyObject
*
args
)
getargs_tuple
(
PyObject
*
self
,
PyObject
*
args
)
...
@@ -2335,6 +2355,8 @@ static PyMethodDef TestMethods[] = {
...
@@ -2335,6 +2355,8 @@ static PyMethodDef TestMethods[] = {
{
"test_with_docstring"
,
(
PyCFunction
)
test_with_docstring
,
METH_NOARGS
,
{
"test_with_docstring"
,
(
PyCFunction
)
test_with_docstring
,
METH_NOARGS
,
PyDoc_STR
(
"This is a pretty normal docstring."
)},
PyDoc_STR
(
"This is a pretty normal docstring."
)},
{
"get_args"
,
get_args
,
METH_VARARGS
},
{
"get_kwargs"
,
(
PyCFunction
)
get_kwargs
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"getargs_tuple"
,
getargs_tuple
,
METH_VARARGS
},
{
"getargs_tuple"
,
getargs_tuple
,
METH_VARARGS
},
{
"getargs_keywords"
,
(
PyCFunction
)
getargs_keywords
,
{
"getargs_keywords"
,
(
PyCFunction
)
getargs_keywords
,
METH_VARARGS
|
METH_KEYWORDS
},
METH_VARARGS
|
METH_KEYWORDS
},
...
...
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