~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2013, 2016 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
17
17
"""Tests for the test framework."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import gc
20
21
import doctest
21
22
import os
22
23
import signal
42
43
from bzrlib import (
43
44
    branchbuilder,
44
45
    bzrdir,
 
46
    controldir,
45
47
    errors,
46
48
    hooks,
47
49
    lockdir,
93
95
            DocTestMatches(u"...a test message\n", doctest.ELLIPSIS))
94
96
 
95
97
 
96
 
class TestUnicodeFilename(tests.TestCase):
97
 
 
98
 
    def test_probe_passes(self):
99
 
        """UnicodeFilename._probe passes."""
100
 
        # We can't test much more than that because the behaviour depends
101
 
        # on the platform.
102
 
        tests.UnicodeFilename._probe()
103
 
 
104
 
 
105
98
class TestTreeShape(tests.TestCaseInTempDir):
106
99
 
107
100
    def test_unicode_paths(self):
108
 
        self.requireFeature(tests.UnicodeFilename)
 
101
        self.requireFeature(features.UnicodeFilenameFeature)
109
102
 
110
103
        filename = u'hell\u00d8'
111
104
        self.build_tree_contents([(filename, 'contents of hello')])
342
335
        server1 = "a"
343
336
        server2 = "b"
344
337
        formats = [workingtree_4.WorkingTreeFormat4(),
345
 
                   workingtree_3.WorkingTreeFormat3(),]
346
 
        scenarios = make_scenarios(server1, server2, formats)
 
338
                   workingtree_3.WorkingTreeFormat3(),
 
339
                   workingtree_4.WorkingTreeFormat6()]
 
340
        scenarios = make_scenarios(server1, server2, formats,
 
341
            remote_server='c', remote_readonly_server='d',
 
342
            remote_backing_server='e')
347
343
        self.assertEqual([
348
344
            ('WorkingTreeFormat4',
349
345
             {'bzrdir_format': formats[0]._matchingbzrdir,
354
350
             {'bzrdir_format': formats[1]._matchingbzrdir,
355
351
              'transport_readonly_server': 'b',
356
352
              'transport_server': 'a',
357
 
              'workingtree_format': formats[1]})],
358
 
            scenarios)
 
353
              'workingtree_format': formats[1]}),
 
354
            ('WorkingTreeFormat6',
 
355
             {'bzrdir_format': formats[2]._matchingbzrdir,
 
356
              'transport_readonly_server': 'b',
 
357
              'transport_server': 'a',
 
358
              'workingtree_format': formats[2]}),
 
359
            ('WorkingTreeFormat6,remote',
 
360
             {'bzrdir_format': formats[2]._matchingbzrdir,
 
361
              'repo_is_remote': True,
 
362
              'transport_readonly_server': 'd',
 
363
              'transport_server': 'c',
 
364
              'vfs_transport_factory': 'e',
 
365
              'workingtree_format': formats[2]}),
 
366
            ], scenarios)
359
367
 
360
368
 
361
369
class TestTreeScenarios(tests.TestCase):
362
370
 
363
371
    def test_scenarios(self):
364
372
        # the tree implementation scenario generator is meant to setup one
365
 
        # instance for each working tree format, and one additional instance
 
373
        # instance for each working tree format, one additional instance
366
374
        # that will use the default wt format, but create a revision tree for
367
 
        # the tests.  this means that the wt ones should have the
368
 
        # workingtree_to_test_tree attribute set to 'return_parameter' and the
369
 
        # revision one set to revision_tree_from_workingtree.
 
375
        # the tests, and one more that uses the default wt format as a
 
376
        # lightweight checkout of a remote repository.  This means that the wt
 
377
        # ones should have the workingtree_to_test_tree attribute set to
 
378
        # 'return_parameter' and the revision one set to
 
379
        # revision_tree_from_workingtree.
370
380
 
371
381
        from bzrlib.tests.per_tree import (
372
382
            _dirstate_tree_from_workingtree,
378
388
            )
379
389
        server1 = "a"
380
390
        server2 = "b"
 
391
        smart_server = test_server.SmartTCPServer_for_testing
 
392
        smart_readonly_server = test_server.ReadonlySmartTCPServer_for_testing
 
393
        mem_server = memory.MemoryServer
381
394
        formats = [workingtree_4.WorkingTreeFormat4(),
382
395
                   workingtree_3.WorkingTreeFormat3(),]
383
396
        scenarios = make_scenarios(server1, server2, formats)
384
 
        self.assertEqual(7, len(scenarios))
 
397
        self.assertEqual(8, len(scenarios))
385
398
        default_wt_format = workingtree.format_registry.get_default()
386
399
        wt4_format = workingtree_4.WorkingTreeFormat4()
387
400
        wt5_format = workingtree_4.WorkingTreeFormat5()
 
401
        wt6_format = workingtree_4.WorkingTreeFormat6()
388
402
        expected_scenarios = [
389
403
            ('WorkingTreeFormat4',
390
404
             {'bzrdir_format': formats[0]._matchingbzrdir,
400
414
              'workingtree_format': formats[1],
401
415
              '_workingtree_to_test_tree': return_parameter,
402
416
             }),
 
417
            ('WorkingTreeFormat6,remote',
 
418
             {'bzrdir_format': wt6_format._matchingbzrdir,
 
419
              'repo_is_remote': True,
 
420
              'transport_readonly_server': smart_readonly_server,
 
421
              'transport_server': smart_server,
 
422
              'vfs_transport_factory': mem_server,
 
423
              'workingtree_format': wt6_format,
 
424
              '_workingtree_to_test_tree': return_parameter,
 
425
             }),
403
426
            ('RevisionTree',
404
427
             {'_workingtree_to_test_tree': revision_tree_from_workingtree,
405
428
              'bzrdir_format': default_wt_format._matchingbzrdir,
617
640
        # Guard against regression into MemoryTransport leaking
618
641
        # files to disk instead of keeping them in memory.
619
642
        self.assertFalse(osutils.lexists('dir'))
620
 
        dir_format = bzrdir.format_registry.make_bzrdir('knit')
 
643
        dir_format = controldir.format_registry.make_bzrdir('knit')
621
644
        self.assertEqual(dir_format.repository_format.__class__,
622
645
                         the_branch.repository._format.__class__)
623
646
        self.assertEqual('Bazaar-NG Knit Repository Format 1',
627
650
    def test_dangling_locks_cause_failures(self):
628
651
        class TestDanglingLock(tests.TestCaseWithMemoryTransport):
629
652
            def test_function(self):
630
 
                t = self.get_transport('.')
 
653
                t = self.get_transport_from_path('.')
631
654
                l = lockdir.LockDir(t, 'lock')
632
655
                l.create()
633
656
                l.attempt_lock()
653
676
        # for the server
654
677
        url = self.get_readonly_url()
655
678
        url2 = self.get_readonly_url('foo/bar')
656
 
        t = transport.get_transport(url)
657
 
        t2 = transport.get_transport(url2)
 
679
        t = transport.get_transport_from_url(url)
 
680
        t2 = transport.get_transport_from_url(url2)
658
681
        self.assertIsInstance(t, ReadonlyTransportDecorator)
659
682
        self.assertIsInstance(t2, ReadonlyTransportDecorator)
660
683
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
668
691
        url = self.get_readonly_url()
669
692
        url2 = self.get_readonly_url('foo/bar')
670
693
        # the transport returned may be any HttpTransportBase subclass
671
 
        t = transport.get_transport(url)
672
 
        t2 = transport.get_transport(url2)
 
694
        t = transport.get_transport_from_url(url)
 
695
        t2 = transport.get_transport_from_url(url2)
673
696
        self.assertIsInstance(t, HttpTransportBase)
674
697
        self.assertIsInstance(t2, HttpTransportBase)
675
698
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
686
709
        builder = self.make_branch_builder('dir')
687
710
        rev_id = builder.build_commit()
688
711
        self.assertPathExists('dir')
689
 
        a_dir = bzrdir.BzrDir.open('dir')
 
712
        a_dir = controldir.ControlDir.open('dir')
690
713
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
691
714
        a_branch = a_dir.open_branch()
692
715
        builder_branch = builder.get_branch()
713
736
class TestChrootedTest(tests.ChrootedTestCase):
714
737
 
715
738
    def test_root_is_root(self):
716
 
        t = transport.get_transport(self.get_readonly_url())
 
739
        t = transport.get_transport_from_url(self.get_readonly_url())
717
740
        url = t.base
718
741
        self.assertEqual(url, t.clone('..').base)
719
742
 
721
744
class TestProfileResult(tests.TestCase):
722
745
 
723
746
    def test_profiles_tests(self):
724
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
747
        self.requireFeature(features.lsprof_feature)
725
748
        terminal = testtools.testresult.doubles.ExtendedTestResult()
726
749
        result = tests.ProfileResult(terminal)
727
750
        class Sample(tests.TestCase):
782
805
 
783
806
    def test_lsprofiling(self):
784
807
        """Verbose test result prints lsprof statistics from test cases."""
785
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
808
        self.requireFeature(features.lsprof_feature)
786
809
        result_stream = StringIO()
787
810
        result = bzrlib.tests.VerboseTestResult(
788
811
            result_stream,
833
856
        self.assertEndsWith(sio.getvalue(), "OK    50002ms\n")
834
857
 
835
858
    def test_known_failure(self):
836
 
        """A KnownFailure being raised should trigger several result actions."""
 
859
        """Using knownFailure should trigger several result actions."""
837
860
        class InstrumentedTestResult(tests.ExtendedTestResult):
838
861
            def stopTestRun(self): pass
839
862
            def report_tests_starting(self): pass
842
865
        result = InstrumentedTestResult(None, None, None, None)
843
866
        class Test(tests.TestCase):
844
867
            def test_function(self):
845
 
                raise tests.KnownFailure('failed!')
 
868
                self.knownFailure('failed!')
846
869
        test = Test("test_function")
847
870
        test.run(result)
848
871
        # it should invoke 'report_known_failure'.
864
887
            descriptions=0,
865
888
            verbosity=2,
866
889
            )
867
 
        test = self.get_passing_test()
868
 
        result.startTest(test)
869
 
        prefix = len(result_stream.getvalue())
870
 
        # the err parameter has the shape:
871
 
        # (class, exception object, traceback)
872
 
        # KnownFailures dont get their tracebacks shown though, so we
873
 
        # can skip that.
874
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
875
 
        result.report_known_failure(test, err)
876
 
        output = result_stream.getvalue()[prefix:]
877
 
        lines = output.splitlines()
878
 
        self.assertContainsRe(lines[0], r'XFAIL *\d+ms$')
879
 
        if sys.version_info > (2, 7):
880
 
            self.expectFailure("_ExpectedFailure on 2.7 loses the message",
881
 
                self.assertNotEqual, lines[1], '    ')
882
 
        self.assertEqual(lines[1], '    foo')
883
 
        self.assertEqual(2, len(lines))
 
890
        _get_test("test_xfail").run(result)
 
891
        self.assertContainsRe(result_stream.getvalue(),
 
892
            "\n\\S+\\.test_xfail\\s+XFAIL\\s+\\d+ms\n"
 
893
            "\\s*(?:Text attachment: )?reason"
 
894
            "(?:\n-+\n|: {{{)"
 
895
            "this_fails"
 
896
            "(?:\n-+\n|}}}\n)")
884
897
 
885
898
    def get_passing_test(self):
886
899
        """Return a test object that can't be run usefully."""
