Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
unittest.test.test_assertions.TestLongMessage Class Reference

List of all members.

Public Member Functions

def setUp
def testDefault
def test_formatMsg
def test_formatMessage_unicode_error
def assertMessages
def testAssertTrue
def testAssertFalse
def testNotEqual
def testAlmostEqual
def testNotAlmostEqual
def test_baseAssertEqual
def testAssertSequenceEqual
def testAssertSetEqual
def testAssertIn
def testAssertNotIn
def testAssertDictEqual
def testAssertDictContainsSubset
def testAssertMultiLineEqual
def testAssertLess
def testAssertLessEqual
def testAssertGreater
def testAssertGreaterEqual
def testAssertIsNone
def testAssertIsNotNone
def testAssertIs
def testAssertIsNot

Public Attributes

 testableTrue
 testableFalse

Detailed Description

Test that the individual asserts honour longMessage.
This actually tests all the message behaviour for
asserts that use longMessage.

Definition at line 106 of file test_assertions.py.


Member Function Documentation

def unittest.test.test_assertions.TestLongMessage.assertMessages (   self,
  methodName,
  args,
  errors 
)

Definition at line 147 of file test_assertions.py.

00147 
00148     def assertMessages(self, methodName, args, errors):
00149         def getMethod(i):
00150             useTestableFalse  = i < 2
00151             if useTestableFalse:
00152                 test = self.testableFalse
00153             else:
00154                 test = self.testableTrue
00155             return getattr(test, methodName)
00156 
00157         for i, expected_regex in enumerate(errors):
00158             testMethod = getMethod(i)
00159             kwargs = {}
00160             withMsg = i % 2
00161             if withMsg:
00162                 kwargs = {"msg": "oops"}
00163 
00164             with self.assertRaisesRegex(self.failureException,
00165                                         expected_regex=expected_regex):
00166                 testMethod(*args, **kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 111 of file test_assertions.py.

00111 
00112     def setUp(self):
00113         class TestableTestFalse(unittest.TestCase):
00114             longMessage = False
00115             failureException = self.failureException
00116 
00117             def testTest(self):
00118                 pass
00119 
00120         class TestableTestTrue(unittest.TestCase):
00121             longMessage = True
00122             failureException = self.failureException
00123 
00124             def testTest(self):
00125                 pass
00126 
00127         self.testableTrue = TestableTestTrue('testTest')
00128         self.testableFalse = TestableTestFalse('testTest')

Definition at line 192 of file test_assertions.py.

00192 
00193     def test_baseAssertEqual(self):
00194         self.assertMessages('_baseAssertEqual', (1, 2),
00195                             ["^1 != 2$", "^oops$", "^1 != 2$", "^1 != 2 : oops$"])

Here is the call graph for this function:

Definition at line 142 of file test_assertions.py.

00142 
00143     def test_formatMessage_unicode_error(self):
00144         one = ''.join(chr(i) for i in range(255))
00145         # this used to cause a UnicodeDecodeError constructing msg
00146         self.testableTrue._formatMessage(one, '\uFFFD')

Here is the call graph for this function:

Definition at line 132 of file test_assertions.py.

00132 
00133     def test_formatMsg(self):
00134         self.assertEqual(self.testableFalse._formatMessage(None, "foo"), "foo")
00135         self.assertEqual(self.testableFalse._formatMessage("foo", "bar"), "foo")
00136 
00137         self.assertEqual(self.testableTrue._formatMessage(None, "foo"), "foo")
00138         self.assertEqual(self.testableTrue._formatMessage("foo", "bar"), "bar : foo")
00139 
00140         # This blows up if _formatMessage uses string concatenation
00141         self.testableTrue._formatMessage(object(), 'foo')

Here is the call graph for this function:

Definition at line 182 of file test_assertions.py.

00182 
00183     def testAlmostEqual(self):
00184         self.assertMessages('assertAlmostEqual', (1, 2),
00185                             ["^1 != 2 within 7 places$", "^oops$",
00186                              "^1 != 2 within 7 places$", "^1 != 2 within 7 places : oops$"])

Here is the call graph for this function:

Definition at line 226 of file test_assertions.py.

00226 
00227     def testAssertDictContainsSubset(self):
00228         with warnings.catch_warnings():
00229             warnings.simplefilter("ignore", DeprecationWarning)
00230 
00231             self.assertMessages('assertDictContainsSubset', ({'key': 'value'}, {}),
00232                                 ["^Missing: 'key'$", "^oops$",
00233                                  "^Missing: 'key'$",
00234                                  "^Missing: 'key' : oops$"])

Here is the call graph for this function:

Definition at line 220 of file test_assertions.py.

00220 
00221     def testAssertDictEqual(self):
00222         self.assertMessages('assertDictEqual', ({}, {'key': 'value'}),
00223                             [r"\+ \{'key': 'value'\}$", "^oops$",
00224                              "\+ \{'key': 'value'\}$",
00225                              "\+ \{'key': 'value'\} : oops$"])

Here is the call graph for this function:

Definition at line 172 of file test_assertions.py.

00172 
00173     def testAssertFalse(self):
00174         self.assertMessages('assertFalse', (True,),
00175                             ["^True is not false$", "^oops$", "^True is not false$",
00176                              "^True is not false : oops$"])

Here is the call graph for this function:

Definition at line 252 of file test_assertions.py.

00252 
00253     def testAssertGreater(self):
00254         self.assertMessages('assertGreater', (1, 2),
00255                             ["^1 not greater than 2$", "^oops$",
00256                              "^1 not greater than 2$",
00257                              "^1 not greater than 2 : oops$"])

Here is the call graph for this function:

Definition at line 258 of file test_assertions.py.

00258 
00259     def testAssertGreaterEqual(self):
00260         self.assertMessages('assertGreaterEqual', (1, 2),
00261                             ["^1 not greater than or equal to 2$", "^oops$",
00262                              "^1 not greater than or equal to 2$",
00263                              "^1 not greater than or equal to 2 : oops$"])

Here is the call graph for this function:

Definition at line 208 of file test_assertions.py.

00208 
00209     def testAssertIn(self):
00210         self.assertMessages('assertIn', (None, []),
00211                             ['^None not found in \[\]$', "^oops$",
00212                              '^None not found in \[\]$',
00213                              '^None not found in \[\] : oops$'])

Here is the call graph for this function:

Definition at line 276 of file test_assertions.py.

00276 
00277     def testAssertIs(self):
00278         self.assertMessages('assertIs', (None, 'foo'),
00279                             ["^None is not 'foo'$", "^oops$",
00280                              "^None is not 'foo'$",
00281                              "^None is not 'foo' : oops$"])

Here is the call graph for this function:

Definition at line 264 of file test_assertions.py.

00264 
00265     def testAssertIsNone(self):
00266         self.assertMessages('assertIsNone', ('not None',),
00267                             ["^'not None' is not None$", "^oops$",
00268                              "^'not None' is not None$",
00269                              "^'not None' is not None : oops$"])

Here is the call graph for this function:

Definition at line 282 of file test_assertions.py.

00282 
00283     def testAssertIsNot(self):
00284         self.assertMessages('assertIsNot', (None, None),
00285                             ["^unexpectedly identical: None$", "^oops$",
00286                              "^unexpectedly identical: None$",
00287                              "^unexpectedly identical: None : oops$"])

Here is the call graph for this function:

Definition at line 270 of file test_assertions.py.

00270 
00271     def testAssertIsNotNone(self):
00272         self.assertMessages('assertIsNotNone', (None,),
00273                             ["^unexpectedly None$", "^oops$",
00274                              "^unexpectedly None$",
00275                              "^unexpectedly None : oops$"])

Here is the call graph for this function:

Definition at line 241 of file test_assertions.py.

00241 
00242     def testAssertLess(self):
00243         self.assertMessages('assertLess', (2, 1),
00244                             ["^2 not less than 1$", "^oops$",
00245                              "^2 not less than 1$", "^2 not less than 1 : oops$"])

Here is the call graph for this function:

Definition at line 246 of file test_assertions.py.

00246 
00247     def testAssertLessEqual(self):
00248         self.assertMessages('assertLessEqual', (2, 1),
00249                             ["^2 not less than or equal to 1$", "^oops$",
00250                              "^2 not less than or equal to 1$",
00251                              "^2 not less than or equal to 1 : oops$"])

Here is the call graph for this function:

Definition at line 235 of file test_assertions.py.

00235 
00236     def testAssertMultiLineEqual(self):
00237         self.assertMessages('assertMultiLineEqual', ("", "foo"),
00238                             [r"\+ foo$", "^oops$",
00239                              r"\+ foo$",
00240                              r"\+ foo : oops$"])

Here is the call graph for this function:

Definition at line 214 of file test_assertions.py.

00214 
00215     def testAssertNotIn(self):
00216         self.assertMessages('assertNotIn', (None, [None]),
00217                             ['^None unexpectedly found in \[None\]$', "^oops$",
00218                              '^None unexpectedly found in \[None\]$',
00219                              '^None unexpectedly found in \[None\] : oops$'])

Here is the call graph for this function:

Definition at line 196 of file test_assertions.py.

00196 
00197     def testAssertSequenceEqual(self):
00198         # Error messages are multiline so not testing on full message
00199         # assertTupleEqual and assertListEqual delegate to this method
00200         self.assertMessages('assertSequenceEqual', ([], [None]),
00201                             ["\+ \[None\]$", "^oops$", r"\+ \[None\]$",
00202                              r"\+ \[None\] : oops$"])

Here is the call graph for this function:

Definition at line 203 of file test_assertions.py.

00203 
00204     def testAssertSetEqual(self):
00205         self.assertMessages('assertSetEqual', (set(), set([None])),
00206                             ["None$", "^oops$", "None$",
00207                              "None : oops$"])

Here is the call graph for this function:

Definition at line 167 of file test_assertions.py.

00167 
00168     def testAssertTrue(self):
00169         self.assertMessages('assertTrue', (False,),
00170                             ["^False is not true$", "^oops$", "^False is not true$",
00171                              "^False is not true : oops$"])

Here is the call graph for this function:

Definition at line 129 of file test_assertions.py.

00129 
00130     def testDefault(self):
00131         self.assertTrue(unittest.TestCase.longMessage)

Here is the call graph for this function:

Definition at line 187 of file test_assertions.py.

00187 
00188     def testNotAlmostEqual(self):
00189         self.assertMessages('assertNotAlmostEqual', (1, 1),
00190                             ["^1 == 1 within 7 places$", "^oops$",
00191                              "^1 == 1 within 7 places$", "^1 == 1 within 7 places : oops$"])

Here is the call graph for this function:

Definition at line 177 of file test_assertions.py.

00177 
00178     def testNotEqual(self):
00179         self.assertMessages('assertNotEqual', (1, 1),
00180                             ["^1 == 1$", "^oops$", "^1 == 1$",
00181                              "^1 == 1 : oops$"])

Here is the call graph for this function:


Member Data Documentation

Definition at line 127 of file test_assertions.py.

Definition at line 126 of file test_assertions.py.


The documentation for this class was generated from the following file: