619
621
# But we have a safety net in place.
620
622
self.assertRaises(AssertionError, self._check_safety_net)
624
def test_dangling_locks_cause_failures(self):
625
class TestDanglingLock(TestCaseWithMemoryTransport):
626
def test_function(self):
627
t = self.get_transport('.')
628
l = lockdir.LockDir(t, 'lock')
631
test = TestDanglingLock('test_function')
633
self.assertEqual(1, len(result.errors))
623
636
class TestTestCaseWithTransport(TestCaseWithTransport):
624
637
"""Tests for the convenience functions TestCaseWithTransport introduces."""
1037
1054
self.assertTrue(result.wasStrictlySuccessful())
1038
1055
self.assertEqual(None, result._extractBenchmarkTime(test))
1057
def test_startTests(self):
1058
"""Starting the first test should trigger startTests."""
1059
class InstrumentedTestResult(ExtendedTestResult):
1061
def startTests(self): self.calls += 1
1062
def report_test_start(self, test): pass
1063
result = InstrumentedTestResult(None, None, None, None)
1064
def test_function():
1066
test = unittest.FunctionTestCase(test_function)
1068
self.assertEquals(1, result.calls)
1041
1071
class TestUnicodeFilenameFeature(TestCase):
1352
1383
class TestTestCase(TestCase):
1353
1384
"""Tests that test the core bzrlib TestCase."""
1386
def test_assertLength_matches_empty(self):
1388
self.assertLength(0, a_list)
1390
def test_assertLength_matches_nonempty(self):
1392
self.assertLength(3, a_list)
1394
def test_assertLength_fails_different(self):
1396
self.assertRaises(AssertionError, self.assertLength, 1, a_list)
1398
def test_assertLength_shows_sequence_in_failure(self):
1400
exception = self.assertRaises(AssertionError, self.assertLength, 2,
1402
self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
1405
def test_base_setUp_not_called_causes_failure(self):
1406
class TestCaseWithBrokenSetUp(TestCase):
1408
pass # does not call TestCase.setUp
1411
test = TestCaseWithBrokenSetUp('test_foo')
1412
result = unittest.TestResult()
1414
self.assertFalse(result.wasSuccessful())
1415
self.assertEqual(1, result.testsRun)
1417
def test_base_tearDown_not_called_causes_failure(self):
1418
class TestCaseWithBrokenTearDown(TestCase):
1420
pass # does not call TestCase.tearDown
1423
test = TestCaseWithBrokenTearDown('test_foo')
1424
result = unittest.TestResult()
1426
self.assertFalse(result.wasSuccessful())
1427
self.assertEqual(1, result.testsRun)
1355
1429
def test_debug_flags_sanitised(self):
1356
1430
"""The bzrlib debug flags should be sanitised by setUp."""
1357
1431
if 'allow_debug' in tests.selftest_debug_flags:
1652
1727
def test_applyDeprecated_not_deprecated(self):
1653
1728
sample_object = ApplyDeprecatedHelper()
1654
1729
# calling an undeprecated callable raises an assertion
1655
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1730
self.assertRaises(AssertionError, self.applyDeprecated,
1731
deprecated_in((0, 11, 0)),
1656
1732
sample_object.sample_normal_method)
1657
self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
1733
self.assertRaises(AssertionError, self.applyDeprecated,
1734
deprecated_in((0, 11, 0)),
1658
1735
sample_undeprecated_function, "a param value")
1659
1736
# calling a deprecated callable (function or method) with the wrong
1660
1737
# expected deprecation fails.
1661
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1738
self.assertRaises(AssertionError, self.applyDeprecated,
1739
deprecated_in((0, 10, 0)),
1662
1740
sample_object.sample_deprecated_method, "a param value")
1663
self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
1741
self.assertRaises(AssertionError, self.applyDeprecated,
1742
deprecated_in((0, 10, 0)),
1664
1743
sample_deprecated_function)
1665
1744
# calling a deprecated callable (function or method) with the right
1666
1745
# expected deprecation returns the functions result.
1667
self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
1746
self.assertEqual("a param value",
1747
self.applyDeprecated(deprecated_in((0, 11, 0)),
1668
1748
sample_object.sample_deprecated_method, "a param value"))
1669
self.assertEqual(2, self.applyDeprecated(zero_eleven,
1749
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 11, 0)),
1670
1750
sample_deprecated_function))
1671
1751
# calling a nested deprecation with the wrong deprecation version
1672
1752
# fails even if a deeper nested function was deprecated with the
1673
1753
# supplied version.
1674
1754
self.assertRaises(AssertionError, self.applyDeprecated,
1675
zero_eleven, sample_object.sample_nested_deprecation)
1755
deprecated_in((0, 11, 0)), sample_object.sample_nested_deprecation)
1676
1756
# calling a nested deprecation with the right deprecation value
1677
1757
# returns the calls result.
1678
self.assertEqual(2, self.applyDeprecated(zero_ten,
1758
self.assertEqual(2, self.applyDeprecated(deprecated_in((0, 10, 0)),
1679
1759
sample_object.sample_nested_deprecation))
1681
1761
def test_callDeprecated(self):
2297
2378
calls.append(test)
2298
2379
return ExtendedTestResult(self.stream, self.descriptions,
2299
2380
self.verbosity)
2300
run_suite(suite, runner_class=MyRunner)
2381
run_suite(suite, runner_class=MyRunner, stream=StringIO())
2301
2382
self.assertEqual(calls, [suite])
2384
def test_done(self):
2385
"""run_suite should call result.done()"""
2387
def one_more_call(): self.calls += 1
2388
def test_function():
2390
test = unittest.FunctionTestCase(test_function)
2391
class InstrumentedTestResult(ExtendedTestResult):
2392
def done(self): one_more_call()
2393
class MyRunner(TextTestRunner):
2394
def run(self, test):
2395
return InstrumentedTestResult(self.stream, self.descriptions,
2397
run_suite(test, runner_class=MyRunner, stream=StringIO())
2398
self.assertEquals(1, self.calls)