897
910
                self._call = test, feature
898
911
        result = InstrumentedTestResult(None, None, None, None)
899
912
        test = SampleTestCase('_test_pass')
900
 
        feature = tests.Feature()
 
913
        feature = features.Feature()
901
914
        result.startTest(test)
902
915
        result.addNotSupported(test, feature)
903
916
        # it should invoke 'report_unsupported'.
922
935
            verbosity=2,
923
936
            )
924
937
        test = self.get_passing_test()
925
 
        feature = tests.Feature()
 
938
        feature = features.Feature()
926
939
        result.startTest(test)
927
940
        prefix = len(result_stream.getvalue())
928
941
        result.report_unsupported(test, feature)
941
954
            def addNotSupported(self, test, feature):
942
955
                self._call = test, feature
943
956
        result = InstrumentedTestResult(None, None, None, None)
944
 
        feature = tests.Feature()
 
957
        feature = features.Feature()
945
958
        class Test(tests.TestCase):
946
959
            def test_function(self):
947
960
                raise tests.UnavailableFeature(feature)
966
979
    def test_strict_with_known_failure(self):
967
980
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
968
981
                                             verbosity=1)
969
 
        test = self.get_passing_test()
970
 
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
971
 
        result.addExpectedFailure(test, err)
 
982
        test = _get_test("test_xfail")
 
983
        test.run(result)
972
984
        self.assertFalse(result.wasStrictlySuccessful())
973
985
        self.assertEqual(None, result._extractBenchmarkTime(test))
974
986
 
990
1002
            pass
991
1003
        test = unittest.FunctionTestCase(test_function)
992
1004
        test.run(result)
993
 
        self.assertEquals(1, result.calls)
 
1005
        self.assertEqual(1, result.calls)
994
1006
 
995
1007
    def test_startTests_only_once(self):
996
1008
        """With multiple tests startTests should still only be called once"""
1002
1014
            unittest.FunctionTestCase(lambda: None),
1003
1015
            unittest.FunctionTestCase(lambda: None)])
1004
1016
        suite.run(result)
1005
 
        self.assertEquals(1, result.calls)
1006
 
        self.assertEquals(2, result.count)
1007
 
 
1008
 
 
1009
 
class TestUnicodeFilenameFeature(tests.TestCase):
1010
 
 
1011
 
    def test_probe_passes(self):
1012
 
        """UnicodeFilenameFeature._probe passes."""
1013
 
        # We can't test much more than that because the behaviour depends
1014
 
        # on the platform.
1015
 
        tests.UnicodeFilenameFeature._probe()
 
1017
        self.assertEqual(1, result.calls)
 
1018
        self.assertEqual(2, result.count)
1016
1019
 
1017
1020
 
1018
1021
class TestRunner(tests.TestCase):
1158
1161
        class SkippedTest(tests.TestCase):
1159
1162
 
1160
1163
            def setUp(self):
1161
 
                tests.TestCase.setUp(self)
 
1164
                super(SkippedTest, self).setUp()
1162
1165
                calls.append('setUp')
1163
1166
                self.addCleanup(self.cleanup)
1164
1167
 
1194
1197
 
1195
1198
    def test_unsupported_features_listed(self):
1196
1199
        """When unsupported features are encountered they are detailed."""
1197
 
        class Feature1(tests.Feature):
 
1200
        class Feature1(features.Feature):
1198
1201
            def _probe(self): return False
1199
 
        class Feature2(tests.Feature):
 
1202
        class Feature2(features.Feature):
1200
1203
            def _probe(self): return False
1201
1204
        # create sample tests
1202
1205
        test1 = SampleTestCase('_test_pass')
1479
1482
 
1480
1483
        Each self.time() call is individually and separately profiled.
1481
1484
        """
1482
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
1485
        self.requireFeature(features.lsprof_feature)
1483
1486
        # overrides the class member with an instance member so no cleanup
1484
1487
        # needed.
1485
1488
        self._gather_lsprof_in_benchmarks = True
1504
1507
        transport_server = memory.MemoryServer()
1505
1508
        transport_server.start_server()
1506
1509
        self.addCleanup(transport_server.stop_server)
1507
 
        t = transport.get_transport(transport_server.get_url())
1508
 
        bzrdir.BzrDir.create(t.base)
 
1510
        t = transport.get_transport_from_url(transport_server.get_url())
 
1511
        controldir.ControlDir.create(t.base)
1509
1512
        self.assertRaises(errors.BzrError,
1510
 
            bzrdir.BzrDir.open_from_transport, t)
 
1513
            controldir.ControlDir.open_from_transport, t)
1511
1514
        # But if we declare this as safe, we can open the bzrdir.
1512
1515
        self.permit_url(t.base)
1513
1516
        self._bzr_selftest_roots.append(t.base)
1514
 
        bzrdir.BzrDir.open_from_transport(t)
 
1517
        controldir.ControlDir.open_from_transport(t)
1515
1518
 
1516
1519
    def test_requireFeature_available(self):
1517
1520
        """self.requireFeature(available) is a no-op."""
1518
 
        class Available(tests.Feature):
 
1521
        class Available(features.Feature):
1519
1522
            def _probe(self):return True
1520
1523
        feature = Available()
1521
1524
        self.requireFeature(feature)
1522
1525
 
1523
1526
    def test_requireFeature_unavailable(self):
1524
1527
        """self.requireFeature(unavailable) raises UnavailableFeature."""
1525
 
        class Unavailable(tests.Feature):
 
1528
        class Unavailable(features.Feature):
1526
1529
            def _probe(self):return False
1527
1530
        feature = Unavailable()
1528
1531
        self.assertRaises(tests.UnavailableFeature,
1651
1654
        self.assertRaises(AssertionError,
1652
1655
            self.assertListRaises, _TestException, success_generator)
1653
1656
 
 
1657
    def _run_successful_test(self, test):
 
1658
        result = testtools.TestResult()
 
1659
        test.run(result)
 
1660
        self.assertTrue(result.wasSuccessful())
 
1661
        return result
 
1662
 
1654
1663
    def test_overrideAttr_without_value(self):
1655
1664
        self.test_attr = 'original' # Define a test attribute
1656
1665
        obj = self # Make 'obj' visible to the embedded test
1657
1666
        class Test(tests.TestCase):
1658
1667
 
1659
1668
            def setUp(self):
1660
 
                tests.TestCase.setUp(self)
 
1669
                super(Test, self).setUp()
1661
1670
                self.orig = self.overrideAttr(obj, 'test_attr')
1662
1671
 
1663
1672
            def test_value(self):
1666
1675
                obj.test_attr = 'modified'
1667
1676
                self.assertEqual('modified', obj.test_attr)
1668
1677
 
1669
 
        test = Test('test_value')
1670
 
        test.run(unittest.TestResult())
 
1678
        self._run_successful_test(Test('test_value'))
1671
1679
        self.assertEqual('original', obj.test_attr)
1672
1680
 
1673
1681
    def test_overrideAttr_with_value(self):
1676
1684
        class Test(tests.TestCase):
1677
1685
 
1678
1686
            def setUp(self):
1679
 
                tests.TestCase.setUp(self)
 
1687
                super(Test, self).setUp()
1680
1688
                self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
1681
1689
 
1682
1690
            def test_value(self):
1683
1691
                self.assertEqual('original', self.orig)
1684
1692
                self.assertEqual('modified', obj.test_attr)
1685
1693
 
1686
 
        test = Test('test_value')
1687
 
        test.run(unittest.TestResult())
 
1694
        self._run_successful_test(Test('test_value'))
1688
1695
        self.assertEqual('original', obj.test_attr)
1689
1696
 
 
1697
    def test_overrideAttr_with_no_existing_value_and_value(self):
 
1698
        # Do not define the test_attribute
 
1699
        obj = self # Make 'obj' visible to the embedded test
 
1700
        class Test(tests.TestCase):
 
1701
 
 
1702
            def setUp(self):
 
1703
                tests.TestCase.setUp(self)
 
1704
                self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
 
1705
 
 
1706
            def test_value(self):
 
1707
                self.assertEqual(tests._unitialized_attr, self.orig)
 
1708
                self.assertEqual('modified', obj.test_attr)
 
1709
 
 
1710
        self._run_successful_test(Test('test_value'))
 
1711
        self.assertRaises(AttributeError, getattr, obj, 'test_attr')
 
1712
 
 
1713
    def test_overrideAttr_with_no_existing_value_and_no_value(self):
 
1714
        # Do not define the test_attribute
 
1715
        obj = self # Make 'obj' visible to the embedded test
 
1716
        class Test(tests.TestCase):
 
1717
 
 
1718
            def setUp(self):
 
1719
                tests.TestCase.setUp(self)
 
1720
                self.orig = self.overrideAttr(obj, 'test_attr')
 
1721
 
 
1722
            def test_value(self):
 
1723
                self.assertEqual(tests._unitialized_attr, self.orig)
 
1724
                self.assertRaises(AttributeError, getattr, obj, 'test_attr')
 
1725
 
 
1726
        self._run_successful_test(Test('test_value'))
 
1727
        self.assertRaises(AttributeError, getattr, obj, 'test_attr')
 
1728
 
1690
1729
    def test_recordCalls(self):
1691
1730
        from bzrlib.tests import test_selftest
1692
1731
        calls = self.recordCalls(
1693
1732
            test_selftest, '_add_numbers')
1694
1733
        self.assertEqual(test_selftest._add_numbers(2, 10),
1695
1734
            12)
1696
 
        self.assertEquals(calls, [((2, 10), {})])
 
1735
        self.assertEqual(calls, [((2, 10), {})])
1697
1736
 
1698
1737
 
1699
1738
def _add_numbers(a, b):
1700
1739
    return a + b
1701
1740
 
1702
1741
 
1703
 
class _MissingFeature(tests.Feature):
 
1742
class _MissingFeature(features.Feature):
1704
1743
    def _probe(self):
1705
1744
        return False
1706
1745
missing_feature = _MissingFeature()
1873
1912
        self.assertIsInstance(2, int)
1874
1913
        self.assertIsInstance(u'', basestring)
1875
1914
        e = self.assertRaises(AssertionError, self.assertIsInstance, None, int)
1876
 
        self.assertEquals(str(e),
 
1915
        self.assertEqual(str(e),
1877
1916
            "None is an instance of <type 'NoneType'> rather than <type 'int'>")
1878
1917
        self.assertRaises(AssertionError, self.assertIsInstance, 23.3, int)
1879
1918
        e = self.assertRaises(AssertionError,
1880
1919
            self.assertIsInstance, None, int, "it's just not")
1881
 
        self.assertEquals(str(e),
 
1920
        self.assertEqual(str(e),
1882
1921
            "None is an instance of <type 'NoneType'> rather than <type 'int'>"
1883
1922
            ": it's just not")
1884
1923
 
1889
1928
    def test_assertEqualDiff(self):
1890
1929
        e = self.assertRaises(AssertionError,
1891
1930
                              self.assertEqualDiff, '', '\n')
1892
 
        self.assertEquals(str(e),
 
1931
        self.assertEqual(str(e),
1893
1932
                          # Don't blink ! The '+' applies to the second string
1894
1933
                          'first string is missing a final newline.\n+ \n')
1895
1934
        e = self.assertRaises(AssertionError,
1896
1935
                              self.assertEqualDiff, '\n', '')
1897
 
        self.assertEquals(str(e),
 
1936
        self.assertEqual(str(e),
1898
1937
                          # Don't blink ! The '-' applies to the second string
1899
1938
                          'second string is missing a final newline.\n- \n')
1900
1939
 
1957
1996
            warnings.warn("this is your last warning")
1958
1997
            return a + b
1959
1998
        wlist, result = self.callCatchWarnings(meth, 1, 2)
1960
 
        self.assertEquals(3, result)
 
1999
        self.assertEqual(3, result)
1961
2000
        # would like just to compare them, but UserWarning doesn't implement
1962
2001
        # eq well
1963
2002
        w0, = wlist
1964
2003
        self.assertIsInstance(w0, UserWarning)
1965
 
        self.assertEquals("this is your last warning", str(w0))
 
2004
        self.assertEqual("this is your last warning", str(w0))
1966
2005
 
1967
2006
 
1968
2007
class TestConvenienceMakers(tests.TestCaseWithTransport):
1971
2010
    def test_make_branch_and_tree_with_format(self):
1972
2011
        # we should be able to supply a format to make_branch_and_tree
1973
2012
        self.make_branch_and_tree('a', format=bzrlib.bzrdir.BzrDirMetaFormat1())
1974
 
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('a')._format,
 
2013
        self.assertIsInstance(bzrlib.controldir.ControlDir.open('a')._format,
1975
2014
                              bzrlib.bzrdir.BzrDirMetaFormat1)
1976
2015
 
1977
2016
    def test_make_branch_and_memory_tree(self):
1989
2028
        tree = self.make_branch_and_tree('t1')
1990
2029
        base = tree.bzrdir.root_transport.base
1991
2030
        self.assertStartsWith(base, 'file://')
1992
 
        self.assertEquals(tree.bzrdir.root_transport,
 
2031
        self.assertEqual(tree.bzrdir.root_transport,
1993
2032
                tree.branch.bzrdir.root_transport)
1994
 
        self.assertEquals(tree.bzrdir.root_transport,
 
2033
        self.assertEqual(tree.bzrdir.root_transport,
1995
2034
                tree.branch.repository.bzrdir.root_transport)
1996
2035
 
1997
2036
 
2055
2094
        self.assertLength(2, output.readlines())
2056
2095
 
2057
2096
    def test_lsprof_tests(self):
2058
 
        self.requireFeature(test_lsprof.LSProfFeature)
 
2097
        self.requireFeature(features.lsprof_feature)
2059
2098
        results = []
2060
2099
        class Test(object):
2061
2100
            def __call__(test, result):
2261
2300
        self.assertEqual(['rocks'], self.argv)
2262
2301
        self.assertEqual(34, self.retcode)
2263
2302
        self.assertEqual('It sure does!\n', out)
2264
 
        self.assertEquals(out, self.out)
 
2303
        self.assertEqual(out, self.out)
2265
2304
        self.assertEqual('', err)
2266
 
        self.assertEquals(err, self.err)
 
2305
        self.assertEqual(err, self.err)
2267
2306
 
2268
2307
    def test_run_bzr_error_regexes(self):
2269
2308
        self.out = ''
2409
2448
    """Base class for tests testing how we might run bzr."""
2410
2449
 
2411
2450
    def setUp(self):
2412
 
        tests.TestCaseWithTransport.setUp(self)
 
2451
        super(TestWithFakedStartBzrSubprocess, self).setUp()
2413
2452
        self.subprocess_calls = []
2414
2453
 
2415
2454
    def start_bzr_subprocess(self, process_args, env_changes=None,
2626
2665
        self.assertEqual('bzr: interrupted\n', result[1])
2627
2666
 
2628
2667
 
2629
 
class TestFeature(tests.TestCase):
2630
 
 
2631
 
    def test_caching(self):
2632
 
        """Feature._probe is called by the feature at most once."""
2633
 
        class InstrumentedFeature(tests.Feature):
2634
 
            def __init__(self):
2635
 
                super(InstrumentedFeature, self).__init__()
2636
 
                self.calls = []
2637
 
            def _probe(self):
2638
 
                self.calls.append('_probe')
2639
 
                return False
2640
 
        feature = InstrumentedFeature()
2641
 
        feature.available()
2642
 
        self.assertEqual(['_probe'], feature.calls)
2643
 
        feature.available()
2644
 
        self.assertEqual(['_probe'], feature.calls)
2645
 
 
2646
 
    def test_named_str(self):
2647
 
        """Feature.__str__ should thunk to feature_name()."""
2648
 
        class NamedFeature(tests.Feature):
2649
 
            def feature_name(self):
2650
 
                return 'symlinks'
2651
 
        feature = NamedFeature()
2652
 
        self.assertEqual('symlinks', str(feature))
2653
 
 
2654
 
    def test_default_str(self):
2655
 
        """Feature.__str__ should default to __class__.__name__."""
2656
 
        class NamedFeature(tests.Feature):
2657
 
            pass
2658
 
        feature = NamedFeature()
2659
 
        self.assertEqual('NamedFeature', str(feature))
2660
 
 
2661
 
 
2662
 
class TestUnavailableFeature(tests.TestCase):
2663
 
 
2664
 
    def test_access_feature(self):
2665
 
        feature = tests.Feature()
2666
 
        exception = tests.UnavailableFeature(feature)
2667
 
        self.assertIs(feature, exception.args[0])
2668
 
 
2669
 
 
2670
 
simple_thunk_feature = tests._CompatabilityThunkFeature(
2671
 
    deprecated_in((2, 1, 0)),
2672
 
    'bzrlib.tests.test_selftest',
2673
 
    'simple_thunk_feature','UnicodeFilename',
2674
 
    replacement_module='bzrlib.tests'
2675
 
    )
2676
 
 
2677
 
class Test_CompatibilityFeature(tests.TestCase):
2678
 
 
2679
 
    def test_does_thunk(self):
2680
 
        res = self.callDeprecated(
2681
 
            ['bzrlib.tests.test_selftest.simple_thunk_feature was deprecated'
2682
 
             ' in version 2.1.0. Use bzrlib.tests.UnicodeFilename instead.'],
2683
 
            simple_thunk_feature.available)
2684
 
        self.assertEqual(tests.UnicodeFilename.available(), res)
2685
 
 
2686
 
 
2687
 
class TestModuleAvailableFeature(tests.TestCase):
2688
 
 
2689
 
    def test_available_module(self):
2690
 
        feature = tests.ModuleAvailableFeature('bzrlib.tests')
2691
 
        self.assertEqual('bzrlib.tests', feature.module_name)
2692
 
        self.assertEqual('bzrlib.tests', str(feature))
2693
 
        self.assertTrue(feature.available())
2694
 
        self.assertIs(tests, feature.module)
2695
 
 
2696
 
    def test_unavailable_module(self):
2697
 
        feature = tests.ModuleAvailableFeature('bzrlib.no_such_module_exists')
2698
 
        self.assertEqual('bzrlib.no_such_module_exists', str(feature))
2699
 
        self.assertFalse(feature.available())
2700
 
        self.assertIs(None, feature.module)
2701
 
 
2702
 
 
2703
2668
class TestSelftestFiltering(tests.TestCase):
2704
2669
 
2705
2670
    def setUp(self):
2706
 
        tests.TestCase.setUp(self)
 
2671
        super(TestSelftestFiltering, self).setUp()
2707
2672
        self.suite = TestUtil.TestSuite()
2708
2673
        self.loader = TestUtil.TestLoader()
2709
2674
        self.suite.addTest(self.loader.loadTestsFromModule(
2882
2847
            self.run_bzr, ['assert-fail'])
2883
2848
        # make sure we got the real thing, not an error from somewhere else in
2884
2849
        # the test framework
2885
 
        self.assertEquals('always fails', str(e))
 
2850
        self.assertEqual('always fails', str(e))
2886
2851
        # check that there's no traceback in the test log
2887
2852
        self.assertNotContainsRe(self.get_log(), r'Traceback')
2888
2853
 
2937
2902
    def test_load_tests_from_module_name_smoke_test(self):
2938
2903
        loader = TestUtil.TestLoader()
2939
2904
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2940
 
        self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
 
2905
        self.assertEqual(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
2941
2906
                          _test_ids(suite))
2942
2907
 
2943
2908
    def test_load_tests_from_module_name_with_bogus_module_name(self):
2972
2937
 
2973
2938
    def test_empty_list(self):
2974
2939
        id_list = self._create_id_list([])
2975
 
        self.assertEquals({}, id_list.tests)
2976
 
        self.assertEquals({}, id_list.modules)
 
2940
        self.assertEqual({}, id_list.tests)
 
2941
        self.assertEqual({}, id_list.modules)
2977
2942
 
2978
2943
    def test_valid_list(self):
2979
2944
        id_list = self._create_id_list(
3006
2971
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',
3007
2972
                     'bogus']
3008
2973
        not_found, duplicates = tests.suite_matches_id_list(suite, test_list)
3009
 
        self.assertEquals(['bogus'], not_found)
3010
 
        self.assertEquals([], duplicates)
 
2974
        self.assertEqual(['bogus'], not_found)
 
2975
        self.assertEqual([], duplicates)
3011
2976
 
3012
2977
    def test_suite_matches_id_list_with_duplicates(self):
3013
2978
        loader = TestUtil.TestLoader()
3020
2985
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing',]
3021
2986
        not_found, duplicates = tests.suite_matches_id_list(
3022
2987
            dupes, test_list)
3023
 
        self.assertEquals([], not_found)
3024
 
        self.assertEquals(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
 
2988
        self.assertEqual([], not_found)
 
2989
        self.assertEqual(['bzrlib.tests.test_sampler.DemoTest.test_nothing'],
3025
2990
                          duplicates)
3026
2991
 
3027
2992
 
3100
3065
        suite = tests.test_suite(test_list,
3101
3066
                                 ['bzrlib.tests.test_selftest.TestTestSuite'])
3102
3067
        # test_test_suite_list_and_start is not included 
3103
 
        self.assertEquals(test_list, _test_ids(suite))
 
3068
        self.assertEqual(test_list, _test_ids(suite))
3104
3069
 
3105
3070
 
3106
3071
class TestLoadTestIdList(tests.TestCaseInTempDir):
3119
3084
        self._create_test_list_file(test_list_fname,
3120
3085
                                    'mod1.cl1.meth1\nmod2.cl2.meth2\n')
3121
3086
        tlist = tests.load_test_id_list(test_list_fname)
3122
 
        self.assertEquals(2, len(tlist))
3123
 
        self.assertEquals('mod1.cl1.meth1', tlist[0])
3124
 
        self.assertEquals('mod2.cl2.meth2', tlist[1])
 
3087
        self.assertEqual(2, len(tlist))
 
3088
        self.assertEqual('mod1.cl1.meth1', tlist[0])
 
3089
        self.assertEqual('mod2.cl2.meth2', tlist[1])
3125
3090
 
3126
3091
    def test_load_dirty_file(self):
3127
3092
        test_list_fname = 'test.list'
3129
3094
                                    '  mod1.cl1.meth1\n\nmod2.cl2.meth2  \n'
3130
3095
                                    'bar baz\n')
3131
3096
        tlist = tests.load_test_id_list(test_list_fname)
3132
 
        self.assertEquals(4, len(tlist))
3133
 
        self.assertEquals('mod1.cl1.meth1', tlist[0])
3134
 
        self.assertEquals('', tlist[1])
3135
 
        self.assertEquals('mod2.cl2.meth2', tlist[2])
3136
 
        self.assertEquals('bar baz', tlist[3])
 
3097
        self.assertEqual(4, len(tlist))
 
3098
        self.assertEqual('mod1.cl1.meth1', tlist[0])
 
3099
        self.assertEqual('', tlist[1])
 
3100
        self.assertEqual('mod2.cl2.meth2', tlist[2])
 
3101
        self.assertEqual('bar baz', tlist[3])
3137
3102
 
3138
3103
 
3139
3104
class TestFilteredByModuleTestLoader(tests.TestCase):
3147
3112
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
3148
3113
        loader = self._create_loader(test_list)
3149
3114
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
3150
 
        self.assertEquals(test_list, _test_ids(suite))
 
3115
        self.assertEqual(test_list, _test_ids(suite))
3151
3116
 
3152
3117
    def test_exclude_tests(self):
3153
3118
        test_list = ['bogus']
3154
3119
        loader = self._create_loader(test_list)
3155
3120
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
3156
 
        self.assertEquals([], _test_ids(suite))
 
3121
        self.assertEqual([], _test_ids(suite))
3157
3122
 
3158
3123
 
3159
3124
class TestFilteredByNameStartTestLoader(tests.TestCase):
3169
3134
        loader = self._create_loader('bzrlib.tests.test_samp')
3170
3135
 
3171
3136
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
3172
 
        self.assertEquals(test_list, _test_ids(suite))
 
3137
        self.assertEqual(test_list, _test_ids(suite))
3173
3138
 
3174
3139
    def test_load_tests_inside_module(self):
3175
3140
        test_list = ['bzrlib.tests.test_sampler.DemoTest.test_nothing']
3176
3141
        loader = self._create_loader('bzrlib.tests.test_sampler.Demo')
3177
3142
 
3178
3143
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
3179
 
        self.assertEquals(test_list, _test_ids(suite))
 
3144
        self.assertEqual(test_list, _test_ids(suite))
3180
3145
 
3181
3146
    def test_exclude_tests(self):
3182
3147
        test_list = ['bogus']
3183
3148
        loader = self._create_loader('bogus')
3184
3149
 
3185
3150
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
3186
 
        self.assertEquals([], _test_ids(suite))
 
3151
        self.assertEqual([], _test_ids(suite))
3187
3152
 
3188
3153
 
3189
3154
class TestTestPrefixRegistry(tests.TestCase):
3195
3160
    def test_register_new_prefix(self):
3196
3161
        tpr = self._get_registry()
3197
3162
        tpr.register('foo', 'fff.ooo.ooo')
3198
 
        self.assertEquals('fff.ooo.ooo', tpr.get('foo'))
 
3163
        self.assertEqual('fff.ooo.ooo', tpr.get('foo'))
3199
3164
 
3200
3165
    def test_register_existing_prefix(self):
3201
3166
        tpr = self._get_registry()
3202
3167
        tpr.register('bar', 'bbb.aaa.rrr')
3203
3168
        tpr.register('bar', 'bBB.aAA.rRR')
3204
 
        self.assertEquals('bbb.aaa.rrr', tpr.get('bar'))
 
3169
        self.assertEqual('bbb.aaa.rrr', tpr.get('bar'))
3205
3170
        self.assertThat(self.get_log(),
3206
3171
            DocTestMatches("...bar...bbb.aaa.rrr...BB.aAA.rRR",
3207
3172
                           doctest.ELLIPSIS))
3213
3178
    def test_resolve_prefix(self):
3214
3179
        tpr = self._get_registry()
3215
3180
        tpr.register('bar', 'bb.aa.rr')
3216
 
        self.assertEquals('bb.aa.rr', tpr.resolve_alias('bar'))
 
3181
        self.assertEqual('bb.aa.rr', tpr.resolve_alias('bar'))
3217
3182
 
3218
3183
    def test_resolve_unknown_alias(self):
3219
3184
        tpr = self._get_registry()
3222
3187
 
3223
3188
    def test_predefined_prefixes(self):
3224
3189
        tpr = tests.test_prefix_alias_registry
3225
 
        self.assertEquals('bzrlib', tpr.resolve_alias('bzrlib'))
3226
 
        self.assertEquals('bzrlib.doc', tpr.resolve_alias('bd'))
3227
 
        self.assertEquals('bzrlib.utils', tpr.resolve_alias('bu'))
3228
 
        self.assertEquals('bzrlib.tests', tpr.resolve_alias('bt'))
3229
 
        self.assertEquals('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
3230
 
        self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
 
3190
        self.assertEqual('bzrlib', tpr.resolve_alias('bzrlib'))
 
3191
        self.assertEqual('bzrlib.doc', tpr.resolve_alias('bd'))
 
3192
        self.assertEqual('bzrlib.utils', tpr.resolve_alias('bu'))
 
3193
        self.assertEqual('bzrlib.tests', tpr.resolve_alias('bt'))
 
3194
        self.assertEqual('bzrlib.tests.blackbox', tpr.resolve_alias('bb'))
 
3195
        self.assertEqual('bzrlib.plugins', tpr.resolve_alias('bp'))
3231
3196
 
3232
3197
 
3233
3198
class TestThreadLeakDetection(tests.TestCase):
3404
3369
        self.assertLength(1, calls)
3405
3370
 
3406
3371
 
 
3372
class _Selftest(object):
 
3373
    """Mixin for tests needing full selftest output"""
 
3374
 
 
3375
    def _inject_stream_into_subunit(self, stream):
 
3376
        """To be overridden by subclasses that run tests out of process"""
 
3377
 
 
3378
    def _run_selftest(self, **kwargs):
 
3379
        sio = StringIO()
 
3380
        self._inject_stream_into_subunit(sio)
 
3381
        tests.selftest(stream=sio, stop_on_failure=False, **kwargs)
 
3382
        return sio.getvalue()
 
3383
 
 
3384
 
 
3385
class _ForkedSelftest(_Selftest):
 
3386
    """Mixin for tests needing full selftest output with forked children"""
 
3387
 
 
3388
    _test_needs_features = [features.subunit]
 
3389
 
 
3390
    def _inject_stream_into_subunit(self, stream):
 
3391
        """Monkey-patch subunit so the extra output goes to stream not stdout
 
