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
f08a0176
Kaydet (Commit)
f08a0176
authored
Mar 22, 2010
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Get rid of buffer() in test_ctypes: backport the 3.x tests.
üst
52093b8e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
47 deletions
+30
-47
test_array_in_pointer.py
Lib/ctypes/test/test_array_in_pointer.py
+1
-1
test_byteswap.py
Lib/ctypes/test/test_byteswap.py
+1
-1
test_pep3118.py
Lib/ctypes/test/test_pep3118.py
+11
-26
test_pickling.py
Lib/ctypes/test/test_pickling.py
+4
-4
test_random_things.py
Lib/ctypes/test/test_random_things.py
+2
-2
test_strings.py
Lib/ctypes/test/test_strings.py
+6
-6
test_ctypes.py
Lib/test/test_ctypes.py
+5
-7
No files found.
Lib/ctypes/test/test_array_in_pointer.py
Dosyayı görüntüle @
f08a0176
...
...
@@ -6,7 +6,7 @@ import re
def
dump
(
obj
):
# helper function to dump memory contents in hex, with a hyphen
# between the bytes.
h
=
hexlify
(
buffer
(
obj
))
h
=
hexlify
(
memoryview
(
obj
))
return
re
.
sub
(
r"(..)"
,
r"\1-"
,
h
)[:
-
1
]
...
...
Lib/ctypes/test/test_byteswap.py
Dosyayı görüntüle @
f08a0176
...
...
@@ -4,7 +4,7 @@ from binascii import hexlify
from
ctypes
import
*
def
bin
(
s
):
return
hexlify
(
buffer
(
s
))
.
upper
()
return
hexlify
(
memoryview
(
s
))
.
upper
()
# Each *simple* type that supports different byte orders has an
# __ctype_be__ attribute that specifies the same type in BIG ENDIAN
...
...
Lib/ctypes/test/test_pep3118.py
Dosyayı görüntüle @
f08a0176
import
unittest
from
ctypes
import
*
import
re
,
s
truct
,
s
ys
import
re
,
sys
if
sys
.
byteorder
==
"little"
:
THIS_ENDIAN
=
"<"
...
...
@@ -9,27 +9,6 @@ else:
THIS_ENDIAN
=
">"
OTHER_ENDIAN
=
"<"
class
memoryview
(
object
):
# This class creates a memoryview - like object from data returned
# by the private _ctypes._buffer_info() function, just enough for
# these tests.
#
# It can be removed when the py3k memoryview object is backported.
def
__init__
(
self
,
ob
):
from
_ctypes
import
_buffer_info
self
.
format
,
self
.
ndim
,
self
.
shape
=
_buffer_info
(
ob
)
if
self
.
shape
==
():
self
.
shape
=
None
self
.
itemsize
=
sizeof
(
ob
)
else
:
size
=
sizeof
(
ob
)
for
dim
in
self
.
shape
:
size
//=
dim
self
.
itemsize
=
size
self
.
strides
=
None
self
.
readonly
=
False
self
.
size
=
sizeof
(
ob
)
def
normalize
(
format
):
# Remove current endian specifier and white space from a format
# string
...
...
@@ -46,7 +25,10 @@ class Test(unittest.TestCase):
v
=
memoryview
(
ob
)
try
:
self
.
assertEqual
(
normalize
(
v
.
format
),
normalize
(
fmt
))
self
.
assertEqual
(
v
.
size
,
sizeof
(
ob
))
if
shape
is
not
None
:
self
.
assertEqual
(
len
(
v
),
shape
[
0
])
else
:
self
.
assertEqual
(
len
(
v
)
*
sizeof
(
itemtp
),
sizeof
(
ob
))
self
.
assertEqual
(
v
.
itemsize
,
sizeof
(
itemtp
))
self
.
assertEqual
(
v
.
shape
,
shape
)
# ctypes object always have a non-strided memory block
...
...
@@ -58,7 +40,7 @@ class Test(unittest.TestCase):
n
=
1
for
dim
in
v
.
shape
:
n
=
n
*
dim
self
.
assertEqual
(
v
.
itemsize
*
n
,
v
.
size
)
self
.
assertEqual
(
n
*
v
.
itemsize
,
len
(
v
.
tobytes
())
)
except
:
# so that we can see the failing type
print
(
tp
)
...
...
@@ -70,7 +52,10 @@ class Test(unittest.TestCase):
v
=
memoryview
(
ob
)
try
:
self
.
assertEqual
(
v
.
format
,
fmt
)
self
.
assertEqual
(
v
.
size
,
sizeof
(
ob
))
if
shape
is
not
None
:
self
.
assertEqual
(
len
(
v
),
shape
[
0
])
else
:
self
.
assertEqual
(
len
(
v
)
*
sizeof
(
itemtp
),
sizeof
(
ob
))
self
.
assertEqual
(
v
.
itemsize
,
sizeof
(
itemtp
))
self
.
assertEqual
(
v
.
shape
,
shape
)
# ctypes object always have a non-strided memory block
...
...
@@ -82,7 +67,7 @@ class Test(unittest.TestCase):
n
=
1
for
dim
in
v
.
shape
:
n
=
n
*
dim
self
.
assertEqual
(
v
.
itemsize
*
n
,
v
.
size
)
self
.
assertEqual
(
n
,
len
(
v
)
)
except
:
# so that we can see the failing type
print
(
tp
)
...
...
Lib/ctypes/test/test_pickling.py
Dosyayı görüntüle @
f08a0176
...
...
@@ -28,8 +28,8 @@ class PickleTest(unittest.TestCase):
]:
dst
=
self
.
loads
(
self
.
dumps
(
src
))
self
.
assertEqual
(
src
.
__dict__
,
dst
.
__dict__
)
self
.
assertEqual
(
buffer
(
src
)[:]
,
buffer
(
dst
)[:]
)
self
.
assertEqual
(
memoryview
(
src
)
.
tobytes
()
,
memoryview
(
dst
)
.
tobytes
()
)
def
test_struct
(
self
):
X
.
init_called
=
0
...
...
@@ -46,8 +46,8 @@ class PickleTest(unittest.TestCase):
# ctypes instances are identical when the instance __dict__
# and the memory buffer are identical
self
.
assertEqual
(
y
.
__dict__
,
x
.
__dict__
)
self
.
assertEqual
(
buffer
(
y
)[:]
,
buffer
(
x
)[:]
)
self
.
assertEqual
(
memoryview
(
y
)
.
tobytes
()
,
memoryview
(
x
)
.
tobytes
()
)
def
test_unpickable
(
self
):
# ctypes objects that are pointers or contain pointers are
...
...
Lib/ctypes/test/test_random_things.py
Dosyayı görüntüle @
f08a0176
...
...
@@ -2,7 +2,7 @@ from ctypes import *
import
unittest
,
sys
def
callback_func
(
arg
):
42
/
arg
42
/
/
arg
raise
ValueError
(
arg
)
if
sys
.
platform
==
"win32"
:
...
...
@@ -69,7 +69,7 @@ class CallbackTracbackTestCase(unittest.TestCase):
out
=
self
.
capture_stderr
(
cb
,
"spam"
)
self
.
assertEqual
(
out
.
splitlines
()[
-
1
],
"TypeError: "
"unsupported operand type(s) for /: 'int' and 'str'"
)
"unsupported operand type(s) for /
/
: 'int' and 'str'"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Lib/ctypes/test/test_strings.py
Dosyayı görüntüle @
f08a0176
...
...
@@ -30,17 +30,17 @@ class StringArrayTestCase(unittest.TestCase):
buf
.
value
=
"Hello, World"
self
.
assertEqual
(
buf
.
value
,
"Hello, World"
)
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
buffer
(
"Hello, World"
))
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
buffer
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
buffer
(
"x"
*
100
))
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
memoryview
(
"Hello, World"
))
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
memoryview
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
memoryview
(
"x"
*
100
))
def
test_c_buffer_raw
(
self
):
buf
=
c_buffer
(
32
)
buf
.
raw
=
buffer
(
"Hello, World"
)
buf
.
raw
=
memoryview
(
"Hello, World"
)
self
.
assertEqual
(
buf
.
value
,
"Hello, World"
)
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
buffer
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
buffer
(
"x"
*
100
))
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
memoryview
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
memoryview
(
"x"
*
100
))
def
test_param_1
(
self
):
BUF
=
c_char
*
4
...
...
Lib/test/test_ctypes.py
Dosyayı görüntüle @
f08a0176
import
unittest
from
test.test_support
import
run_unittest
,
import_module
,
check_py3k_warnings
from
test.test_support
import
run_unittest
,
import_module
#Skip tests if _ctypes module does not exist
import_module
(
'_ctypes'
)
def
test_main
():
with
check_py3k_warnings
((
"buffer.. not supported"
,
DeprecationWarning
),
(
"classic (int|long) division"
,
DeprecationWarning
)):
import
ctypes.test
skipped
,
testcases
=
ctypes
.
test
.
get_tests
(
ctypes
.
test
,
"test_*.py"
,
verbosity
=
0
)
suites
=
[
unittest
.
makeSuite
(
t
)
for
t
in
testcases
]
run_unittest
(
unittest
.
TestSuite
(
suites
))
import
ctypes.test
skipped
,
testcases
=
ctypes
.
test
.
get_tests
(
ctypes
.
test
,
"test_*.py"
,
verbosity
=
0
)
suites
=
[
unittest
.
makeSuite
(
t
)
for
t
in
testcases
]
run_unittest
(
unittest
.
TestSuite
(
suites
))
if
__name__
==
"__main__"
:
test_main
()
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