summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-09-13 07:46:37 +0000
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-09-13 07:46:37 +0000
commit9b90cd1f7b7fa658a48389ca599cd6ffde922e34 (patch)
tree860050591ce74169f13d8fb1ebaf3cb735de6b7e /Lib/test/test_bytes.py
parentf994f047455f9a558f9da4a9a9df9a679fcdd628 (diff)
downloadcpython-git-9b90cd1f7b7fa658a48389ca599cd6ffde922e34.tar.gz
Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84470 | florent.xicluna | 2010-09-03 22:00:37 +0200 (ven., 03 sept. 2010) | 1 line Strengthen BytesWarning tests. ........ r84471 | florent.xicluna | 2010-09-03 22:23:40 +0200 (ven., 03 sept. 2010) | 1 line Typo ........ r84566 | florent.xicluna | 2010-09-06 22:27:15 +0200 (lun., 06 sept. 2010) | 1 line typo ........ r84567 | florent.xicluna | 2010-09-06 22:27:55 +0200 (lun., 06 sept. 2010) | 1 line typo ........ r84759 | florent.xicluna | 2010-09-13 04:28:18 +0200 (lun., 13 sept. 2010) | 1 line Reenable test_ucs4 and remove some duplicated lines. ........
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 516d6d9782..d0f56625c8 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -9,14 +9,28 @@ import os
import re
import sys
import copy
+import functools
import pickle
import tempfile
import unittest
-import warnings
import test.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.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
@@ -26,12 +40,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)
@@ -120,8 +128,8 @@ class BaseBytesTest(unittest.TestCase):
self.assertFalse(b3 < b2)
self.assertFalse(b3 <= b2)
+ @check_bytes_warnings
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"\0a\0b\0c") == u"abc", False)
@@ -795,14 +803,8 @@ 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
-
+ @check_bytes_warnings
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')")
@@ -853,8 +855,8 @@ class AssortedBytesTest(unittest.TestCase):
b = bytearray(buf)
self.assertEqual(b, bytearray(sample))
+ @check_bytes_warnings
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'")