3392
 
 
3393
        Some APIs need rewriting so this kind of bogus hackery can be replaced
 
3394
        by passing the stream param from run_tests down into ProtocolTestCase.
 
3395
        """
 
3396
        from subunit import ProtocolTestCase
 
3397
        _original_init = ProtocolTestCase.__init__
 
3398
        def _init_with_passthrough(self, *args, **kwargs):
 
3399
            _original_init(self, *args, **kwargs)
 
3400
            self._passthrough = stream
 
3401
        self.overrideAttr(ProtocolTestCase, "__init__", _init_with_passthrough)
 
3402
 
 
3403
    def _run_selftest(self, **kwargs):
 
3404
        # GZ 2011-05-26: Add a PosixSystem feature so this check can go away
 
3405
        if getattr(os, "fork", None) is None:
 
3406
            raise tests.TestNotApplicable("Platform doesn't support forking")
 
3407
        # Make sure the fork code is actually invoked by claiming two cores
 
3408
        self.overrideAttr(osutils, "local_concurrency", lambda: 2)
 
3409
        kwargs.setdefault("suite_decorators", []).append(tests.fork_decorator)
 
3410
        return super(_ForkedSelftest, self)._run_selftest(**kwargs)
 
3411
 
 
3412
 
 
3413
class TestParallelFork(_ForkedSelftest, tests.TestCase):
 
3414
    """Check operation of --parallel=fork selftest option"""
 
3415
 
 
3416
    def test_error_in_child_during_fork(self):
 
3417
        """Error in a forked child during test setup should get reported"""
 
3418
        class Test(tests.TestCase):
 
3419
            def testMethod(self):
 
3420
                pass
 
3421
        # We don't care what, just break something that a child will run
 
3422
        self.overrideAttr(tests, "workaround_zealous_crypto_random", None)
 
3423
        out = self._run_selftest(test_suite_factory=Test)
 
3424
        # Lines from the tracebacks of the two child processes may be mixed
 
3425
        # together due to the way subunit parses and forwards the streams,
 
3426
        # so permit extra lines between each part of the error output.
 
3427
        self.assertContainsRe(out,
 
3428
            "Traceback.*:\n"
 
3429
            "(?:.*\n)*"
 
3430
            ".+ in fork_for_tests\n"
 
3431
            "(?:.*\n)*"
 
3432
            "\s*workaround_zealous_crypto_random\(\)\n"
 
3433
            "(?:.*\n)*"
 
3434
            "TypeError:")
 
3435
 
 
3436
 
 
3437
class TestUncollectedWarnings(_Selftest, tests.TestCase):
 
3438
    """Check a test case still alive after being run emits a warning"""
 
3439
 
 
3440
    class Test(tests.TestCase):
 
3441
        def test_pass(self):
 
3442
            pass
 
3443
        def test_self_ref(self):
 
3444
            self.also_self = self.test_self_ref
 
3445
        def test_skip(self):
 
3446
            self.skip("Don't need")
 
3447
 
 
3448
    def _get_suite(self):
 
3449
        return TestUtil.TestSuite([
 
3450
            self.Test("test_pass"),
 
3451
            self.Test("test_self_ref"),
 
3452
            self.Test("test_skip"),
 
3453
            ])
 
3454
 
 
3455
    def _run_selftest_with_suite(self, **kwargs):
 
3456
        old_flags = tests.selftest_debug_flags
 
3457
        tests.selftest_debug_flags = old_flags.union(["uncollected_cases"])
 
3458
        gc_on = gc.isenabled()
 
3459
        if gc_on:
 
3460
            gc.disable()
 
3461
        try:
 
3462
            output = self._run_selftest(test_suite_factory=self._get_suite,
 
3463
                **kwargs)
 
3464
        finally:
 
3465
            if gc_on:
 
3466
                gc.enable()
 
3467
            tests.selftest_debug_flags = old_flags
 
3468
        self.assertNotContainsRe(output, "Uncollected test case.*test_pass")
 
3469
        self.assertContainsRe(output, "Uncollected test case.*test_self_ref")
 
3470
        return output
 
3471
 
 
3472
    def test_testsuite(self):
 
3473
        self._run_selftest_with_suite()
 
3474
 
 
3475
    def test_pattern(self):
 
3476
        out = self._run_selftest_with_suite(pattern="test_(?:pass|self_ref)$")
 
3477
        self.assertNotContainsRe(out, "test_skip")
 
3478
 
 
3479
    def test_exclude_pattern(self):
 
3480
        out = self._run_selftest_with_suite(exclude_pattern="test_skip$")
 
3481
        self.assertNotContainsRe(out, "test_skip")
 
3482
 
 
3483
    def test_random_seed(self):
 
3484
        self._run_selftest_with_suite(random_seed="now")
 
3485
 
 
3486
    def test_matching_tests_first(self):
 
3487
        self._run_selftest_with_suite(matching_tests_first=True,
 
3488
            pattern="test_self_ref$")
 
3489
 
 
3490
    def test_starting_with_and_exclude(self):
 
3491
        out = self._run_selftest_with_suite(starting_with=["bt."],
 
3492
            exclude_pattern="test_skip$")
 
3493
        self.assertNotContainsRe(out, "test_skip")
 
3494
 
 
3495
    def test_additonal_decorator(self):
 
3496
        out = self._run_selftest_with_suite(
 
3497
            suite_decorators=[tests.TestDecorator])
 
3498
 
 
3499
 
 
3500
class TestUncollectedWarningsSubunit(TestUncollectedWarnings):
 
3501
    """Check warnings from tests staying alive are emitted with subunit"""
 
3502
 
 
3503
    _test_needs_features = [features.subunit]
 
3504
 
 
3505
    def _run_selftest_with_suite(self, **kwargs):
 
3506
        return TestUncollectedWarnings._run_selftest_with_suite(self,
 
3507
            runner_class=tests.SubUnitBzrRunner, **kwargs)
 
3508
 
 
3509
 
 
3510
class TestUncollectedWarningsForked(_ForkedSelftest, TestUncollectedWarnings):
 
3511
    """Check warnings from tests staying alive are emitted when forking"""
 
3512
 
 
3513
 
3407
3514
class TestEnvironHandling(tests.TestCase):
3408
3515
 
3409
3516
    def test_overrideEnv_None_called_twice_doesnt_leak(self):
3414
3521
            def test_me(self):
3415
3522
                # The first call save the 42 value
3416
3523
                self.overrideEnv('MYVAR', None)
3417
 
                self.assertEquals(None, os.environ.get('MYVAR'))
 
3524
                self.assertEqual(None, os.environ.get('MYVAR'))
3418
3525
                # Make sure we can call it twice
3419
3526
                self.overrideEnv('MYVAR', None)
3420
 
                self.assertEquals(None, os.environ.get('MYVAR'))
 
3527
                self.assertEqual(None, os.environ.get('MYVAR'))
3421
3528
        output = StringIO()
3422
3529
        result = tests.TextTestResult(output, 0, 1)
3423
3530
        Test('test_me').run(result)
3424
3531
        if not result.wasStrictlySuccessful():
3425
3532
            self.fail(output.getvalue())
3426
3533
        # We get our value back
3427
 
        self.assertEquals('42', os.environ.get('MYVAR'))
 
3534
        self.assertEqual('42', os.environ.get('MYVAR'))
3428
3535
 
3429
3536
 
3430
3537
class TestIsolatedEnv(tests.TestCase):
3446
3553
        # Make sure we know the definition of BZR_HOME: not part of os.environ
3447
3554
        # for tests.TestCase.
3448
3555
        self.assertTrue('BZR_HOME' in tests.isolated_environ)
3449
 
        self.assertEquals(None, tests.isolated_environ['BZR_HOME'])
 
3556
        self.assertEqual(None, tests.isolated_environ['BZR_HOME'])
3450
3557
        # Being part of isolated_environ, BZR_HOME should not appear here
3451
3558
        self.assertFalse('BZR_HOME' in os.environ)
3452
3559
        # Make sure we know the definition of LINES: part of os.environ for
3453
3560
        # tests.TestCase
3454
3561
        self.assertTrue('LINES' in tests.isolated_environ)
3455
 
        self.assertEquals('25', tests.isolated_environ['LINES'])
3456
 
        self.assertEquals('25', os.environ['LINES'])
 
3562
        self.assertEqual('25', tests.isolated_environ['LINES'])
 
3563
        self.assertEqual('25', os.environ['LINES'])
3457
3564
 
3458
3565
    def test_injecting_unknown_variable(self):
3459
3566
        # BZR_HOME is known to be absent from os.environ
3460
3567
        test = self.ScratchMonkey('test_me')
3461
3568
        tests.override_os_environ(test, {'BZR_HOME': 'foo'})
3462
 
        self.assertEquals('foo', os.environ['BZR_HOME'])
 
3569
        self.assertEqual('foo', os.environ['BZR_HOME'])
3463
3570
        tests.restore_os_environ(test)
3464
3571
        self.assertFalse('BZR_HOME' in os.environ)
3465
3572
 
3467
3574
        test = self.ScratchMonkey('test_me')
3468
3575
        # LINES is known to be present in os.environ
3469
3576
        tests.override_os_environ(test, {'LINES': '42'})
3470
 
        self.assertEquals('42', os.environ['LINES'])
 
3577
        self.assertEqual('42', os.environ['LINES'])
3471
3578
        tests.restore_os_environ(test)
3472
 
        self.assertEquals('25', os.environ['LINES'])
 
3579
        self.assertEqual('25', os.environ['LINES'])
3473
3580
 
3474
3581
    def test_deleting_variable(self):
3475
3582
        test = self.ScratchMonkey('test_me')
3477
3584
        tests.override_os_environ(test, {'LINES': None})
3478
3585
        self.assertTrue('LINES' not in os.environ)
3479
3586
        tests.restore_os_environ(test)
3480
 
        self.assertEquals('25', os.environ['LINES'])
 
3587
        self.assertEqual('25', os.environ['LINES'])
3481
3588
 
3482
3589
 
3483
3590
class TestDocTestSuiteIsolation(tests.TestCase):
3570
3677
        # test at the command level without loading the whole test suite
3571
3678
        out, err = self.run_bzr(('selftest', '--list') + selftest_args)
3572
3679
        actual = out.splitlines()
3573
 
        self.assertEquals(expected, actual)
 
3680
        self.assertEqual(expected, actual)
3574
3681
 
3575
3682
    def test_full_list(self):
3576
3683
        self.assertTestList(['a', 'b', 'c'])
3611
3718
        test.run(result)
3612
3719
        self.assertTrue(hasattr(test, '_counters'))
3613
3720
        self.assertTrue(test._counters.has_key('myhook'))
3614
 
        self.assertEquals(expected_calls, test._counters['myhook'])
 
3721
        self.assertEqual(expected_calls, test._counters['myhook'])
3615
3722
 
3616
3723
    def test_no_hook(self):
3617
3724
        self.assertHookCalls(0, 'no_hook')