/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

MergeĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the test framework."""
18
18
 
43
43
    weaverepo,
44
44
    )
45
45
from bzrlib.symbol_versioning import (
46
 
    one_zero,
47
 
    zero_eleven,
48
 
    zero_ten,
 
46
    deprecated_function,
 
47
    deprecated_in,
 
48
    deprecated_method,
49
49
    )
50
50
from bzrlib.tests import (
51
51
                          ChrootedTestCase,
1150
1150
        class SkippedTest(TestCase):
1151
1151
 
1152
1152
            def setUp(self):
 
1153
                TestCase.setUp(self)
1153
1154
                calls.append('setUp')
1154
1155
                self.addCleanup(self.cleanup)
1155
1156
 
1352
1353
class TestTestCase(TestCase):
1353
1354
    """Tests that test the core bzrlib TestCase."""
1354
1355
 
 
1356
    def test_assertLength_matches_empty(self):
 
1357
        a_list = []
 
1358
        self.assertLength(0, a_list)
 
1359
 
 
1360
    def test_assertLength_matches_nonempty(self):
 
1361
        a_list = [1, 2, 3]
 
1362
        self.assertLength(3, a_list)
 
1363
 
 
1364
    def test_assertLength_fails_different(self):
 
1365
        a_list = []
 
1366
        self.assertRaises(AssertionError, self.assertLength, 1, a_list)
 
1367
 
 
1368
    def test_assertLength_shows_sequence_in_failure(self):
 
1369
        a_list = [1, 2, 3]
 
1370
        exception = self.assertRaises(AssertionError, self.assertLength, 2,
 
1371
            a_list)
 
1372
        self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
 
1373
            exception.args[0])
 
1374
 
 
1375
    def test_base_setUp_not_called_causes_failure(self):
 
1376
        class TestCaseWithBrokenSetUp(TestCase):
 
1377
            def setUp(self):
 
1378
                pass # does not call TestCase.setUp
 
1379
            def test_foo(self):
 
1380
                pass
 
1381
        test = TestCaseWithBrokenSetUp('test_foo')
 
1382
        result = unittest.TestResult()
 
1383
        test.run(result)
 
1384
        self.assertFalse(result.wasSuccessful())
 
1385
        self.assertEqual(1, result.testsRun)
 
1386
 
 
1387
    def test_base_tearDown_not_called_causes_failure(self):
 
1388
        class TestCaseWithBrokenTearDown(TestCase):
 
1389
            def tearDown(self):
 
1390
                pass # does not call TestCase.tearDown
 
1391
            def test_foo(self):
 
1392
                pass
 
1393
        test = TestCaseWithBrokenTearDown('test_foo')
 
1394
        result = unittest.TestResult()
 
1395
        test.run(result)
 
1396
        self.assertFalse(result.wasSuccessful())
 
1397
        self.assertEqual(1, result.testsRun)
 
1398
 
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:
1610
1654
            self.assertListRaises, _TestException, success_generator)
1611
1655
 
1612
1656
 
1613
 
@symbol_versioning.deprecated_function(zero_eleven)
 
1657
# NB: Don't delete this; it's not actually from 0.11!
 
1658
@deprecated_function(deprecated_in((0, 11, 0)))
1614
1659
def sample_deprecated_function():
1615
1660
    """A deprecated function to test applyDeprecated with."""
1616
1661
    return 2
1623
1668
class ApplyDeprecatedHelper(object):
1624
1669
    """A helper class for ApplyDeprecated tests."""
1625
1670
 
1626
 
    @symbol_versioning.deprecated_method(zero_eleven)
 
1671
    @deprecated_method(deprecated_in((0, 11, 0)))
1627
1672
    def sample_deprecated_method(self, param_one):
1628
1673
        """A deprecated method for testing with."""
1629
1674
        return param_one
1631
1676
    def sample_normal_method(self):
1632
1677
        """A undeprecated method."""
1633
1678
 
1634
 
    @symbol_versioning.deprecated_method(zero_ten)
 
1679
    @deprecated_method(deprecated_in((0, 10, 0)))
1635
1680
    def sample_nested_deprecation(self):
1636
1681
        return sample_deprecated_function()
1637
1682
 
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))
1680
1730
 
1681
1731
    def test_callDeprecated(self):
1823
1873
class TestSelftestFiltering(TestCase):
1824
1874
 
1825
1875
    def setUp(self):
 
1876
        TestCase.setUp(self)
1826
1877
        self.suite = TestUtil.TestSuite()
1827
1878
        self.loader = TestUtil.TestLoader()
1828
1879
        self.suite.addTest(self.loader.loadTestsFromModuleNames([