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
edf5f0dd
Kaydet (Commit)
edf5f0dd
authored
Eyl 03, 2010
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Strengthen BytesWarning tests.
üst
764d612f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
45 deletions
+54
-45
test_bytes.py
Lib/test/test_bytes.py
+54
-45
No files found.
Lib/test/test_bytes.py
Dosyayı görüntüle @
edf5f0dd
...
...
@@ -9,15 +9,28 @@ import os
import
re
import
sys
import
copy
import
operator
import
functools
import
pickle
import
tempfile
import
unittest
import
warnings
import
test.support
import
test.string_tests
import
test.buffer_tests
if
sys
.
flags
.
bytes_warning
:
def
check_bytes_warnings
(
func
):
@functools.wraps
(
func
)
def
wrapper
(
*
args
,
**
kw
):
with
test
.
support
.
check_warnings
((
''
,
BytesWarning
)):
return
func
(
*
args
,
**
kw
)
return
wrapper
else
:
# no-op
def
check_bytes_warnings
(
func
):
return
func
class
Indexable
:
def
__init__
(
self
,
value
=
0
):
self
.
value
=
value
...
...
@@ -121,20 +134,19 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertFalse
(
b3
<
b2
)
self
.
assertFalse
(
b3
<=
b2
)
@check_bytes_warnings
def
test_compare_to_str
(
self
):
with
test
.
support
.
check_warnings
():
warnings
.
simplefilter
(
'ignore'
,
BytesWarning
)
# Byte comparisons with unicode should always fail!
# Test this for all expected byte orders and Unicode character
# sizes.
self
.
assertEqual
(
self
.
type2test
(
b
"
\0
a
\0
b
\0
c"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"
\0\0\0
a
\0\0\0
b
\0\0\0
c"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"a
\0
b
\0
c
\0
"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"a
\0\0\0
b
\0\0\0
c
\0\0\0
"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
()
==
str
(),
False
)
self
.
assertEqual
(
self
.
type2test
()
!=
str
(),
True
)
# Byte comparisons with unicode should always fail!
# Test this for all expected byte orders and Unicode character
# sizes.
self
.
assertEqual
(
self
.
type2test
(
b
"
\0
a
\0
b
\0
c"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"
\0\0\0
a
\0\0\0
b
\0\0\0
c"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"a
\0
b
\0
c
\0
"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
(
b
"a
\0\0\0
b
\0\0\0
c
\0\0\0
"
)
==
"abc"
,
False
)
self
.
assertEqual
(
self
.
type2test
()
==
str
(),
False
)
self
.
assertEqual
(
self
.
type2test
()
!=
str
(),
True
)
def
test_reversed
(
self
):
input
=
list
(
map
(
ord
,
"Hello"
))
...
...
@@ -823,17 +835,16 @@ class AssortedBytesTest(unittest.TestCase):
# Test various combinations of bytes and bytearray
#
@check_bytes_warnings
def
test_repr_str
(
self
):
with
test
.
support
.
check_warnings
():
warnings
.
simplefilter
(
'ignore'
,
BytesWarning
)
for
f
in
str
,
repr
:
self
.
assertEqual
(
f
(
bytearray
()),
"bytearray(b'')"
)
self
.
assertEqual
(
f
(
bytearray
([
0
])),
"bytearray(b'
\\
x00')"
)
self
.
assertEqual
(
f
(
bytearray
([
0
,
1
,
254
,
255
])),
"bytearray(b'
\\
x00
\\
x01
\\
xfe
\\
xff')"
)
self
.
assertEqual
(
f
(
b
"abc"
),
"b'abc'"
)
self
.
assertEqual
(
f
(
b
"'"
),
'''b"'"'''
)
# '''
self
.
assertEqual
(
f
(
b
"'
\"
"
),
r"""b'\'"'"""
)
# '
for
f
in
str
,
repr
:
self
.
assertEqual
(
f
(
bytearray
()),
"bytearray(b'')"
)
self
.
assertEqual
(
f
(
bytearray
([
0
])),
"bytearray(b'
\\
x00')"
)
self
.
assertEqual
(
f
(
bytearray
([
0
,
1
,
254
,
255
])),
"bytearray(b'
\\
x00
\\
x01
\\
xfe
\\
xff')"
)
self
.
assertEqual
(
f
(
b
"abc"
),
"b'abc'"
)
self
.
assertEqual
(
f
(
b
"'"
),
'''b"'"'''
)
# '''
self
.
assertEqual
(
f
(
b
"'
\"
"
),
r"""b'\'"'"""
)
# '
def
test_compare_bytes_to_bytearray
(
self
):
self
.
assertEqual
(
b
"abc"
==
bytes
(
b
"abc"
),
True
)
...
...
@@ -876,15 +887,14 @@ class AssortedBytesTest(unittest.TestCase):
b
=
bytearray
(
buf
)
self
.
assertEqual
(
b
,
bytearray
(
sample
))
@check_bytes_warnings
def
test_to_str
(
self
):
with
test
.
support
.
check_warnings
():
warnings
.
simplefilter
(
'ignore'
,
BytesWarning
)
self
.
assertEqual
(
str
(
b
''
),
"b''"
)
self
.
assertEqual
(
str
(
b
'x'
),
"b'x'"
)
self
.
assertEqual
(
str
(
b
'
\x80
'
),
"b'
\\
x80'"
)
self
.
assertEqual
(
str
(
bytearray
(
b
''
)),
"bytearray(b'')"
)
self
.
assertEqual
(
str
(
bytearray
(
b
'x'
)),
"bytearray(b'x')"
)
self
.
assertEqual
(
str
(
bytearray
(
b
'
\x80
'
)),
"bytearray(b'
\\
x80')"
)
self
.
assertEqual
(
str
(
b
''
),
"b''"
)
self
.
assertEqual
(
str
(
b
'x'
),
"b'x'"
)
self
.
assertEqual
(
str
(
b
'
\x80
'
),
"b'
\\
x80'"
)
self
.
assertEqual
(
str
(
bytearray
(
b
''
)),
"bytearray(b'')"
)
self
.
assertEqual
(
str
(
bytearray
(
b
'x'
)),
"bytearray(b'x')"
)
self
.
assertEqual
(
str
(
bytearray
(
b
'
\x80
'
)),
"bytearray(b'
\\
x80')"
)
def
test_literal
(
self
):
tests
=
[
...
...
@@ -930,19 +940,18 @@ class AssortedBytesTest(unittest.TestCase):
def
test_compare
(
self
):
if
sys
.
flags
.
bytes_warning
:
with
test
.
support
.
check_warnings
():
warnings
.
simplefilter
(
'error'
,
BytesWarning
)
with
self
.
assertRaises
(
BytesWarning
):
b
''
==
''
with
self
.
assertRaises
(
BytesWarning
):
b
''
!=
''
with
self
.
assertRaises
(
BytesWarning
):
bytearray
(
b
''
)
==
''
with
self
.
assertRaises
(
BytesWarning
):
bytearray
(
b
''
)
!=
''
def
bytes_warning
():
return
test
.
support
.
check_warnings
((
''
,
BytesWarning
)
)
with
bytes_warning
(
):
b
''
==
''
with
bytes_warning
(
):
b
''
!=
''
with
bytes_warning
(
):
bytearray
(
b
''
)
==
''
with
bytes_warning
(
):
bytearray
(
b
''
)
!=
''
else
:
# self.skipTest("BytesWarning is needed for this test: use -bb option")
pass
self
.
skipTest
(
"BytesWarning is needed for this test: use -bb option"
)
# Optimizations:
# __iter__? (optimization)
...
...
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