1352
1353
class TestTestCase(TestCase):
1353
1354
"""Tests that test the core bzrlib TestCase."""
1356
def test_assertLength_matches_empty(self):
1358
self.assertLength(0, a_list)
1360
def test_assertLength_matches_nonempty(self):
1362
self.assertLength(3, a_list)
1364
def test_assertLength_fails_different(self):
1366
self.assertRaises(AssertionError, self.assertLength, 1, a_list)
1368
def test_assertLength_shows_sequence_in_failure(self):
1370
exception = self.assertRaises(AssertionError, self.assertLength, 2,
1372
self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
1375
def test_base_setUp_not_called_causes_failure(self):
1376
class TestCaseWithBrokenSetUp(TestCase):
1378
pass # does not call TestCase.setUp
1381
test = TestCaseWithBrokenSetUp('test_foo')
1382
result = unittest.TestResult()
1384
self.assertFalse(result.wasSuccessful())
1385
self.assertEqual(1, result.testsRun)
1387
def test_base_tearDown_not_called_causes_failure(self):
1388
class TestCaseWithBrokenTearDown(TestCase):
1390
pass # does not call TestCase.tearDown
1393
test = TestCaseWithBrokenTearDown('test_foo')
1394
result = unittest.TestResult()
1396
self.assertFalse(result.wasSuccessful())
1397
self.assertEqual(1, result.testsRun)
1355
1399
def test_debug_flags_sanitised(self):
1356
1400
"""The bzrlib debug flags should be sanitised by setUp."""
1357
1401
if 'allow_debug' in tests.selftest_debug_flags:
1652
1697
def test_applyDeprecated_not_deprecated(self):
1653
1698
sample_object = ApplyDeprecatedHelper()
1654
1699
# calling an undeprecated callable raises an assertion
1655
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1700
self.assertRaises(AssertionError, self.applyDeprecated,
1701
deprecated_in((0, 11, 0)),
1656
1702
sample_object.sample_normal_method)
1657
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1703
self.assertRaises(AssertionError, self.applyDeprecated,
1704
deprecated_in((0, 11, 0)),
1658
1705
sample_undeprecated_function, "a param value")
1659
1706
# calling a deprecated callable (function or method) with the wrong
1660
1707
# expected deprecation fails.
1661
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1708
self.assertRaises(AssertionError, self.applyDeprecated,
1709
deprecated_in((0, 10, 0)),
1662
1710
sample_object.sample_deprecated_method, "a param value")
1663
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1711
self.assertRaises(AssertionError, self.applyDeprecated,
1712
deprecated_in((0, 10, 0)),
1664
1713
sample_deprecated_function)
1665
1714
# calling a deprecated callable (function or method) with the right
1666
1715
# expected deprecation returns the functions result.
1667
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
1716
self.assertEqual("a param value",
1717
self.applyDeprecated(deprecated_in((0, 11, 0)),
1668
1718
sample_object.sample_deprecated_method, "a param value"))
1669
self.assertEqual(2, self.applyDeprecated(zero_eleven,
1719
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1670
1720
sample_deprecated_function))
1671
1721
# calling a nested deprecation with the wrong deprecation version
1672
1722
# fails even if a deeper nested function was deprecated with the
1673
1723
# supplied version.
1674
1724
self.assertRaises(AssertionError, self.applyDeprecated,
1675
zero_eleven, sample_object.sample_nested_deprecation)
1725
deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1676
1726
# calling a nested deprecation with the right deprecation value
1677
1727
# returns the calls result.
1678
self.assertEqual(2, self.applyDeprecated(zero_ten,
1728
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1679
1729
sample_object.sample_nested_deprecation))
1681
1731
def test_callDeprecated(self):