1cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hyltonimport datetime
23e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
33e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hyltonimport unittest
4cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton
5cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton
6cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hyltonclass Test_Assertions(unittest.TestCase):
75d0ad50f5acf84f2e8a1ca5c6951f333aef0e25aNeal Norwitz    def test_AlmostEqual(self):
83e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertAlmostEqual(1.00000001, 1.0)
93e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertNotAlmostEqual(1.0000001, 1.0)
102990640d8af1d1fd6ba264ced46e741b9dc091d0Jeremy Hylton        self.assertRaises(self.failureException,
113e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                          self.assertAlmostEqual, 1.0000001, 1.0)
123e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertRaises(self.failureException,
132990640d8af1d1fd6ba264ced46e741b9dc091d0Jeremy Hylton                          self.assertNotAlmostEqual, 1.00000001, 1.0)
145d0ad50f5acf84f2e8a1ca5c6951f333aef0e25aNeal Norwitz
155d0ad50f5acf84f2e8a1ca5c6951f333aef0e25aNeal Norwitz        self.assertAlmostEqual(1.1, 1.0, places=0)
16ddbaa660d3b64a71b4ac9eab64b1bb944ca1276bGeorg Brandl        self.assertRaises(self.failureException,
17ddbaa660d3b64a71b4ac9eab64b1bb944ca1276bGeorg Brandl                          self.assertAlmostEqual, 1.1, 1.0, places=1)
185d0ad50f5acf84f2e8a1ca5c6951f333aef0e25aNeal Norwitz
19e0d12eb85cff367497090b1fdc58582edc0d4c99Benjamin Peterson        self.assertAlmostEqual(0, .1+.1j, places=0)
20090b3dde06c7590ed7d789bd01a7d800cc09a348Neal Norwitz        self.assertNotAlmostEqual(0, .1+.1j, places=1)
21e0d12eb85cff367497090b1fdc58582edc0d4c99Benjamin Peterson        self.assertRaises(self.failureException,
22c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          self.assertAlmostEqual, 0, .1+.1j, places=1)
23cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        self.assertRaises(self.failureException,
24c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          self.assertNotAlmostEqual, 0, .1+.1j, places=0)
258c1bce00d25ddda20d4e760e5771324865ddae17Christian Heimes
26c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertAlmostEqual(float('inf'), float('inf'))
27c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(self.failureException, self.assertNotAlmostEqual,
28c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          float('inf'), float('inf'))
29c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
30c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def test_AmostEqualWithDelta(self):
31dfaf90da9c4a9a4f7dd7bd716fa0695d32bbd91fChristian Heimes        self.assertAlmostEqual(1.1, 1.0, delta=0.5)
32dfaf90da9c4a9a4f7dd7bd716fa0695d32bbd91fChristian Heimes        self.assertAlmostEqual(1.0, 1.1, delta=0.5)
33c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertNotAlmostEqual(1.1, 1.0, delta=0.05)
34dfaf90da9c4a9a4f7dd7bd716fa0695d32bbd91fChristian Heimes        self.assertNotAlmostEqual(1.0, 1.1, delta=0.05)
35c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
3665a0141e146aba6e2ae2b82d39d016ab03b8c7e2Christian Heimes        self.assertAlmostEqual(1.0, 1.0, delta=0.5)
37c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(self.failureException, self.assertNotAlmostEqual,
38c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          1.0, 1.0, delta=0.5)
39c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
40c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(self.failureException, self.assertAlmostEqual,
41c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          1.1, 1.0, delta=0.05)
42c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(self.failureException, self.assertNotAlmostEqual,
43c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          1.1, 1.0, delta=0.5)
44c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
45c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(TypeError, self.assertAlmostEqual,
46c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          1.1, 1.0, places=2, delta=2)
47c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(TypeError, self.assertNotAlmostEqual,
48c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                          1.1, 1.0, places=2, delta=2)
49c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
50c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        first = datetime.datetime.now()
51c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        second = first + datetime.timedelta(seconds=10)
52c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertAlmostEqual(first, second,
53c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                               delta=datetime.timedelta(seconds=20))
54c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertNotAlmostEqual(first, second,
55c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                                  delta=datetime.timedelta(seconds=5))
56c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
57c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def test_assertRaises(self):
58c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        def _raise(e):
59c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            raise e
60c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(KeyError, _raise, KeyError)
61c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertRaises(KeyError, _raise, KeyError("key"))
62c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        try:
63c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertRaises(KeyError, lambda: None)
64045bbcdc8e1c745e49d3f4b0d79ca8182375bce0Benjamin Peterson        except self.failureException as e:
65c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertIn("KeyError not raised", e.args)
66c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        else:
67c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.fail("assertRaises() didn't fail")
68c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        try:
69c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertRaises(KeyError, _raise, ValueError)
70c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        except ValueError:
71c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            pass
72c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        else:
73c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.fail("assertRaises() didn't let exception pass through")
74c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        with self.assertRaises(KeyError) as cm:
75c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            try:
76c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                raise KeyError
77c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            except Exception, e:
78c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                raise
79cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        self.assertIs(cm.exception, e)
80c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
81c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        with self.assertRaises(KeyError):
82cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            raise KeyError("key")
83cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        try:
84cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            with self.assertRaises(KeyError):
853e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                pass
86cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        except self.failureException as e:
87c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertIn("KeyError not raised", e.args)
88cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        else:
89c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.fail("assertRaises() didn't fail")
90c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        try:
91c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            with self.assertRaises(KeyError):
92c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                raise ValueError
93c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        except ValueError:
94cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            pass
95cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        else:
96cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            self.fail("assertRaises() didn't let exception pass through")
973e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
98cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton    def testAssertNotRegexpMatches(self):
99c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertNotRegexpMatches('Ala ma kota', r'r+')
100c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        try:
101c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertNotRegexpMatches('Ala ma kota', r'k.t', 'Message')
102c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        except self.failureException, e:
103c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertIn("'kot'", e.args[0])
104c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            self.assertIn('Message', e.args[0])
105c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        else:
106cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            self.fail('assertNotRegexpMatches should have failed.')
107cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton
1083e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
109cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hyltonclass TestLongMessage(unittest.TestCase):
1106f7993765ac0989b5d13084240797913627a31d8Guido van Rossum    """Test that the individual asserts honour longMessage.
111c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    This actually tests all the message behaviour for
112c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    asserts that use longMessage."""
113c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
114c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def setUp(self):
115c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        class TestableTestFalse(unittest.TestCase):
116c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            longMessage = False
117c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            failureException = self.failureException
118c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
119c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            def testTest(self):
120c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                pass
121cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton
122cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton        class TestableTestTrue(unittest.TestCase):
1233e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton            longMessage = True
124c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            failureException = self.failureException
125c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
126c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            def testTest(self):
127c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                pass
128c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
129c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.testableTrue = TestableTestTrue('testTest')
130c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.testableFalse = TestableTestFalse('testTest')
131c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
132c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testDefault(self):
133c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertFalse(unittest.TestCase.longMessage)
134c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
135c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def test_formatMsg(self):
136c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertEqual(self.testableFalse._formatMessage(None, "foo"), "foo")
137c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertEqual(self.testableFalse._formatMessage("foo", "bar"), "foo")
138c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
139c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertEqual(self.testableTrue._formatMessage(None, "foo"), "foo")
140c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertEqual(self.testableTrue._formatMessage("foo", "bar"), "bar : foo")
141c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
142c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        # This blows up if _formatMessage uses string concatenation
143c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.testableTrue._formatMessage(object(), 'foo')
144c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
145c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def test_formatMessage_unicode_error(self):
146c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        one = ''.join(chr(i) for i in range(255))
147c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        # this used to cause a UnicodeDecodeError constructing msg
148c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.testableTrue._formatMessage(one, u'\uFFFD')
149c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
150c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def assertMessages(self, methodName, args, errors):
151c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        def getMethod(i):
152c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            useTestableFalse  = i < 2
153c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            if useTestableFalse:
154c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                test = self.testableFalse
155c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            else:
156c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                test = self.testableTrue
157c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            return getattr(test, methodName)
158c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
159c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        for i, expected_regexp in enumerate(errors):
160c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            testMethod = getMethod(i)
161c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            kwargs = {}
162cb17ae8b19c35cc63e7daec871c025d903c49105Jeremy Hylton            withMsg = i % 2
1633e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton            if withMsg:
1643e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                kwargs = {"msg": "oops"}
1655d0ad50f5acf84f2e8a1ca5c6951f333aef0e25aNeal Norwitz
166c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou            with self.assertRaisesRegexp(self.failureException,
167c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                                         expected_regexp=expected_regexp):
1683e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                testMethod(*args, **kwargs)
1693e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
1703e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertTrue(self):
1713e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertTrue', (False,),
172b646547bb45fe1df6abefd94f892c633798d91d2Alexandre Vassalotti                            ["^False is not true$", "^oops$", "^False is not true$",
173b646547bb45fe1df6abefd94f892c633798d91d2Alexandre Vassalotti                             "^False is not true : oops$"])
1743e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
1753e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertFalse(self):
1763e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertFalse', (True,),
1773e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^True is not false$", "^oops$", "^True is not false$",
1783e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^True is not false : oops$"])
1793e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
1803e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testNotEqual(self):
1813e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertNotEqual', (1, 1),
1823e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^1 == 1$", "^oops$", "^1 == 1$",
1833e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^1 == 1 : oops$"])
1843e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
185b646547bb45fe1df6abefd94f892c633798d91d2Alexandre Vassalotti    def testAlmostEqual(self):
186c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertAlmostEqual', (1, 2),
1873e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^1 != 2 within 7 places$", "^oops$",
1883e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^1 != 2 within 7 places$", "^1 != 2 within 7 places : oops$"])
189c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
1903e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testNotAlmostEqual(self):
1913e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertNotAlmostEqual', (1, 1),
1923e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^1 == 1 within 7 places$", "^oops$",
1933e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^1 == 1 within 7 places$", "^1 == 1 within 7 places : oops$"])
1943e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
1953e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def test_baseAssertEqual(self):
1963e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('_baseAssertEqual', (1, 2),
197c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^1 != 2$", "^oops$", "^1 != 2$", "^1 != 2 : oops$"])
198c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
199c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertSequenceEqual(self):
200c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        # Error messages are multiline so not testing on full message
201c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        # assertTupleEqual and assertListEqual delegate to this method
202c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertSequenceEqual', ([], [None]),
203c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["\+ \[None\]$", "^oops$", r"\+ \[None\]$",
204c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             r"\+ \[None\] : oops$"])
205c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
206c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertSetEqual(self):
207c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertSetEqual', (set(), set([None])),
208c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["None$", "^oops$", "None$",
209c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "None : oops$"])
210c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
211c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertIn(self):
212c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertIn', (None, []),
2133e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ['^None not found in \[\]$', "^oops$",
214c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             '^None not found in \[\]$',
215c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             '^None not found in \[\] : oops$'])
2163e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
2173e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertNotIn(self):
2183e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertNotIn', (None, [None]),
2193e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ['^None unexpectedly found in \[None\]$', "^oops$",
2203e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             '^None unexpectedly found in \[None\]$',
221c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             '^None unexpectedly found in \[None\] : oops$'])
222c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
223c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertDictEqual(self):
224c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertDictEqual', ({}, {'key': 'value'}),
225c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            [r"\+ \{'key': 'value'\}$", "^oops$",
226c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "\+ \{'key': 'value'\}$",
227c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "\+ \{'key': 'value'\} : oops$"])
228c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
229c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertDictContainsSubset(self):
230c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}),
231c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^Missing: 'key'$", "^oops$",
232c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^Missing: 'key'$",
233c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^Missing: 'key' : oops$"])
234c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
235c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertMultiLineEqual(self):
236c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertMultiLineEqual', ("", "foo"),
237c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            [r"\+ foo$", "^oops$",
238c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             r"\+ foo$",
239c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             r"\+ foo : oops$"])
240c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
241c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertLess(self):
242c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertLess', (2, 1),
243c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^2 not less than 1$", "^oops$",
244c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^2 not less than 1$", "^2 not less than 1 : oops$"])
245c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
246c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertLessEqual(self):
247c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertLessEqual', (2, 1),
248c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^2 not less than or equal to 1$", "^oops$",
249c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^2 not less than or equal to 1$",
250c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^2 not less than or equal to 1 : oops$"])
251c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
252c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertGreater(self):
253c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertGreater', (1, 2),
254c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^1 not greater than 2$", "^oops$",
255c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^1 not greater than 2$",
256c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^1 not greater than 2 : oops$"])
257c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
258c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertGreaterEqual(self):
259c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertGreaterEqual', (1, 2),
260c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^1 not greater than or equal to 2$", "^oops$",
261c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^1 not greater than or equal to 2$",
262c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^1 not greater than or equal to 2 : oops$"])
263c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
264c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    def testAssertIsNone(self):
265c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertIsNone', ('not None',),
266c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^'not None' is not None$", "^oops$",
267c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^'not None' is not None$",
268c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^'not None' is not None : oops$"])
269c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
2703e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertIsNotNone(self):
271c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou        self.assertMessages('assertIsNotNone', (None,),
272c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                            ["^unexpectedly None$", "^oops$",
273c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^unexpectedly None$",
2743e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^unexpectedly None : oops$"])
2753e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton
2763e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertIs(self):
2773e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertIs', (None, 'foo'),
2783e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^None is not 'foo'$", "^oops$",
279c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^None is not 'foo'$",
280c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou                             "^None is not 'foo' : oops$"])
281c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
2823e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton    def testAssertIsNot(self):
2833e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton        self.assertMessages('assertIsNot', (None, None),
2843e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                            ["^unexpectedly identical: None$", "^oops$",
2853e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^unexpectedly identical: None$",
2863e0055f8c65c407e74ce476b8e2b1fb889723514Jeremy Hylton                             "^unexpectedly identical: None : oops$"])
287c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
288c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou
289c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrouif __name__ == '__main__':
290c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou    unittest.main()
291c83ea137d7e717f764e2f31fc2544f522de7d857Antoine Pitrou