Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
41a08bcb
Commit
41a08bcb
authored
Mar 20, 2010
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up warnings filter use in test_bytes.
parent
77628993
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
42 deletions
+41
-42
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+41
-42
No files found.
Lib/test/test_bytes.py
View file @
41a08bcb
...
...
@@ -27,12 +27,6 @@ class Indexable:
class
BaseBytesTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
warning_filters
=
warnings
.
filters
[:]
def
tearDown
(
self
):
warnings
.
filters
=
self
.
warning_filters
def
test_basics
(
self
):
b
=
self
.
type2test
()
self
.
assertEqual
(
type
(
b
),
self
.
type2test
)
...
...
@@ -127,15 +121,19 @@ class BaseBytesTest(unittest.TestCase):
self
.
assertFalse
(
b3
<=
b2
)
def
test_compare_to_str
(
self
):
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
)
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
)
def
test_reversed
(
self
):
input
=
list
(
map
(
ord
,
"Hello"
))
...
...
@@ -829,22 +827,17 @@ class AssortedBytesTest(unittest.TestCase):
# Test various combinations of bytes and bytearray
#
def setUp(self):
self.warning_filters = warnings.filters[:]
def tearDown(self):
warnings.filters = self.warning_filters
def test_repr_str(self):
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'
\
'"'""") # '
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'
\
'"'""") # '
def test_compare_bytes_to_bytearray(self):
self.assertEqual(b"abc" == bytes(b"abc"), True)
...
...
@@ -888,13 +881,14 @@ class AssortedBytesTest(unittest.TestCase):
self.assertEqual(b, bytearray(sample))
def test_to_str(self):
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')")
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')")
def test_literal(self):
tests = [
...
...
@@ -940,11 +934,16 @@ class AssortedBytesTest(unittest.TestCase):
def test_compare(self):
if sys.flags.bytes_warning:
warnings.simplefilter('error', BytesWarning)
self.assertRaises(BytesWarning, operator.eq, b'', '')
self.assertRaises(BytesWarning, operator.ne, b'', '')
self.assertRaises(BytesWarning, operator.eq, bytearray(b''), '')
self.assertRaises(BytesWarning, operator.ne, bytearray(b''), '')
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'') != ''
else:
# self.skipTest("BytesWarning is needed for this test: use -bb option")
pass
...
...
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