Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8f203dda
Kaydet (Commit)
8f203dda
authored
Kas 16, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #19591: Use specific asserts in ctype tests.
üst
745d54d2
7c5e24f9
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
84 additions
and
85 deletions
+84
-85
test_arrays.py
Lib/ctypes/test/test_arrays.py
+3
-3
test_as_parameter.py
Lib/ctypes/test/test_as_parameter.py
+1
-1
test_buffers.py
Lib/ctypes/test/test_buffers.py
+5
-5
test_byteswap.py
Lib/ctypes/test/test_byteswap.py
+26
-26
test_cast.py
Lib/ctypes/test/test_cast.py
+3
-3
test_frombuffer.py
Lib/ctypes/test/test_frombuffer.py
+1
-1
test_funcptr.py
Lib/ctypes/test/test_funcptr.py
+1
-1
test_functions.py
Lib/ctypes/test/test_functions.py
+1
-1
test_loading.py
Lib/ctypes/test/test_loading.py
+1
-1
test_numbers.py
Lib/ctypes/test/test_numbers.py
+3
-3
test_parameters.py
Lib/ctypes/test/test_parameters.py
+2
-2
test_pointers.py
Lib/ctypes/test/test_pointers.py
+4
-4
test_python_api.py
Lib/ctypes/test/test_python_api.py
+1
-1
test_refcounts.py
Lib/ctypes/test/test_refcounts.py
+7
-7
test_strings.py
Lib/ctypes/test/test_strings.py
+19
-19
test_structures.py
Lib/ctypes/test/test_structures.py
+6
-7
No files found.
Lib/ctypes/test/test_arrays.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -84,8 +84,8 @@ class ArrayTestCase(unittest.TestCase):
self
.
assertEqual
(
values
,
[
1
,
2
,
3
,
4
,
5
])
def
test_classcache
(
self
):
self
.
assert
True
(
not
ARRAY
(
c_int
,
3
)
is
ARRAY
(
c_int
,
4
))
self
.
assert
True
(
ARRAY
(
c_int
,
3
)
is
ARRAY
(
c_int
,
3
))
self
.
assert
IsNot
(
ARRAY
(
c_int
,
3
),
ARRAY
(
c_int
,
4
))
self
.
assert
Is
(
ARRAY
(
c_int
,
3
),
ARRAY
(
c_int
,
3
))
def
test_from_address
(
self
):
# Failed with 0.9.8, reported by JUrner
...
...
@@ -125,7 +125,7 @@ class ArrayTestCase(unittest.TestCase):
# Create a new array type based on it:
t1
=
my_int
*
1
t2
=
my_int
*
1
self
.
assert
True
(
t1
is
t2
)
self
.
assert
Is
(
t1
,
t2
)
def
test_subclass
(
self
):
class
T
(
Array
):
...
...
Lib/ctypes/test/test_as_parameter.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -134,7 +134,7 @@ class BasicWrapTestCase(unittest.TestCase):
f
.
argtypes
=
[
c_longlong
,
MyCallback
]
def
callback
(
value
):
self
.
assert
True
(
isinstance
(
value
,
int
)
)
self
.
assert
IsInstance
(
value
,
int
)
return
value
&
0x7FFFFFFF
cb
=
MyCallback
(
callback
)
...
...
Lib/ctypes/test/test_buffers.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -7,12 +7,12 @@ class StringBufferTestCase(unittest.TestCase):
b
=
create_string_buffer
(
32
)
self
.
assertEqual
(
len
(
b
),
32
)
self
.
assertEqual
(
sizeof
(
b
),
32
*
sizeof
(
c_char
))
self
.
assert
True
(
type
(
b
[
0
])
is
bytes
)
self
.
assert
Is
(
type
(
b
[
0
]),
bytes
)
b
=
create_string_buffer
(
b
"abc"
)
self
.
assertEqual
(
len
(
b
),
4
)
# trailing nul char
self
.
assertEqual
(
sizeof
(
b
),
4
*
sizeof
(
c_char
))
self
.
assert
True
(
type
(
b
[
0
])
is
bytes
)
self
.
assert
Is
(
type
(
b
[
0
]),
bytes
)
self
.
assertEqual
(
b
[
0
],
b
"a"
)
self
.
assertEqual
(
b
[:],
b
"abc
\0
"
)
self
.
assertEqual
(
b
[::],
b
"abc
\0
"
)
...
...
@@ -33,12 +33,12 @@ class StringBufferTestCase(unittest.TestCase):
b
=
create_unicode_buffer
(
32
)
self
.
assertEqual
(
len
(
b
),
32
)
self
.
assertEqual
(
sizeof
(
b
),
32
*
sizeof
(
c_wchar
))
self
.
assert
True
(
type
(
b
[
0
])
is
str
)
self
.
assert
Is
(
type
(
b
[
0
]),
str
)
b
=
create_unicode_buffer
(
"abc"
)
self
.
assertEqual
(
len
(
b
),
4
)
# trailing nul char
self
.
assertEqual
(
sizeof
(
b
),
4
*
sizeof
(
c_wchar
))
self
.
assert
True
(
type
(
b
[
0
])
is
str
)
self
.
assert
Is
(
type
(
b
[
0
]),
str
)
self
.
assertEqual
(
b
[
0
],
"a"
)
self
.
assertEqual
(
b
[:],
"abc
\0
"
)
self
.
assertEqual
(
b
[::],
"abc
\0
"
)
...
...
@@ -50,7 +50,7 @@ class StringBufferTestCase(unittest.TestCase):
b
=
create_unicode_buffer
(
"abc"
)
self
.
assertEqual
(
len
(
b
),
4
)
# trailing nul char
self
.
assertEqual
(
sizeof
(
b
),
4
*
sizeof
(
c_wchar
))
self
.
assert
True
(
type
(
b
[
0
])
is
str
)
self
.
assert
Is
(
type
(
b
[
0
]),
str
)
self
.
assertEqual
(
b
[
0
],
"a"
)
self
.
assertEqual
(
b
[:],
"abc
\0
"
)
self
.
assertEqual
(
b
[::],
"abc
\0
"
)
...
...
Lib/ctypes/test/test_byteswap.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -23,11 +23,11 @@ class Test(unittest.TestCase):
def
test_endian_short
(
self
):
if
sys
.
byteorder
==
"little"
:
self
.
assert
True
(
c_short
.
__ctype_le__
is
c_short
)
self
.
assert
True
(
c_short
.
__ctype_be__
.
__ctype_le__
is
c_short
)
self
.
assert
Is
(
c_short
.
__ctype_le__
,
c_short
)
self
.
assert
Is
(
c_short
.
__ctype_be__
.
__ctype_le__
,
c_short
)
else
:
self
.
assert
True
(
c_short
.
__ctype_be__
is
c_short
)
self
.
assert
True
(
c_short
.
__ctype_le__
.
__ctype_be__
is
c_short
)
self
.
assert
Is
(
c_short
.
__ctype_be__
,
c_short
)
self
.
assert
Is
(
c_short
.
__ctype_le__
.
__ctype_be__
,
c_short
)
s
=
c_short
.
__ctype_be__
(
0x1234
)
self
.
assertEqual
(
bin
(
struct
.
pack
(
">h"
,
0x1234
)),
"1234"
)
self
.
assertEqual
(
bin
(
s
),
"1234"
)
...
...
@@ -50,11 +50,11 @@ class Test(unittest.TestCase):
def
test_endian_int
(
self
):
if
sys
.
byteorder
==
"little"
:
self
.
assert
True
(
c_int
.
__ctype_le__
is
c_int
)
self
.
assert
True
(
c_int
.
__ctype_be__
.
__ctype_le__
is
c_int
)
self
.
assert
Is
(
c_int
.
__ctype_le__
,
c_int
)
self
.
assert
Is
(
c_int
.
__ctype_be__
.
__ctype_le__
,
c_int
)
else
:
self
.
assert
True
(
c_int
.
__ctype_be__
is
c_int
)
self
.
assert
True
(
c_int
.
__ctype_le__
.
__ctype_be__
is
c_int
)
self
.
assert
Is
(
c_int
.
__ctype_be__
,
c_int
)
self
.
assert
Is
(
c_int
.
__ctype_le__
.
__ctype_be__
,
c_int
)
s
=
c_int
.
__ctype_be__
(
0x12345678
)
self
.
assertEqual
(
bin
(
struct
.
pack
(
">i"
,
0x12345678
)),
"12345678"
)
...
...
@@ -78,11 +78,11 @@ class Test(unittest.TestCase):
def
test_endian_longlong
(
self
):
if
sys
.
byteorder
==
"little"
:
self
.
assert
True
(
c_longlong
.
__ctype_le__
is
c_longlong
)
self
.
assert
True
(
c_longlong
.
__ctype_be__
.
__ctype_le__
is
c_longlong
)
self
.
assert
Is
(
c_longlong
.
__ctype_le__
,
c_longlong
)
self
.
assert
Is
(
c_longlong
.
__ctype_be__
.
__ctype_le__
,
c_longlong
)
else
:
self
.
assert
True
(
c_longlong
.
__ctype_be__
is
c_longlong
)
self
.
assert
True
(
c_longlong
.
__ctype_le__
.
__ctype_be__
is
c_longlong
)
self
.
assert
Is
(
c_longlong
.
__ctype_be__
,
c_longlong
)
self
.
assert
Is
(
c_longlong
.
__ctype_le__
.
__ctype_be__
,
c_longlong
)
s
=
c_longlong
.
__ctype_be__
(
0x1234567890ABCDEF
)
self
.
assertEqual
(
bin
(
struct
.
pack
(
">q"
,
0x1234567890ABCDEF
)),
"1234567890ABCDEF"
)
...
...
@@ -106,11 +106,11 @@ class Test(unittest.TestCase):
def
test_endian_float
(
self
):
if
sys
.
byteorder
==
"little"
:
self
.
assert
True
(
c_float
.
__ctype_le__
is
c_float
)
self
.
assert
True
(
c_float
.
__ctype_be__
.
__ctype_le__
is
c_float
)
self
.
assert
Is
(
c_float
.
__ctype_le__
,
c_float
)
self
.
assert
Is
(
c_float
.
__ctype_be__
.
__ctype_le__
,
c_float
)
else
:
self
.
assert
True
(
c_float
.
__ctype_be__
is
c_float
)
self
.
assert
True
(
c_float
.
__ctype_le__
.
__ctype_be__
is
c_float
)
self
.
assert
Is
(
c_float
.
__ctype_be__
,
c_float
)
self
.
assert
Is
(
c_float
.
__ctype_le__
.
__ctype_be__
,
c_float
)
s
=
c_float
(
math
.
pi
)
self
.
assertEqual
(
bin
(
struct
.
pack
(
"f"
,
math
.
pi
)),
bin
(
s
))
# Hm, what's the precision of a float compared to a double?
...
...
@@ -124,11 +124,11 @@ class Test(unittest.TestCase):
def
test_endian_double
(
self
):
if
sys
.
byteorder
==
"little"
:
self
.
assert
True
(
c_double
.
__ctype_le__
is
c_double
)
self
.
assert
True
(
c_double
.
__ctype_be__
.
__ctype_le__
is
c_double
)
self
.
assert
Is
(
c_double
.
__ctype_le__
,
c_double
)
self
.
assert
Is
(
c_double
.
__ctype_be__
.
__ctype_le__
,
c_double
)
else
:
self
.
assert
True
(
c_double
.
__ctype_be__
is
c_double
)
self
.
assert
True
(
c_double
.
__ctype_le__
.
__ctype_be__
is
c_double
)
self
.
assert
Is
(
c_double
.
__ctype_be__
,
c_double
)
self
.
assert
Is
(
c_double
.
__ctype_le__
.
__ctype_be__
,
c_double
)
s
=
c_double
(
math
.
pi
)
self
.
assertEqual
(
s
.
value
,
math
.
pi
)
self
.
assertEqual
(
bin
(
struct
.
pack
(
"d"
,
math
.
pi
)),
bin
(
s
))
...
...
@@ -140,14 +140,14 @@ class Test(unittest.TestCase):
self
.
assertEqual
(
bin
(
struct
.
pack
(
">d"
,
math
.
pi
)),
bin
(
s
))
def
test_endian_other
(
self
):
self
.
assert
True
(
c_byte
.
__ctype_le__
is
c_byte
)
self
.
assert
True
(
c_byte
.
__ctype_be__
is
c_byte
)
self
.
assert
Is
(
c_byte
.
__ctype_le__
,
c_byte
)
self
.
assert
Is
(
c_byte
.
__ctype_be__
,
c_byte
)
self
.
assert
True
(
c_ubyte
.
__ctype_le__
is
c_ubyte
)
self
.
assert
True
(
c_ubyte
.
__ctype_be__
is
c_ubyte
)
self
.
assert
Is
(
c_ubyte
.
__ctype_le__
,
c_ubyte
)
self
.
assert
Is
(
c_ubyte
.
__ctype_be__
,
c_ubyte
)
self
.
assert
True
(
c_char
.
__ctype_le__
is
c_char
)
self
.
assert
True
(
c_char
.
__ctype_be__
is
c_char
)
self
.
assert
Is
(
c_char
.
__ctype_le__
,
c_char
)
self
.
assert
Is
(
c_char
.
__ctype_be__
,
c_char
)
def
test_struct_fields_1
(
self
):
if
sys
.
byteorder
==
"little"
:
...
...
Lib/ctypes/test/test_cast.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -38,14 +38,14 @@ class Test(unittest.TestCase):
p
=
cast
(
array
,
POINTER
(
c_char_p
))
# array and p share a common _objects attribute
self
.
assert
True
(
p
.
_objects
is
array
.
_objects
)
self
.
assert
Is
(
p
.
_objects
,
array
.
_objects
)
self
.
assertEqual
(
array
.
_objects
,
{
'0'
:
b
"foo bar"
,
id
(
array
):
array
})
p
[
0
]
=
b
"spam spam"
self
.
assertEqual
(
p
.
_objects
,
{
'0'
:
b
"spam spam"
,
id
(
array
):
array
})
self
.
assert
True
(
array
.
_objects
is
p
.
_objects
)
self
.
assert
Is
(
array
.
_objects
,
p
.
_objects
)
p
[
1
]
=
b
"foo bar"
self
.
assertEqual
(
p
.
_objects
,
{
'1'
:
b
'foo bar'
,
'0'
:
b
"spam spam"
,
id
(
array
):
array
})
self
.
assert
True
(
array
.
_objects
is
p
.
_objects
)
self
.
assert
Is
(
array
.
_objects
,
p
.
_objects
)
def
test_other
(
self
):
p
=
cast
((
c_int
*
4
)(
1
,
2
,
3
,
4
),
POINTER
(
c_int
))
...
...
Lib/ctypes/test/test_frombuffer.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -23,7 +23,7 @@ class Test(unittest.TestCase):
a
[
0
],
a
[
-
1
]
=
200
,
-
200
self
.
assertEqual
(
x
[:],
a
.
tolist
())
self
.
assert
True
(
a
in
x
.
_objects
.
values
())
self
.
assert
In
(
a
,
x
.
_objects
.
values
())
self
.
assertRaises
(
ValueError
,
c_int
.
from_buffer
,
a
,
-
1
)
...
...
Lib/ctypes/test/test_funcptr.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -75,7 +75,7 @@ class CFuncPtrTestCase(unittest.TestCase):
## "lpfnWndProc", WNDPROC_2(wndproc))
# instead:
self
.
assert
True
(
WNDPROC
is
WNDPROC_2
)
self
.
assert
Is
(
WNDPROC
,
WNDPROC_2
)
# 'wndclass.lpfnWndProc' leaks 94 references. Why?
self
.
assertEqual
(
wndclass
.
lpfnWndProc
(
1
,
2
,
3
,
4
),
10
)
...
...
Lib/ctypes/test/test_functions.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -306,7 +306,7 @@ class FunctionTestCase(unittest.TestCase):
f
.
argtypes
=
[
c_longlong
,
MyCallback
]
def
callback
(
value
):
self
.
assert
True
(
isinstance
(
value
,
int
)
)
self
.
assert
IsInstance
(
value
,
int
)
return
value
&
0x7FFFFFFF
cb
=
MyCallback
(
callback
)
...
...
Lib/ctypes/test/test_loading.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -43,7 +43,7 @@ class LoaderTest(unittest.TestCase):
if
os
.
name
in
(
"nt"
,
"ce"
):
def
test_load_library
(
self
):
self
.
assert
False
(
libc_name
is
Non
e
)
self
.
assert
IsNotNone
(
libc_nam
e
)
if
is_resource_enabled
(
"printing"
):
print
(
find_library
(
"kernel32"
))
print
(
find_library
(
"user32"
))
...
...
Lib/ctypes/test/test_numbers.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -181,10 +181,10 @@ class NumberTestCase(unittest.TestCase):
a
=
array
(
t
.
_type_
,
[
3.14
])
v
=
t
.
from_address
(
a
.
buffer_info
()[
0
])
self
.
assertEqual
(
v
.
value
,
a
[
0
])
self
.
assert
True
(
type
(
v
)
is
t
)
self
.
assert
Is
(
type
(
v
),
t
)
a
[
0
]
=
2.3456e17
self
.
assertEqual
(
v
.
value
,
a
[
0
])
self
.
assert
True
(
type
(
v
)
is
t
)
self
.
assert
Is
(
type
(
v
),
t
)
def
test_char_from_address
(
self
):
from
ctypes
import
c_char
...
...
@@ -194,7 +194,7 @@ class NumberTestCase(unittest.TestCase):
a
[
0
]
=
ord
(
'x'
)
v
=
c_char
.
from_address
(
a
.
buffer_info
()[
0
])
self
.
assertEqual
(
v
.
value
,
b
'x'
)
self
.
assert
True
(
type
(
v
)
is
c_char
)
self
.
assert
Is
(
type
(
v
),
c_char
)
a
[
0
]
=
ord
(
'?'
)
self
.
assertEqual
(
v
.
value
,
b
'?'
)
...
...
Lib/ctypes/test/test_parameters.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -54,7 +54,7 @@ class SimpleTypesTestCase(unittest.TestCase):
# c_char_p.from_param on a Python String packs the string
# into a cparam object
s
=
b
"123"
self
.
assert
True
(
c_char_p
.
from_param
(
s
)
.
_obj
is
s
)
self
.
assert
Is
(
c_char_p
.
from_param
(
s
)
.
_obj
,
s
)
# new in 0.9.1: convert (encode) unicode to ascii
self
.
assertEqual
(
c_char_p
.
from_param
(
b
"123"
)
.
_obj
,
b
"123"
)
...
...
@@ -64,7 +64,7 @@ class SimpleTypesTestCase(unittest.TestCase):
# calling c_char_p.from_param with a c_char_p instance
# returns the argument itself:
a
=
c_char_p
(
b
"123"
)
self
.
assert
True
(
c_char_p
.
from_param
(
a
)
is
a
)
self
.
assert
Is
(
c_char_p
.
from_param
(
a
),
a
)
def
test_cw_strings
(
self
):
from
ctypes
import
byref
...
...
Lib/ctypes/test/test_pointers.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -78,7 +78,7 @@ class PointersTestCase(unittest.TestCase):
## i = c_int(42)
## callback(byref(i))
## self.assert
True(i.value ==
84)
## self.assert
Equal(i.value,
84)
doit
(
callback
)
## print self.result
...
...
@@ -91,11 +91,11 @@ class PointersTestCase(unittest.TestCase):
i
=
ct
(
42
)
p
=
pointer
(
i
)
## print type(p.contents), ct
self
.
assert
True
(
type
(
p
.
contents
)
is
ct
)
self
.
assert
Is
(
type
(
p
.
contents
),
ct
)
# p.contents is the same as p[0]
## print p.contents
## self.assert
True(p.contents ==
42)
## self.assert
True(p[0] ==
42)
## self.assert
Equal(p.contents,
42)
## self.assert
Equal(p[0],
42)
self
.
assertRaises
(
TypeError
,
delitem
,
p
,
0
)
...
...
Lib/ctypes/test/test_python_api.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -64,7 +64,7 @@ class PythonAPITestCase(unittest.TestCase):
ref
=
grc
(
s
)
# id(python-object) is the address
pyobj
=
PyObj_FromPtr
(
id
(
s
))
self
.
assert
True
(
s
is
pyobj
)
self
.
assert
Is
(
s
,
pyobj
)
self
.
assertEqual
(
grc
(
s
),
ref
+
1
)
del
pyobj
...
...
Lib/ctypes/test/test_refcounts.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -26,7 +26,7 @@ class RefcountTestCase(unittest.TestCase):
self
.
assertEqual
(
grc
(
callback
),
2
)
cb
=
MyCallback
(
callback
)
self
.
assert
True
(
grc
(
callback
)
>
2
)
self
.
assert
Greater
(
grc
(
callback
),
2
)
result
=
f
(
-
10
,
cb
)
self
.
assertEqual
(
result
,
-
18
)
cb
=
None
...
...
@@ -46,15 +46,15 @@ class RefcountTestCase(unittest.TestCase):
# the CFuncPtr instance holds at least one refcount on func:
f
=
OtherCallback
(
func
)
self
.
assert
True
(
grc
(
func
)
>
2
)
self
.
assert
Greater
(
grc
(
func
),
2
)
# and may release it again
del
f
self
.
assert
True
(
grc
(
func
)
>=
2
)
self
.
assert
GreaterEqual
(
grc
(
func
),
2
)
# but now it must be gone
gc
.
collect
()
self
.
assert
True
(
grc
(
func
)
==
2
)
self
.
assert
Equal
(
grc
(
func
),
2
)
class
X
(
ctypes
.
Structure
):
_fields_
=
[(
"a"
,
OtherCallback
)]
...
...
@@ -62,11 +62,11 @@ class RefcountTestCase(unittest.TestCase):
x
.
a
=
OtherCallback
(
func
)
# the CFuncPtr instance holds at least one refcount on func:
self
.
assert
True
(
grc
(
func
)
>
2
)
self
.
assert
Greater
(
grc
(
func
),
2
)
# and may release it again
del
x
self
.
assert
True
(
grc
(
func
)
>=
2
)
self
.
assert
GreaterEqual
(
grc
(
func
),
2
)
# and now it must be gone again
gc
.
collect
()
...
...
@@ -75,7 +75,7 @@ class RefcountTestCase(unittest.TestCase):
f
=
OtherCallback
(
func
)
# the CFuncPtr instance holds at least one refcount on func:
self
.
assert
True
(
grc
(
func
)
>
2
)
self
.
assert
Greater
(
grc
(
func
),
2
)
# create a cycle
f
.
cycle
=
f
...
...
Lib/ctypes/test/test_strings.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -115,24 +115,24 @@ class StringTestCase(unittest.TestCase):
# New in releases later than 0.4.0:
# c_string(number) returns an empty string of size number
self
.
assert
True
(
len
(
c_string
(
32
)
.
raw
)
==
32
)
self
.
assert
Equal
(
len
(
c_string
(
32
)
.
raw
),
32
)
self
.
assertRaises
(
ValueError
,
c_string
,
-
1
)
self
.
assertRaises
(
ValueError
,
c_string
,
0
)
# These tests fail, because it is no longer initialized
## self.assert
True(c_string(2).value ==
"")
## self.assert
True(c_string(2).raw ==
"\000\000")
self
.
assert
True
(
c_string
(
2
)
.
raw
[
-
1
]
==
"
\000
"
)
self
.
assert
True
(
len
(
c_string
(
2
)
.
raw
)
==
2
)
## self.assert
Equal(c_string(2).value,
"")
## self.assert
Equal(c_string(2).raw,
"\000\000")
self
.
assert
Equal
(
c_string
(
2
)
.
raw
[
-
1
],
"
\000
"
)
self
.
assert
Equal
(
len
(
c_string
(
2
)
.
raw
),
2
)
def
XX_test_initialized_strings
(
self
):
self
.
assert
True
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
]
==
"ab"
)
self
.
assert
True
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:]
==
"ab"
)
self
.
assert
True
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:
-
1
]
==
"ba"
)
self
.
assert
True
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:
2
]
==
"a"
)
self
.
assert
True
(
c_string
(
"ab"
,
4
)
.
raw
[
-
1
]
==
"
\000
"
)
self
.
assert
True
(
c_string
(
"ab"
,
2
)
.
raw
==
"a
\000
"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
],
"ab"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:],
"ab"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:
-
1
],
"ba"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
4
)
.
raw
[:
2
:
2
],
"a"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
4
)
.
raw
[
-
1
],
"
\000
"
)
self
.
assert
Equal
(
c_string
(
"ab"
,
2
)
.
raw
,
"a
\000
"
)
def
XX_test_toolong
(
self
):
cs
=
c_string
(
"abcdef"
)
...
...
@@ -163,22 +163,22 @@ else:
# XXX This behaviour is about to change:
# len returns the size of the internal buffer in bytes.
# This includes the terminating NUL character.
self
.
assert
True
(
sizeof
(
cs
)
==
14
)
self
.
assert
Equal
(
sizeof
(
cs
),
14
)
# The value property is the string up to the first terminating NUL.
self
.
assert
True
(
cs
.
value
==
"abcdef"
)
self
.
assert
True
(
c_wstring
(
"abc
\000
def"
)
.
value
==
"abc"
)
self
.
assert
Equal
(
cs
.
value
,
"abcdef"
)
self
.
assert
Equal
(
c_wstring
(
"abc
\000
def"
)
.
value
,
"abc"
)
self
.
assert
True
(
c_wstring
(
"abc
\000
def"
)
.
value
==
"abc"
)
self
.
assert
Equal
(
c_wstring
(
"abc
\000
def"
)
.
value
,
"abc"
)
# The raw property is the total buffer contents:
self
.
assert
True
(
cs
.
raw
==
"abcdef
\000
"
)
self
.
assert
True
(
c_wstring
(
"abc
\000
def"
)
.
raw
==
"abc
\000
def
\000
"
)
self
.
assert
Equal
(
cs
.
raw
,
"abcdef
\000
"
)
self
.
assert
Equal
(
c_wstring
(
"abc
\000
def"
)
.
raw
,
"abc
\000
def
\000
"
)
# We can change the value:
cs
.
value
=
"ab"
self
.
assert
True
(
cs
.
value
==
"ab"
)
self
.
assert
True
(
cs
.
raw
==
"ab
\000\000\000\000\000
"
)
self
.
assert
Equal
(
cs
.
value
,
"ab"
)
self
.
assert
Equal
(
cs
.
raw
,
"ab
\000\000\000\000\000
"
)
self
.
assertRaises
(
TypeError
,
c_wstring
,
"123"
)
self
.
assertRaises
(
ValueError
,
c_wstring
,
0
)
...
...
Lib/ctypes/test/test_structures.py
Dosyayı görüntüle @
8f203dda
...
...
@@ -374,9 +374,9 @@ class StructureTestCase(unittest.TestCase):
## class X(Structure):
## _fields_ = []
self
.
assert
True
(
"in_dll"
in
dir
(
type
(
Structure
)))
self
.
assert
True
(
"from_address"
in
dir
(
type
(
Structure
)))
self
.
assert
True
(
"in_dll"
in
dir
(
type
(
Structure
)))
self
.
assert
In
(
"in_dll"
,
dir
(
type
(
Structure
)))
self
.
assert
In
(
"from_address"
,
dir
(
type
(
Structure
)))
self
.
assert
In
(
"in_dll"
,
dir
(
type
(
Structure
)))
def
test_positional_args
(
self
):
# see also http://bugs.python.org/issue5042
...
...
@@ -446,8 +446,8 @@ class TestRecursiveStructure(unittest.TestCase):
try
:
Recursive
.
_fields_
=
[(
"next"
,
Recursive
)]
except
AttributeError
as
details
:
self
.
assert
True
(
"Structure or union cannot contain itself"
in
str
(
details
))
self
.
assert
In
(
"Structure or union cannot contain itself"
,
str
(
details
))
else
:
self
.
fail
(
"Structure or union cannot contain itself"
)
...
...
@@ -463,8 +463,7 @@ class TestRecursiveStructure(unittest.TestCase):
try
:
Second
.
_fields_
=
[(
"first"
,
First
)]
except
AttributeError
as
details
:
self
.
assertTrue
(
"_fields_ is final"
in
str
(
details
))
self
.
assertIn
(
"_fields_ is final"
,
str
(
details
))
else
:
self
.
fail
(
"AttributeError not raised"
)
...
...
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