[Python-checkins] cpython (2.7): Fixed Py3k warnings in tests for issue #24731.

serhiy.storchaka python-checkins at python.org
Sun Nov 29 13:14:14 EST 2015


https://hg.python.org/cpython/rev/2ea1a3bf448f
changeset: 99389:2ea1a3bf448f
branch: 2.7
user: Serhiy Storchaka <storchaka at gmail.com>
date: Sun Nov 29 20:13:56 2015 +0200
summary:
 Fixed Py3k warnings in tests for issue #24731.
files:
 Lib/test/test_compile.py | 17 +++++++++--------
 Lib/test/test_float.py | 17 ++++++++++-------
 Lib/test/test_int.py | 17 ++++++++++-------
 3 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -576,14 +576,15 @@
 # objects are accepted, which could be not terminated.
 with self.assertRaisesRegexp(TypeError, "without null bytes"):
 compile(u"123\x00", "<dummy>", "eval")
- with self.assertRaisesRegexp(TypeError, "without null bytes"):
- compile(buffer("123\x00"), "<dummy>", "eval")
- code = compile(buffer("123\x00", 1, 2), "<dummy>", "eval")
- self.assertEqual(eval(code), 23)
- code = compile(buffer("1234", 1, 2), "<dummy>", "eval")
- self.assertEqual(eval(code), 23)
- code = compile(buffer("23ドル$", 1, 2), "<dummy>", "eval")
- self.assertEqual(eval(code), 23)
+ with test_support.check_py3k_warnings():
+ with self.assertRaisesRegexp(TypeError, "without null bytes"):
+ compile(buffer("123\x00"), "<dummy>", "eval")
+ code = compile(buffer("123\x00", 1, 2), "<dummy>", "eval")
+ self.assertEqual(eval(code), 23)
+ code = compile(buffer("1234", 1, 2), "<dummy>", "eval")
+ self.assertEqual(eval(code), 23)
+ code = compile(buffer("23ドル$", 1, 2), "<dummy>", "eval")
+ self.assertEqual(eval(code), 23)
 
 class TestStackSize(unittest.TestCase):
 # These tests check that the computed stack size for a code object
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -71,7 +71,8 @@
 factories += [unicode, CustomUnicode]
 
 for f in factories:
- x = f(" 3.14 ")
+ with test_support.check_py3k_warnings(quiet=True):
+ x = f(" 3.14 ")
 msg = 'x has value %s and type %s' % (x, type(x).__name__)
 try:
 self.assertEqual(float(x), 3.14, msg=msg)
@@ -79,15 +80,17 @@
 raise AssertionError('For %s got TypeError: %s' %
 (type(x).__name__, err))
 errmsg = "could not convert"
- with self.assertRaisesRegexp(ValueError, errmsg, msg=msg):
+ with self.assertRaisesRegexp(ValueError, errmsg, msg=msg), \
+ test_support.check_py3k_warnings(quiet=True):
 float(f('A' * 0x10))
 
 def test_float_buffer(self):
- self.assertEqual(float(buffer('12.3', 1, 3)), 2.3)
- self.assertEqual(float(buffer('12.3\x00', 1, 3)), 2.3)
- self.assertEqual(float(buffer('12.3 ', 1, 3)), 2.3)
- self.assertEqual(float(buffer('12.3A', 1, 3)), 2.3)
- self.assertEqual(float(buffer('12.34', 1, 3)), 2.3)
+ with test_support.check_py3k_warnings():
+ self.assertEqual(float(buffer('12.3', 1, 3)), 2.3)
+ self.assertEqual(float(buffer('12.3\x00', 1, 3)), 2.3)
+ self.assertEqual(float(buffer('12.3 ', 1, 3)), 2.3)
+ self.assertEqual(float(buffer('12.3A', 1, 3)), 2.3)
+ self.assertEqual(float(buffer('12.34', 1, 3)), 2.3)
 
 def check_conversion_to_int(self, x):
 """Check that int(x) has the correct value and type, for a float x."""
diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -351,7 +351,8 @@
 factories += [unicode, CustomUnicode]
 
 for f in factories:
- x = f('100')
+ with test_support.check_py3k_warnings(quiet=True):
+ x = f('100')
 msg = 'x has value %s and type %s' % (x, type(x).__name__)
 try:
 self.assertEqual(int(x), 100, msg=msg)
@@ -365,15 +366,17 @@
 with self.assertRaisesRegexp(TypeError, errmsg, msg=msg):
 int(x, 2)
 errmsg = 'invalid literal'
- with self.assertRaisesRegexp(ValueError, errmsg, msg=msg):
+ with self.assertRaisesRegexp(ValueError, errmsg, msg=msg), \
+ test_support.check_py3k_warnings(quiet=True):
 int(f('A' * 0x10))
 
 def test_int_buffer(self):
- self.assertEqual(int(buffer('123', 1, 2)), 23)
- self.assertEqual(int(buffer('123\x00', 1, 2)), 23)
- self.assertEqual(int(buffer('123 ', 1, 2)), 23)
- self.assertEqual(int(buffer('123A', 1, 2)), 23)
- self.assertEqual(int(buffer('1234', 1, 2)), 23)
+ with test_support.check_py3k_warnings():
+ self.assertEqual(int(buffer('123', 1, 2)), 23)
+ self.assertEqual(int(buffer('123\x00', 1, 2)), 23)
+ self.assertEqual(int(buffer('123 ', 1, 2)), 23)
+ self.assertEqual(int(buffer('123A', 1, 2)), 23)
+ self.assertEqual(int(buffer('1234', 1, 2)), 23)
 
 def test_error_on_string_float_for_x(self):
 self.assertRaises(ValueError, int, '1.2')
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /