From 43e9007767618aac7d6c30228518ae375ebb3008 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sun, 29 Nov 2015 20:13:56 +0200 Subject: [PATCH] Fixed Py3k warnings in tests for issue #24731. --- 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 index 6a6ef0e146..c9f2835e3c 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -576,14 +576,15 @@ if 1: # objects are accepted, which could be not terminated. with self.assertRaisesRegexp(TypeError, "without null bytes"): compile(u"123\x00", "", "eval") - with self.assertRaisesRegexp(TypeError, "without null bytes"): - compile(buffer("123\x00"), "", "eval") - code = compile(buffer("123\x00", 1, 2), "", "eval") - self.assertEqual(eval(code), 23) - code = compile(buffer("1234", 1, 2), "", "eval") - self.assertEqual(eval(code), 23) - code = compile(buffer("$23$", 1, 2), "", "eval") - self.assertEqual(eval(code), 23) + with test_support.check_py3k_warnings(): + with self.assertRaisesRegexp(TypeError, "without null bytes"): + compile(buffer("123\x00"), "", "eval") + code = compile(buffer("123\x00", 1, 2), "", "eval") + self.assertEqual(eval(code), 23) + code = compile(buffer("1234", 1, 2), "", "eval") + self.assertEqual(eval(code), 23) + code = compile(buffer("$23$", 1, 2), "", "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 index 4ec894cd45..c917c1ea45 100644 --- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -71,7 +71,8 @@ class GeneralFloatCases(unittest.TestCase): 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 @@ class GeneralFloatCases(unittest.TestCase): 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 index 0dd8efc53f..ea5c0e3f48 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -351,7 +351,8 @@ class IntTestCases(IntLongCommonTests, unittest.TestCase): 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 @@ class IntTestCases(IntLongCommonTests, unittest.TestCase): 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') -- 2.50.1