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
70ef1c79
Commit
70ef1c79
authored
Jun 18, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"Fix" the array module test -- by ripping out the 'c' typecode.
(We already have 'b' for bytes and 'u' for unicode.)
parent
cdedee82
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
67 deletions
+6
-67
Lib/test/test_array.py
Lib/test/test_array.py
+2
-40
Modules/arraymodule.c
Modules/arraymodule.c
+4
-27
No files found.
Lib/test/test_array.py
View file @
70ef1c79
...
...
@@ -17,7 +17,7 @@ class ArraySubclassWithKwargs(array.array):
array
.
array
.
__init__
(
typecode
)
tests
=
[]
# list to accumulate all tests
typecodes
=
"
c
ubBhHiIlLfd"
typecodes
=
"ubBhHiIlLfd"
class
BadConstructorTest
(
unittest
.
TestCase
):
...
...
@@ -676,7 +676,7 @@ class BaseTest(unittest.TestCase):
def
test_buffer
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
b
=
b
uffer
(
a
)
b
=
b
ytes
(
buffer
(
a
)
)
self
.
assertEqual
(
b
[
0
],
a
.
tostring
()[
0
])
def
test_weakref
(
self
):
...
...
@@ -708,44 +708,6 @@ class StringTest(BaseTest):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
self
.
assertRaises
(
TypeError
,
a
.
__setitem__
,
0
,
self
.
example
[:
2
])
class
CharacterTest
(
StringTest
):
typecode
=
'c'
example
=
'
\
x01
azAZ
\
x00
\
xfe
'
smallerexample
=
'
\
x01
azAY
\
x00
\
xfe
'
biggerexample
=
'
\
x01
azAZ
\
x00
\
xff
'
outside
=
'
\
x33
'
minitemsize
=
1
def
test_subbclassing
(
self
):
class
EditableString
(
array
.
array
):
def
__new__
(
cls
,
s
,
*
args
,
**
kwargs
):
return
array
.
array
.
__new__
(
cls
,
'c'
,
s
)
def
__init__
(
self
,
s
,
color
=
'blue'
):
self
.
color
=
color
def
strip
(
self
):
self
[:]
=
array
.
array
(
'c'
,
self
.
tostring
().
strip
())
def
__repr__
(
self
):
return
'EditableString(%r)'
%
self
.
tostring
()
s
=
EditableString
(
"
\
t
test
\
r
\
n
"
)
s
.
strip
()
self
.
assertEqual
(
s
.
tostring
(),
"test"
)
self
.
assertEqual
(
s
.
color
,
"blue"
)
s
.
color
=
"red"
self
.
assertEqual
(
s
.
color
,
"red"
)
self
.
assertEqual
(
list
(
s
.
__dict__
.
keys
()),
[
"color"
])
def
test_nounicode
(
self
):
a
=
array
.
array
(
self
.
typecode
,
self
.
example
)
self
.
assertRaises
(
ValueError
,
a
.
fromunicode
,
str
(
''
))
self
.
assertRaises
(
ValueError
,
a
.
tounicode
)
tests
.
append
(
CharacterTest
)
class
UnicodeTest
(
StringTest
):
typecode
=
'u'
example
=
'
\
x01
\
u263a
\
x00
\
ufeff
'
...
...
Modules/arraymodule.c
View file @
70ef1c79
...
...
@@ -101,25 +101,6 @@ Note that the basic Get and Set functions do NOT check that the index is
in bounds; that's the responsibility of the caller.
****************************************************************************/
static
PyObject
*
c_getitem
(
arrayobject
*
ap
,
Py_ssize_t
i
)
{
Py_UNICODE
buf
[
1
];
buf
[
0
]
=
((
unsigned
char
*
)
ap
->
ob_item
)[
i
];
return
PyUnicode_FromUnicode
(
buf
,
1
);
}
static
int
c_setitem
(
arrayobject
*
ap
,
Py_ssize_t
i
,
PyObject
*
v
)
{
char
x
;
if
(
!
PyArg_Parse
(
v
,
"c;array item must be char"
,
&
x
))
return
-
1
;
if
(
i
>=
0
)
((
char
*
)
ap
->
ob_item
)[
i
]
=
x
;
return
0
;
}
static
PyObject
*
b_getitem
(
arrayobject
*
ap
,
Py_ssize_t
i
)
{
...
...
@@ -391,7 +372,6 @@ d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
/* Description of types */
static
struct
arraydescr
descriptors
[]
=
{
{
'c'
,
sizeof
(
char
),
c_getitem
,
c_setitem
},
{
'b'
,
sizeof
(
char
),
b_getitem
,
b_setitem
},
{
'B'
,
sizeof
(
char
),
BB_getitem
,
BB_setitem
},
{
'u'
,
sizeof
(
Py_UNICODE
),
u_getitem
,
u_setitem
},
...
...
@@ -1403,8 +1383,8 @@ values,as if it had been read from a file using the fromfile() method).");
static
PyObject
*
array_tostring
(
arrayobject
*
self
,
PyObject
*
unused
)
{
return
Py
String
_FromStringAndSize
(
self
->
ob_item
,
self
->
ob_size
*
self
->
ob_descr
->
itemsize
);
return
Py
Bytes
_FromStringAndSize
(
self
->
ob_item
,
self
->
ob_size
*
self
->
ob_descr
->
itemsize
);
}
PyDoc_STRVAR
(
tostring_doc
,
...
...
@@ -1562,9 +1542,7 @@ array_repr(arrayobject *a)
if
(
len
==
0
)
{
return
PyUnicode_FromFormat
(
"array('%c')"
,
typecode
);
}
if
(
typecode
==
'c'
)
v
=
array_tostring
(
a
,
NULL
);
else
if
(
typecode
==
'u'
)
if
(
typecode
==
'u'
)
v
=
array_tounicode
(
a
,
NULL
);
else
v
=
array_tolist
(
a
,
NULL
);
...
...
@@ -1899,7 +1877,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
PyErr_SetString
(
PyExc_ValueError
,
"bad typecode (must be
c,
b, B, u, h, H, i, I, l, L, f or d)"
);
"bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)"
);
return
NULL
;
}
...
...
@@ -1913,7 +1891,6 @@ type is specified at object creation time by using a type code, which\n\
is a single character. The following type codes are defined:
\n
\
\n
\
Type code C Type Minimum size in bytes
\n
\
'c' character 1
\n
\
'b' signed integer 1
\n
\
'B' unsigned integer 1
\n
\
'u' Unicode character 2
\n
\
...
...
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