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
79af7ea0
Commit
79af7ea0
authored
Mar 18, 2006
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for the C APIs PyCodec_IncrementalEncoder() and
PyCodec_IncrementalDecoder().
parent
bff3caac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
Lib/test/test_codecs.py
Lib/test/test_codecs.py
+14
-2
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+24
-0
No files found.
Lib/test/test_codecs.py
View file @
79af7ea0
from
test
import
test_support
from
test
import
test_support
import
unittest
import
unittest
import
codecs
import
codecs
import
sys
,
StringIO
import
sys
,
StringIO
,
_testcapi
class
Queue
(
object
):
class
Queue
(
object
):
"""
"""
...
@@ -1032,9 +1032,11 @@ class BasicUnicodeTest(unittest.TestCase):
...
@@ -1032,9 +1032,11 @@ class BasicUnicodeTest(unittest.TestCase):
decodedresult
+=
reader
.
read
()
decodedresult
+=
reader
.
read
()
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check incremental decoder/encoder and iterencode()/iterdecode()
# check incremental decoder/encoder (fetched via the Python
# and C API) and iterencode()/iterdecode()
try
:
try
:
encoder
=
codecs
.
getincrementalencoder
(
encoding
)()
encoder
=
codecs
.
getincrementalencoder
(
encoding
)()
cencoder
=
_testcapi
.
codec_incrementalencoder
(
encoding
)
except
LookupError
:
# no IncrementalEncoder
except
LookupError
:
# no IncrementalEncoder
pass
pass
else
:
else
:
...
@@ -1048,6 +1050,16 @@ class BasicUnicodeTest(unittest.TestCase):
...
@@ -1048,6 +1050,16 @@ class BasicUnicodeTest(unittest.TestCase):
decodedresult
+=
decoder
.
decode
(
c
)
decodedresult
+=
decoder
.
decode
(
c
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check C API
encodedresult
=
""
for
c
in
s
:
encodedresult
+=
cencoder
.
encode
(
c
)
cdecoder
=
_testcapi
.
codec_incrementaldecoder
(
encoding
)
decodedresult
=
u""
for
c
in
encodedresult
:
decodedresult
+=
cdecoder
.
decode
(
c
)
self
.
assertEqual
(
decodedresult
,
s
,
"%r != %r (encoding=%r)"
%
(
decodedresult
,
s
,
encoding
))
# check iterencode()/iterdecode()
# check iterencode()/iterdecode()
result
=
u""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
s
,
encoding
),
encoding
))
result
=
u""
.
join
(
codecs
.
iterdecode
(
codecs
.
iterencode
(
s
,
encoding
),
encoding
))
self
.
assertEqual
(
result
,
s
,
"%r != %r (encoding=%r)"
%
(
result
,
s
,
encoding
))
self
.
assertEqual
(
result
,
s
,
"%r != %r (encoding=%r)"
%
(
result
,
s
,
encoding
))
...
...
Modules/_testcapimodule.c
View file @
79af7ea0
...
@@ -478,6 +478,26 @@ test_u_code(PyObject *self)
...
@@ -478,6 +478,26 @@ test_u_code(PyObject *self)
return
Py_None
;
return
Py_None
;
}
}
static
PyObject
*
codec_incrementalencoder
(
PyObject
*
self
,
PyObject
*
args
)
{
const
char
*
encoding
,
*
errors
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s|s:test_incrementalencoder"
,
&
encoding
,
&
errors
))
return
NULL
;
return
PyCodec_IncrementalEncoder
(
encoding
,
errors
);
}
static
PyObject
*
codec_incrementaldecoder
(
PyObject
*
self
,
PyObject
*
args
)
{
const
char
*
encoding
,
*
errors
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s|s:test_incrementaldecoder"
,
&
encoding
,
&
errors
))
return
NULL
;
return
PyCodec_IncrementalDecoder
(
encoding
,
errors
);
}
#endif
#endif
/* Simple test of _PyLong_NumBits and _PyLong_Sign. */
/* Simple test of _PyLong_NumBits and _PyLong_Sign. */
...
@@ -623,6 +643,10 @@ static PyMethodDef TestMethods[] = {
...
@@ -623,6 +643,10 @@ static PyMethodDef TestMethods[] = {
{
"getargs_K"
,
(
PyCFunction
)
getargs_K
,
METH_VARARGS
},
{
"getargs_K"
,
(
PyCFunction
)
getargs_K
,
METH_VARARGS
},
{
"test_longlong_api"
,
(
PyCFunction
)
test_longlong_api
,
METH_NOARGS
},
{
"test_longlong_api"
,
(
PyCFunction
)
test_longlong_api
,
METH_NOARGS
},
{
"test_L_code"
,
(
PyCFunction
)
test_L_code
,
METH_NOARGS
},
{
"test_L_code"
,
(
PyCFunction
)
test_L_code
,
METH_NOARGS
},
{
"codec_incrementalencoder"
,
(
PyCFunction
)
codec_incrementalencoder
,
METH_VARARGS
},
{
"codec_incrementaldecoder"
,
(
PyCFunction
)
codec_incrementaldecoder
,
METH_VARARGS
},
#endif
#endif
#ifdef Py_USING_UNICODE
#ifdef Py_USING_UNICODE
{
"test_u_code"
,
(
PyCFunction
)
test_u_code
,
METH_NOARGS
},
{
"test_u_code"
,
(
PyCFunction
)
test_u_code
,
METH_NOARGS
},
...
...
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