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
2a378502
Kaydet (Commit)
2a378502
authored
Ara 31, 1996
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Exercise the new feature set somewhat.
Use TestFailed exception and verbose flag from test_support module.
üst
60c50614
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
10 deletions
+73
-10
test_struct.py
Lib/test/test_struct.py
+73
-10
No files found.
Lib/test/test_struct.py
Dosyayı görüntüle @
2a378502
from
test_support
import
TestFailed
,
verbose
import
struct
## import pdb
...
...
@@ -7,18 +8,19 @@ def simple_err(func, *args):
except
struct
.
error
:
pass
else
:
print
'expected struct.error not caught'
raise
TestFailed
,
"
%
s
%
s did not raise struct.error"
%
(
func
.
__name__
,
args
)
## pdb.set_trace()
simple_err
(
struct
.
calcsize
,
'Q'
)
sz
=
struct
.
calcsize
(
'i'
)
if
sz
*
3
<>
struct
.
calcsize
(
'iii'
):
print
'inconsistent sizes'
raise
TestFailed
,
'inconsistent sizes'
sz
=
struct
.
calcsize
(
'cbhilfd'
)
if
sz
*
3
<>
struct
.
calcsize
(
'3c3b3h3i3l3f3d'
):
print
'inconsistent sizes'
raise
TestFailed
,
'inconsistent sizes'
simple_err
(
struct
.
pack
,
'iii'
,
3
)
simple_err
(
struct
.
pack
,
'i'
,
3
,
3
,
3
)
...
...
@@ -29,16 +31,77 @@ simple_err(struct.unpack, 'iii', s)
simple_err
(
struct
.
unpack
,
'i'
,
s
)
c
=
'a'
b
=
-
1
b
=
1
h
=
255
i
=
65535
l
=
65536
f
=
3.1415
d
=
3.1415
s
=
struct
.
pack
(
'xcbhilfd'
,
c
,
b
,
h
,
i
,
l
,
f
,
d
)
cp
,
bp
,
hp
,
ip
,
lp
,
fp
,
dp
=
struct
.
unpack
(
'xcbhilfd'
,
s
)
if
cp
<>
c
or
bp
<>
b
or
hp
<>
h
or
ip
<>
i
or
lp
<>
l
or
\
int
(
100
*
fp
)
<>
int
(
100
*
f
)
or
int
(
100
*
dp
)
<>
int
(
100
*
d
):
# ^^^ calculate only to two decimal places
print
'unpack/pack not transitive'
for
format
in
(
'xcbhilfd'
,
'xcBHILfd'
,
'@xsbhilfd'
):
s
=
struct
.
pack
(
format
,
c
,
b
,
h
,
i
,
l
,
f
,
d
)
cp
,
bp
,
hp
,
ip
,
lp
,
fp
,
dp
=
struct
.
unpack
(
format
,
s
)
if
(
cp
<>
c
or
bp
<>
b
or
hp
<>
h
or
ip
<>
i
or
lp
<>
l
or
int
(
100
*
fp
)
<>
int
(
100
*
f
)
or
int
(
100
*
dp
)
<>
int
(
100
*
d
)):
# ^^^ calculate only to two decimal places
raise
TestFailed
,
"unpack/pack not transitive (
%
s,
%
s)"
%
(
str
(
format
),
str
((
cp
,
bp
,
hp
,
ip
,
lp
,
fp
,
dp
)))
# Test some of the new features
# (format, argument, big-endian result, little-endian result, asymmetric)
tests
=
[
(
'c'
,
'a'
,
'a'
,
'a'
,
0
),
(
'xc'
,
'a'
,
'
\0
a'
,
'
\0
a'
,
0
),
(
'cx'
,
'a'
,
'a
\0
'
,
'a
\0
'
,
0
),
(
's'
,
'a'
,
'a'
,
'a'
,
0
),
(
'0s'
,
'helloworld'
,
''
,
''
,
1
),
(
'1s'
,
'helloworld'
,
'h'
,
'h'
,
1
),
(
'9s'
,
'helloworld'
,
'helloworl'
,
'helloworl'
,
1
),
(
'10s'
,
'helloworld'
,
'helloworld'
,
'helloworld'
,
0
),
(
'11s'
,
'helloworld'
,
'helloworld
\0
'
,
'helloworld
\0
'
,
1
),
(
'20s'
,
'helloworld'
,
'helloworld'
+
10
*
'
\0
'
,
'helloworld'
+
10
*
'
\0
'
,
1
),
(
'b'
,
7
,
'
\7
'
,
'
\7
'
,
0
),
(
'b'
,
-
7
,
'
\371
'
,
'
\371
'
,
0
),
(
'B'
,
7
,
'
\7
'
,
'
\7
'
,
0
),
(
'B'
,
249
,
'
\371
'
,
'
\371
'
,
0
),
(
'h'
,
700
,
'
\002\274
'
,
'
\274\002
'
,
0
),
(
'h'
,
-
700
,
'
\375
D'
,
'D
\375
'
,
0
),
(
'H'
,
700
,
'
\002\274
'
,
'
\274\002
'
,
0
),
(
'H'
,
0x10000
-
700
,
'
\375
D'
,
'D
\375
'
,
0
),
(
'i'
,
70000000
,
'
\004
,
\035\200
'
,
'
\200\035
,
\004
'
,
0
),
(
'i'
,
-
70000000
,
'
\373\323\342\200
'
,
'
\200\342\323\373
'
,
0
),
(
'I'
,
70000000L
,
'
\004
,
\035\200
'
,
'
\200\035
,
\004
'
,
0
),
(
'I'
,
0x100000000
L
-
70000000
,
'
\373\323\342\200
'
,
'
\200\342\323\373
'
,
0
),
(
'l'
,
70000000
,
'
\004
,
\035\200
'
,
'
\200\035
,
\004
'
,
0
),
(
'l'
,
-
70000000
,
'
\373\323\342\200
'
,
'
\200\342\323\373
'
,
0
),
(
'L'
,
70000000L
,
'
\004
,
\035\200
'
,
'
\200\035
,
\004
'
,
0
),
(
'L'
,
0x100000000
L
-
70000000
,
'
\373\323\342\200
'
,
'
\200\342\323\373
'
,
0
),
]
def
badpack
(
fmt
,
arg
,
got
,
exp
):
return
def
badunpack
(
fmt
,
arg
,
got
,
exp
):
return
"unpack(
%
s,
%
s) -> (
%
s,) # expected (
%
s,)"
%
(
`fmt`
,
`arg`
,
`got`
,
`exp`
)
isbigendian
=
struct
.
pack
(
'=h'
,
1
)
==
'
\0\1
'
for
fmt
,
arg
,
big
,
lil
,
asy
in
tests
:
if
verbose
:
print
`fmt`
,
`arg`
,
`big`
,
`lil`
for
(
xfmt
,
exp
)
in
[(
'>'
+
fmt
,
big
),
(
'!'
+
fmt
,
big
),
(
'<'
+
fmt
,
lil
),
(
'='
+
fmt
,
isbigendian
and
big
or
lil
)]:
res
=
struct
.
pack
(
xfmt
,
arg
)
if
res
!=
exp
:
raise
TestFailed
,
"pack(
%
s,
%
s) ->
%
s # expected
%
s"
%
(
`fmt`
,
`arg`
,
`res`
,
`exp`
)
n
=
struct
.
calcsize
(
xfmt
)
if
n
!=
len
(
res
):
raise
TestFailed
,
"calcsize(
%
s) ->
%
d # expected
%
d"
%
(
`xfmt`
,
n
,
len
(
res
))
rev
=
struct
.
unpack
(
xfmt
,
res
)[
0
]
if
rev
!=
arg
and
not
asy
:
raise
TestFailed
,
"unpack(
%
s,
%
s) -> (
%
s,) # expected (
%
s,)"
%
(
`fmt`
,
`res`
,
`rev`
,
`arg`
)
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