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
c02e1e65
Kaydet (Commit)
c02e1e65
authored
Tem 29, 2012
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #15467: Move helpers for __sizeof__ tests into test_support.
Patch by Serhiy Storchaka.
üst
68123468
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
31 deletions
+42
-31
test_struct.py
Lib/test/test_struct.py
+11
-31
test_support.py
Lib/test/test_support.py
+28
-0
test_sys.py
Lib/test/test_sys.py
+0
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_struct.py
Dosyayı görüntüle @
c02e1e65
...
...
@@ -3,8 +3,8 @@ import array
import
unittest
import
struct
import
inspect
from
test
.test_support
import
(
run_unittest
,
check_warnings
,
check_py3k_warnings
,
cpython_only
)
from
test
import
test_support
as
support
from
test.test_support
import
(
check_warnings
,
check_py3k_warnings
)
import
sys
ISBIGENDIAN
=
sys
.
byteorder
==
"big"
...
...
@@ -33,33 +33,6 @@ def bigendian_to_native(value):
class
StructTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
# due to missing size_t information from struct, it is assumed that
# sizeof(Py_ssize_t) = sizeof(void*)
self
.
header
=
'PP'
if
hasattr
(
sys
,
"gettotalrefcount"
):
self
.
header
+=
'2P'
def
check_sizeof
(
self
,
format_str
,
number_of_codes
):
def
size
(
fmt
):
"""Wrapper around struct.calcsize which enforces the alignment
of the end of a structure to the alignment requirement of pointer.
Note: This wrapper should only be used if a pointer member is
included and no member with a size larger than a pointer exists.
"""
return
struct
.
calcsize
(
fmt
+
'0P'
)
struct_obj
=
struct
.
Struct
(
format_str
)
# The size of 'PyStructObject'
totalsize
=
size
(
self
.
header
+
'5P'
)
# The size taken up by the 'formatcode' dynamic array
totalsize
+=
size
(
'3P'
)
*
(
number_of_codes
+
1
)
result
=
sys
.
getsizeof
(
struct_obj
)
msg
=
'wrong size for
%
s: got
%
d, expected
%
d'
\
%
(
type
(
struct_obj
),
result
,
totalsize
)
self
.
assertEqual
(
result
,
totalsize
,
msg
)
def
check_float_coerce
(
self
,
format
,
number
):
# SF bug 1530559. struct.pack raises TypeError where it used
# to convert.
...
...
@@ -572,7 +545,14 @@ class StructTest(unittest.TestCase):
hugecount2
=
'{}b{}H'
.
format
(
sys
.
maxsize
//
2
,
sys
.
maxsize
//
2
)
self
.
assertRaises
(
struct
.
error
,
struct
.
calcsize
,
hugecount2
)
@cpython_only
def
check_sizeof
(
self
,
format_str
,
number_of_codes
):
# The size of 'PyStructObject'
totalsize
=
support
.
calcobjsize
(
'5P'
)
# The size taken up by the 'formatcode' dynamic array
totalsize
+=
struct
.
calcsize
(
'3P'
)
*
(
number_of_codes
+
1
)
support
.
check_sizeof
(
self
,
struct
.
Struct
(
format_str
),
totalsize
)
@support.cpython_only
def
test__sizeof__
(
self
):
for
code
in
integer_codes
:
self
.
check_sizeof
(
code
,
1
)
...
...
@@ -587,7 +567,7 @@ class StructTest(unittest.TestCase):
self
.
check_sizeof
(
'0c'
,
0
)
def
test_main
():
run_unittest
(
StructTest
)
support
.
run_unittest
(
StructTest
)
if
__name__
==
'__main__'
:
test_main
()
Lib/test/test_support.py
Dosyayı görüntüle @
c02e1e65
...
...
@@ -18,6 +18,8 @@ import importlib
import
UserDict
import
re
import
time
import
struct
import
_testcapi
try
:
import
thread
except
ImportError
:
...
...
@@ -861,6 +863,32 @@ def gc_collect():
gc
.
collect
()
_header
=
'2P'
if
hasattr
(
sys
,
"gettotalrefcount"
):
_header
=
'2P'
+
_header
_vheader
=
_header
+
'P'
def
calcobjsize
(
fmt
):
return
struct
.
calcsize
(
_header
+
fmt
+
'0P'
)
def
calcvobjsize
(
fmt
):
return
struct
.
calcsize
(
_vheader
+
fmt
+
'0P'
)
_TPFLAGS_HAVE_GC
=
1
<<
14
_TPFLAGS_HEAPTYPE
=
1
<<
9
def
check_sizeof
(
test
,
o
,
size
):
result
=
sys
.
getsizeof
(
o
)
# add GC header size
if
((
type
(
o
)
==
type
)
and
(
o
.
__flags__
&
_TPFLAGS_HEAPTYPE
)
or
\
((
type
(
o
)
!=
type
)
and
(
type
(
o
)
.
__flags__
&
_TPFLAGS_HAVE_GC
))):
size
+=
_testcapi
.
SIZEOF_PYGC_HEAD
msg
=
'wrong size for
%
s: got
%
d, expected
%
d'
\
%
(
type
(
o
),
result
,
size
)
test
.
assertEqual
(
result
,
size
,
msg
)
#=======================================================================
# Decorator for running a function in a different locale, correctly resetting
# it afterwards.
...
...
Lib/test/test_sys.py
Dosyayı görüntüle @
c02e1e65
This diff is collapsed.
Click to expand it.
Misc/NEWS
Dosyayı görüntüle @
c02e1e65
...
...
@@ -887,6 +887,9 @@ Tools/Demos
Tests
-----
- Issue #15467: Move helpers for __sizeof__ tests into test_support.
Patch by Serhiy Storchaka.
- Issue #11689: Fix a variable scoping error in an sqlite3 test.
Initial patch by Torsten Landschoff.
...
...
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