From cae969e70afd4e02d9543c3a18f089a1c66de982 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 3 Jan 2011 23:56:12 +0000 Subject: [PATCH] fix test_unittest: ignore DeprecationWarning on assertDictContainsSubset() --- Lib/unittest/test/test_assertions.py | 13 +++++---- Lib/unittest/test/test_case.py | 41 +++++++++++++++------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py index e5dc9faf3a..a1d20ebf2d 100644 --- a/Lib/unittest/test/test_assertions.py +++ b/Lib/unittest/test/test_assertions.py @@ -1,5 +1,5 @@ import datetime - +import warnings import unittest @@ -224,10 +224,13 @@ class TestLongMessage(unittest.TestCase): "\+ \{'key': 'value'\} : oops$"]) def testAssertDictContainsSubset(self): - self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}), - ["^Missing: 'key'$", "^oops$", - "^Missing: 'key'$", - "^Missing: 'key' : oops$"]) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + + self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}), + ["^Missing: 'key'$", "^oops$", + "^Missing: 'key'$", + "^Missing: 'key' : oops$"]) def testAssertMultiLineEqual(self): self.assertMessages('assertMultiLineEqual', ("", "foo"), diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 1513fbecb7..314aef3ac7 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -489,31 +489,34 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing): animals) def testAssertDictContainsSubset(self): - self.assertDictContainsSubset({}, {}) - self.assertDictContainsSubset({}, {'a': 1}) - self.assertDictContainsSubset({'a': 1}, {'a': 1}) - self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2}) - self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2}) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({1: "one"}, {}) + self.assertDictContainsSubset({}, {}) + self.assertDictContainsSubset({}, {'a': 1}) + self.assertDictContainsSubset({'a': 1}, {'a': 1}) + self.assertDictContainsSubset({'a': 1}, {'a': 1, 'b': 2}) + self.assertDictContainsSubset({'a': 1, 'b': 2}, {'a': 1, 'b': 2}) - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({'a': 2}, {'a': 1}) + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({1: "one"}, {}) - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({'c': 1}, {'a': 1}) + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'a': 2}, {'a': 1}) - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1}) + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'c': 1}, {'a': 1}) - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1}) + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1}) - one = ''.join(chr(i) for i in range(255)) - # this used to cause a UnicodeDecodeError constructing the failure msg - with self.assertRaises(self.failureException): - self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'}) + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'a': 1, 'c': 1}, {'a': 1}) + + one = ''.join(chr(i) for i in range(255)) + # this used to cause a UnicodeDecodeError constructing the failure msg + with self.assertRaises(self.failureException): + self.assertDictContainsSubset({'foo': one}, {'foo': '\uFFFD'}) def testAssertEqual(self): equal_pairs = [ -- 2.40.0