/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/__init__.py

  • Committer: Aaron Bentley
  • Date: 2009-09-29 04:40:55 UTC
  • mfrom: (4717 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4718.
  • Revision ID: aaron@aaronbentley.com-20090929044055-e9jtpmz6eyut711h
Merged bzr.dev into fix_get_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
import atexit
30
30
import codecs
 
31
from copy import copy
31
32
from cStringIO import StringIO
32
33
import difflib
33
34
import doctest
52
53
from bzrlib import (
53
54
    branchbuilder,
54
55
    bzrdir,
 
56
    config,
55
57
    debug,
56
58
    errors,
57
59
    hooks,
89
91
    deprecated_passed,
90
92
    )
91
93
import bzrlib.trace
92
 
from bzrlib.transport import get_transport
 
94
from bzrlib.transport import get_transport, pathfilter
93
95
import bzrlib.transport
94
96
from bzrlib.transport.local import LocalURLServer
95
97
from bzrlib.transport.memory import MemoryServer
174
176
        self._overall_start_time = time.time()
175
177
        self._strict = strict
176
178
 
177
 
    def done(self):
178
 
        # nb: called stopTestRun in the version of this that Python merged
179
 
        # upstream, according to lifeless 20090803
 
179
    def stopTestRun(self):
 
180
        run = self.testsRun
 
181
        actionTaken = "Ran"
 
182
        stopTime = time.time()
 
183
        timeTaken = stopTime - self.startTime
 
184
        self.printErrors()
 
185
        self.stream.writeln(self.separator2)
 
186
        self.stream.writeln("%s %d test%s in %.3fs" % (actionTaken,
 
187
                            run, run != 1 and "s" or "", timeTaken))
 
188
        self.stream.writeln()
 
189
        if not self.wasSuccessful():
 
190
            self.stream.write("FAILED (")
 
191
            failed, errored = map(len, (self.failures, self.errors))
 
192
            if failed:
 
193
                self.stream.write("failures=%d" % failed)
 
194
            if errored:
 
195
                if failed: self.stream.write(", ")
 
196
                self.stream.write("errors=%d" % errored)
 
197
            if self.known_failure_count:
 
198
                if failed or errored: self.stream.write(", ")
 
199
                self.stream.write("known_failure_count=%d" %
 
200
                    self.known_failure_count)
 
201
            self.stream.writeln(")")
 
202
        else:
 
203
            if self.known_failure_count:
 
204
                self.stream.writeln("OK (known_failures=%d)" %
 
205
                    self.known_failure_count)
 
206
            else:
 
207
                self.stream.writeln("OK")
 
208
        if self.skip_count > 0:
 
209
            skipped = self.skip_count
 
210
            self.stream.writeln('%d test%s skipped' %
 
211
                                (skipped, skipped != 1 and "s" or ""))
 
212
        if self.unsupported:
 
213
            for feature, count in sorted(self.unsupported.items()):
 
214
                self.stream.writeln("Missing feature '%s' skipped %d tests." %
 
215
                    (feature, count))
180
216
        if self._strict:
181
217
            ok = self.wasStrictlySuccessful()
182
218
        else:
183
219
            ok = self.wasSuccessful()
184
 
        if ok:
185
 
            self.stream.write('tests passed\n')
186
 
        else:
187
 
            self.stream.write('tests failed\n')
188
220
        if TestCase._first_thread_leaker_id:
189
221
            self.stream.write(
190
222
                '%s is leaking threads among %d leaking tests.\n' % (
267
299
        elif isinstance(err[1], UnavailableFeature):
268
300
            return self.addNotSupported(test, err[1].args[0])
269
301
        else:
 
302
            self._post_mortem()
270
303
            unittest.TestResult.addError(self, test, err)
271
304
            self.error_count += 1
272
305
            self.report_error(test, err)
284
317
        if isinstance(err[1], KnownFailure):
285
318
            return self._addKnownFailure(test, err)
286
319
        else:
 
320
            self._post_mortem()
287
321
            unittest.TestResult.addFailure(self, test, err)
288
322
            self.failure_count += 1
289
323
            self.report_failure(test, err)
373
407
            self.stream.writeln(self.separator2)
374
408
            self.stream.writeln("%s" % err)
375
409
 
 
410
    def _post_mortem(self):
 
411
        """Start a PDB post mortem session."""
 
412
        if os.environ.get('BZR_TEST_PDB', None):
 
413
            import pdb;pdb.post_mortem()
 
414
 
376
415
    def progress(self, offset, whence):
377
416
        """The test is adjusting the count of tests to run."""
378
417
        if whence == SUBUNIT_SEEK_SET:
382
421
        else:
383
422
            raise errors.BzrError("Unknown whence %r" % whence)
384
423
 
385
 
    def finished(self):
386
 
        pass
387
 
 
388
424
    def report_cleaning_up(self):
389
425
        pass
390
426
 
 
427
    def startTestRun(self):
 
428
        self.startTime = time.time()
 
429
 
391
430
    def report_success(self, test):
392
431
        pass
393
432
 
420
459
        self.pb.update_latency = 0
421
460
        self.pb.show_transport_activity = False
422
461
 
423
 
    def done(self):
 
462
    def stopTestRun(self):
424
463
        # called when the tests that are going to run have run
425
464
        self.pb.clear()
426
 
        super(TextTestResult, self).done()
427
 
 
428
 
    def finished(self):
429
465
        self.pb.finished()
 
466
        super(TextTestResult, self).stopTestRun()
430
467
 
431
 
    def report_starting(self):
 
468
    def startTestRun(self):
 
469
        super(TextTestResult, self).startTestRun()
432
470
        self.pb.update('[test 0/%d] Starting' % (self.num_tests))
433
471
 
434
472
    def printErrors(self):
474
512
        return self._shortened_test_description(test)
475
513
 
476
514
    def report_error(self, test, err):
477
 
        self.pb.note('ERROR: %s\n    %s\n',
 
515
        ui.ui_factory.note('ERROR: %s\n    %s\n' % (
478
516
            self._test_description(test),
479
517
            err[1],
480
 
            )
 
518
            ))
481
519
 
482
520
    def report_failure(self, test, err):
483
 
        self.pb.note('FAIL: %s\n    %s\n',
 
521
        ui.ui_factory.note('FAIL: %s\n    %s\n' % (
484
522
            self._test_description(test),
485
523
            err[1],
486
 
            )
 
524
            ))
487
525
 
488
526
    def report_known_failure(self, test, err):
489
 
        self.pb.note('XFAIL: %s\n%s\n',
490
 
            self._test_description(test), err[1])
 
527
        ui.ui_factory.note('XFAIL: %s\n%s\n' % (
 
528
            self._test_description(test), err[1]))
491
529
 
492
530
    def report_skip(self, test, reason):
493
531
        pass
513
551
            result = a_string
514
552
        return result.ljust(final_width)
515
553
 
516
 
    def report_starting(self):
 
554
    def startTestRun(self):
 
555
        super(VerboseTestResult, self).startTestRun()
517
556
        self.stream.write('running %d tests...\n' % self.num_tests)
518
557
 
519
558
    def report_test_start(self, test):
577
616
                 descriptions=0,
578
617
                 verbosity=1,
579
618
                 bench_history=None,
580
 
                 list_only=False,
581
619
                 strict=False,
 
620
                 result_decorators=None,
582
621
                 ):
 
622
        """Create a TextTestRunner.
 
623
 
 
624
        :param result_decorators: An optional list of decorators to apply
 
625
            to the result object being used by the runner. Decorators are
 
626
            applied left to right - the first element in the list is the 
 
627
            innermost decorator.
 
628
        """
583
629
        self.stream = unittest._WritelnDecorator(stream)
584
630
        self.descriptions = descriptions
585
631
        self.verbosity = verbosity
586
632
        self._bench_history = bench_history
587
 
        self.list_only = list_only
588
633
        self._strict = strict
 
634
        self._result_decorators = result_decorators or []
589
635
 
590
636
    def run(self, test):
591
637
        "Run the given test case or test suite."
592
 
        startTime = time.time()
593
638
        if self.verbosity == 1:
594
639
            result_class = TextTestResult
595
640
        elif self.verbosity >= 2:
596
641
            result_class = VerboseTestResult
597
 
        result = result_class(self.stream,
 
642
        original_result = result_class(self.stream,
598
643
                              self.descriptions,
599
644
                              self.verbosity,
600
645
                              bench_history=self._bench_history,
601
646
                              strict=self._strict,
602
647
                              )
603
 
        result.stop_early = self.stop_on_failure
604
 
        result.report_starting()
605
 
        if self.list_only:
606
 
            if self.verbosity >= 2:
607
 
                self.stream.writeln("Listing tests only ...\n")
608
 
            run = 0
609
 
            for t in iter_suite_tests(test):
610
 
                self.stream.writeln("%s" % (t.id()))
611
 
                run += 1
612
 
            return None
613
 
        else:
614
 
            try:
615
 
                import testtools
616
 
            except ImportError:
617
 
                test.run(result)
618
 
            else:
619
 
                if isinstance(test, testtools.ConcurrentTestSuite):
620
 
                    # We need to catch bzr specific behaviors
621
 
                    test.run(BZRTransformingResult(result))
622
 
                else:
623
 
                    test.run(result)
624
 
            run = result.testsRun
625
 
            actionTaken = "Ran"
626
 
        stopTime = time.time()
627
 
        timeTaken = stopTime - startTime
628
 
        result.printErrors()
629
 
        self.stream.writeln(result.separator2)
630
 
        self.stream.writeln("%s %d test%s in %.3fs" % (actionTaken,
631
 
                            run, run != 1 and "s" or "", timeTaken))
632
 
        self.stream.writeln()
633
 
        if not result.wasSuccessful():
634
 
            self.stream.write("FAILED (")
635
 
            failed, errored = map(len, (result.failures, result.errors))
636
 
            if failed:
637
 
                self.stream.write("failures=%d" % failed)
638
 
            if errored:
639
 
                if failed: self.stream.write(", ")
640
 
                self.stream.write("errors=%d" % errored)
641
 
            if result.known_failure_count:
642
 
                if failed or errored: self.stream.write(", ")
643
 
                self.stream.write("known_failure_count=%d" %
644
 
                    result.known_failure_count)
645
 
            self.stream.writeln(")")
646
 
        else:
647
 
            if result.known_failure_count:
648
 
                self.stream.writeln("OK (known_failures=%d)" %
649
 
                    result.known_failure_count)
650
 
            else:
651
 
                self.stream.writeln("OK")
652
 
        if result.skip_count > 0:
653
 
            skipped = result.skip_count
654
 
            self.stream.writeln('%d test%s skipped' %
655
 
                                (skipped, skipped != 1 and "s" or ""))
656
 
        if result.unsupported:
657
 
            for feature, count in sorted(result.unsupported.items()):
658
 
                self.stream.writeln("Missing feature '%s' skipped %d tests." %
659
 
                    (feature, count))
660
 
        result.finished()
661
 
        return result
 
648
        # Signal to result objects that look at stop early policy to stop,
 
649
        original_result.stop_early = self.stop_on_failure
 
650
        result = original_result
 
651
        for decorator in self._result_decorators:
 
652
            result = decorator(result)
 
653
            result.stop_early = self.stop_on_failure
 
654
        try:
 
655
            import testtools
 
656
        except ImportError:
 
657
            pass
 
658
        else:
 
659
            if isinstance(test, testtools.ConcurrentTestSuite):
 
660
                # We need to catch bzr specific behaviors
 
661
                result = BZRTransformingResult(result)
 
662
        result.startTestRun()
 
663
        try:
 
664
            test.run(result)
 
665
        finally:
 
666
            result.stopTestRun()
 
667
        # higher level code uses our extended protocol to determine
 
668
        # what exit code to give.
 
669
        return original_result
662
670
 
663
671
 
664
672
def iter_suite_tests(suite):
812
820
        self._cleanups = []
813
821
        self._bzr_test_setUp_run = False
814
822
        self._bzr_test_tearDown_run = False
 
823
        self._directory_isolation = True
815
824
 
816
825
    def setUp(self):
817
826
        unittest.TestCase.setUp(self)
822
831
        self._benchcalls = []
823
832
        self._benchtime = None
824
833
        self._clear_hooks()
 
834
        self._track_transports()
825
835
        self._track_locks()
826
836
        self._clear_debug_flags()
827
837
        TestCase._active_threads = threading.activeCount()
868
878
        # this hook should always be installed
869
879
        request._install_hook()
870
880
 
 
881
    def disable_directory_isolation(self):
 
882
        """Turn off directory isolation checks."""
 
883
        self._directory_isolation = False
 
884
 
 
885
    def enable_directory_isolation(self):
 
886
        """Enable directory isolation checks."""
 
887
        self._directory_isolation = True
 
888
 
871
889
    def _silenceUI(self):
872
890
        """Turn off UI for duration of test"""
873
891
        # by default the UI is off; tests can turn it on if they want it.
928
946
    def _lock_broken(self, result):
929
947
        self._lock_actions.append(('broken', result))
930
948
 
 
949
    def permit_dir(self, name):
 
950
        """Permit a directory to be used by this test. See permit_url."""
 
951
        name_transport = get_transport(name)
 
952
        self.permit_url(name)
 
953
        self.permit_url(name_transport.base)
 
954
 
 
955
    def permit_url(self, url):
 
956
        """Declare that url is an ok url to use in this test.
 
957
        
 
958
        Do this for memory transports, temporary test directory etc.
 
959
        
 
960
        Do not do this for the current working directory, /tmp, or any other
 
961
        preexisting non isolated url.
 
962
        """
 
963
        if not url.endswith('/'):
 
964
            url += '/'
 
965
        self._bzr_selftest_roots.append(url)
 
966
 
 
967
    def permit_source_tree_branch_repo(self):
 
968
        """Permit the source tree bzr is running from to be opened.
 
969
 
 
970
        Some code such as bzrlib.version attempts to read from the bzr branch
 
971
        that bzr is executing from (if any). This method permits that directory
 
972
        to be used in the test suite.
 
973
        """
 
974
        path = self.get_source_path()
 
975
        self.record_directory_isolation()
 
976
        try:
 
977
            try:
 
978
                workingtree.WorkingTree.open(path)
 
979
            except (errors.NotBranchError, errors.NoWorkingTree):
 
980
                return
 
981
        finally:
 
982
            self.enable_directory_isolation()
 
983
 
 
984
    def _preopen_isolate_transport(self, transport):
 
985
        """Check that all transport openings are done in the test work area."""
 
986
        while isinstance(transport, pathfilter.PathFilteringTransport):
 
987
            # Unwrap pathfiltered transports
 
988
            transport = transport.server.backing_transport.clone(
 
989
                transport._filter('.'))
 
990
        url = transport.base
 
991
        # ReadonlySmartTCPServer_for_testing decorates the backing transport
 
992
        # urls it is given by prepending readonly+. This is appropriate as the
 
993
        # client shouldn't know that the server is readonly (or not readonly).
 
994
        # We could register all servers twice, with readonly+ prepending, but
 
995
        # that makes for a long list; this is about the same but easier to
 
996
        # read.
 
997
        if url.startswith('readonly+'):
 
998
            url = url[len('readonly+'):]
 
999
        self._preopen_isolate_url(url)
 
1000
 
 
1001
    def _preopen_isolate_url(self, url):
 
1002
        if not self._directory_isolation:
 
1003
            return
 
1004
        if self._directory_isolation == 'record':
 
1005
            self._bzr_selftest_roots.append(url)
 
1006
            return
 
1007
        # This prevents all transports, including e.g. sftp ones backed on disk
 
1008
        # from working unless they are explicitly granted permission. We then
 
1009
        # depend on the code that sets up test transports to check that they are
 
1010
        # appropriately isolated and enable their use by calling
 
1011
        # self.permit_transport()
 
1012
        if not osutils.is_inside_any(self._bzr_selftest_roots, url):
 
1013
            raise errors.BzrError("Attempt to escape test isolation: %r %r"
 
1014
                % (url, self._bzr_selftest_roots))
 
1015
 
 
1016
    def record_directory_isolation(self):
 
1017
        """Gather accessed directories to permit later access.
 
1018
        
 
1019
        This is used for tests that access the branch bzr is running from.
 
1020
        """
 
1021
        self._directory_isolation = "record"
 
1022
 
 
1023
    def start_server(self, transport_server, backing_server=None):
 
1024
        """Start transport_server for this test.
 
1025
 
 
1026
        This starts the server, registers a cleanup for it and permits the
 
1027
        server's urls to be used.
 
1028
        """
 
1029
        if backing_server is None:
 
1030
            transport_server.setUp()
 
1031
        else:
 
1032
            transport_server.setUp(backing_server)
 
1033
        self.addCleanup(transport_server.tearDown)
 
1034
        # Obtain a real transport because if the server supplies a password, it
 
1035
        # will be hidden from the base on the client side.
 
1036
        t = get_transport(transport_server.get_url())
 
1037
        # Some transport servers effectively chroot the backing transport;
 
1038
        # others like SFTPServer don't - users of the transport can walk up the
 
1039
        # transport to read the entire backing transport. This wouldn't matter
 
1040
        # except that the workdir tests are given - and that they expect the
 
1041
        # server's url to point at - is one directory under the safety net. So
 
1042
        # Branch operations into the transport will attempt to walk up one
 
1043
        # directory. Chrooting all servers would avoid this but also mean that
 
1044
        # we wouldn't be testing directly against non-root urls. Alternatively
 
1045
        # getting the test framework to start the server with a backing server
 
1046
        # at the actual safety net directory would work too, but this then
 
1047
        # means that the self.get_url/self.get_transport methods would need
 
1048
        # to transform all their results. On balance its cleaner to handle it
 
1049
        # here, and permit a higher url when we have one of these transports.
 
1050
        if t.base.endswith('/work/'):
 
1051
            # we have safety net/test root/work
 
1052
            t = t.clone('../..')
 
1053
        elif isinstance(transport_server, server.SmartTCPServer_for_testing):
 
1054
            # The smart server adds a path similar to work, which is traversed
 
1055
            # up from by the client. But the server is chrooted - the actual
 
1056
            # backing transport is not escaped from, and VFS requests to the
 
1057
            # root will error (because they try to escape the chroot).
 
1058
            t2 = t.clone('..')
 
1059
            while t2.base != t.base:
 
1060
                t = t2
 
1061
                t2 = t.clone('..')
 
1062
        self.permit_url(t.base)
 
1063
 
 
1064
    def _track_transports(self):
 
1065
        """Install checks for transport usage."""
 
1066
        # TestCase has no safe place it can write to.
 
1067
        self._bzr_selftest_roots = []
 
1068
        # Currently the easiest way to be sure that nothing is going on is to
 
1069
        # hook into bzr dir opening. This leaves a small window of error for
 
1070
        # transport tests, but they are well known, and we can improve on this
 
1071
        # step.
 
1072
        bzrdir.BzrDir.hooks.install_named_hook("pre_open",
 
1073
            self._preopen_isolate_transport, "Check bzr directories are safe.")
 
1074
 
931
1075
    def _ndiff_strings(self, a, b):
932
1076
        """Return ndiff between two strings containing lines.
933
1077
 
970
1114
            return
971
1115
        if message is None:
972
1116
            message = "texts not equal:\n"
 
1117
        if a + '\n' == b:
 
1118
            message = 'first string is missing a final newline.\n'
973
1119
        if a == b + '\n':
974
 
            message = 'first string is missing a final newline.\n'
975
 
        if a + '\n' == b:
976
1120
            message = 'second string is missing a final newline.\n'
977
1121
        raise AssertionError(message +
978
1122
                             self._ndiff_strings(a, b))
1658
1802
        if retcode is not None:
1659
1803
            self.assertEquals(retcode, result,
1660
1804
                              message='Unexpected return code')
1661
 
        return out, err
 
1805
        return result, out, err
1662
1806
 
1663
1807
    def run_bzr(self, args, retcode=0, encoding=None, stdin=None,
1664
1808
                working_dir=None, error_regexes=[], output_encoding=None):
1693
1837
        :keyword error_regexes: A list of expected error messages.  If
1694
1838
            specified they must be seen in the error output of the command.
1695
1839
        """
1696
 
        out, err = self._run_bzr_autosplit(
 
1840
        retcode, out, err = self._run_bzr_autosplit(
1697
1841
            args=args,
1698
1842
            retcode=retcode,
1699
1843
            encoding=encoding,
1850
1994
        """
1851
1995
        return Popen(*args, **kwargs)
1852
1996
 
 
1997
    def get_source_path(self):
 
1998
        """Return the path of the directory containing bzrlib."""
 
1999
        return os.path.dirname(os.path.dirname(bzrlib.__file__))
 
2000
 
1853
2001
    def get_bzr_path(self):
1854
2002
        """Return the path of the 'bzr' executable for this test suite."""
1855
 
        bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
 
2003
        bzr_path = self.get_source_path()+'/bzr'
1856
2004
        if not os.path.isfile(bzr_path):
1857
2005
            # We are probably installed. Assume sys.argv is the right file
1858
2006
            bzr_path = sys.argv[0]
2067
2215
        if self.__readonly_server is None:
2068
2216
            if self.transport_readonly_server is None:
2069
2217
                # readonly decorator requested
2070
 
                # bring up the server
2071
2218
                self.__readonly_server = ReadonlyServer()
2072
 
                self.__readonly_server.setUp(self.get_vfs_only_server())
2073
2219
            else:
 
2220
                # explicit readonly transport.
2074
2221
                self.__readonly_server = self.create_transport_readonly_server()
2075
 
                self.__readonly_server.setUp(self.get_vfs_only_server())
2076
 
            self.addCleanup(self.__readonly_server.tearDown)
 
2222
            self.start_server(self.__readonly_server,
 
2223
                self.get_vfs_only_server())
2077
2224
        return self.__readonly_server
2078
2225
 
2079
2226
    def get_readonly_url(self, relpath=None):
2098
2245
        """
2099
2246
        if self.__vfs_server is None:
2100
2247
            self.__vfs_server = MemoryServer()
2101
 
            self.__vfs_server.setUp()
2102
 
            self.addCleanup(self.__vfs_server.tearDown)
 
2248
            self.start_server(self.__vfs_server)
2103
2249
        return self.__vfs_server
2104
2250
 
2105
2251
    def get_server(self):
2112
2258
        then the self.get_vfs_server is returned.
2113
2259
        """
2114
2260
        if self.__server is None:
2115
 
            if self.transport_server is None or self.transport_server is self.vfs_transport_factory:
2116
 
                return self.get_vfs_only_server()
 
2261
            if (self.transport_server is None or self.transport_server is
 
2262
                self.vfs_transport_factory):
 
2263
                self.__server = self.get_vfs_only_server()
2117
2264
            else:
2118
2265
                # bring up a decorated means of access to the vfs only server.
2119
2266
                self.__server = self.transport_server()
2120
 
                try:
2121
 
                    self.__server.setUp(self.get_vfs_only_server())
2122
 
                except TypeError, e:
2123
 
                    # This should never happen; the try:Except here is to assist
2124
 
                    # developers having to update code rather than seeing an
2125
 
                    # uninformative TypeError.
2126
 
                    raise Exception, "Old server API in use: %s, %s" % (self.__server, e)
2127
 
            self.addCleanup(self.__server.tearDown)
 
2267
                self.start_server(self.__server, self.get_vfs_only_server())
2128
2268
        return self.__server
2129
2269
 
2130
2270
    def _adjust_url(self, base, relpath):
2192
2332
        propagating. This method ensures than a test did not leaked.
2193
2333
        """
2194
2334
        root = TestCaseWithMemoryTransport.TEST_ROOT
 
2335
        self.permit_url(get_transport(root).base)
2195
2336
        wt = workingtree.WorkingTree.open(root)
2196
2337
        last_rev = wt.last_revision()
2197
2338
        if last_rev != 'null:':
2205
2346
 
2206
2347
    def _make_test_root(self):
2207
2348
        if TestCaseWithMemoryTransport.TEST_ROOT is None:
2208
 
            root = osutils.mkdtemp(prefix='testbzr-', suffix='.tmp')
 
2349
            # Watch out for tricky test dir (on OSX /tmp -> /private/tmp)
 
2350
            root = osutils.realpath(osutils.mkdtemp(prefix='testbzr-',
 
2351
                                                    suffix='.tmp'))
2209
2352
            TestCaseWithMemoryTransport.TEST_ROOT = root
2210
2353
 
2211
2354
            self._create_safety_net()
2214
2357
            # specifically told when all tests are finished.  This will do.
2215
2358
            atexit.register(_rmtree_temp_dir, root)
2216
2359
 
 
2360
        self.permit_dir(TestCaseWithMemoryTransport.TEST_ROOT)
2217
2361
        self.addCleanup(self._check_safety_net)
2218
2362
 
2219
2363
    def makeAndChdirToTestDir(self):
2227
2371
        os.chdir(TestCaseWithMemoryTransport.TEST_ROOT)
2228
2372
        self.test_dir = TestCaseWithMemoryTransport.TEST_ROOT
2229
2373
        self.test_home_dir = self.test_dir + "/MemoryTransportMissingHomeDir"
 
2374
        self.permit_dir(self.test_dir)
2230
2375
 
2231
2376
    def make_branch(self, relpath, format=None):
2232
2377
        """Create a branch on the transport at relpath."""
2263
2408
 
2264
2409
    def make_smart_server(self, path):
2265
2410
        smart_server = server.SmartTCPServer_for_testing()
2266
 
        smart_server.setUp(self.get_server())
 
2411
        self.start_server(smart_server, self.get_server())
2267
2412
        remote_transport = get_transport(smart_server.get_url()).clone(path)
2268
 
        self.addCleanup(smart_server.tearDown)
2269
2413
        return remote_transport
2270
2414
 
2271
2415
    def make_branch_and_memory_tree(self, relpath, format=None):
2365
2509
            if os.path.exists(name):
2366
2510
                name = name_prefix + '_' + str(i)
2367
2511
            else:
2368
 
                os.mkdir(name)
 
2512
                # now create test and home directories within this dir
 
2513
                self.test_base_dir = name
 
2514
                self.addCleanup(self.deleteTestDir)
 
2515
                os.mkdir(self.test_base_dir)
2369
2516
                break
2370
 
        # now create test and home directories within this dir
2371
 
        self.test_base_dir = name
 
2517
        self.permit_dir(self.test_base_dir)
 
2518
        # 'sprouting' and 'init' of a branch both walk up the tree to find
 
2519
        # stacking policy to honour; create a bzr dir with an unshared
 
2520
        # repository (but not a branch - our code would be trying to escape
 
2521
        # then!) to stop them, and permit it to be read.
 
2522
        # control = bzrdir.BzrDir.create(self.test_base_dir)
 
2523
        # control.create_repository()
2372
2524
        self.test_home_dir = self.test_base_dir + '/home'
2373
2525
        os.mkdir(self.test_home_dir)
2374
2526
        self.test_dir = self.test_base_dir + '/work'
2380
2532
            f.write(self.id())
2381
2533
        finally:
2382
2534
            f.close()
2383
 
        self.addCleanup(self.deleteTestDir)
2384
2535
 
2385
2536
    def deleteTestDir(self):
2386
2537
        os.chdir(TestCaseWithMemoryTransport.TEST_ROOT)
2472
2623
        """
2473
2624
        if self.__vfs_server is None:
2474
2625
            self.__vfs_server = self.vfs_transport_factory()
2475
 
            self.__vfs_server.setUp()
2476
 
            self.addCleanup(self.__vfs_server.tearDown)
 
2626
            self.start_server(self.__vfs_server)
2477
2627
        return self.__vfs_server
2478
2628
 
2479
2629
    def make_branch_and_tree(self, relpath, format=None):
2486
2636
        repository will also be accessed locally. Otherwise a lightweight
2487
2637
        checkout is created and returned.
2488
2638
 
 
2639
        We do this because we can't physically create a tree in the local
 
2640
        path, with a branch reference to the transport_factory url, and
 
2641
        a branch + repository in the vfs_transport, unless the vfs_transport
 
2642
        namespace is distinct from the local disk - the two branch objects
 
2643
        would collide. While we could construct a tree with its branch object
 
2644
        pointing at the transport_factory transport in memory, reopening it
 
2645
        would behaving unexpectedly, and has in the past caused testing bugs
 
2646
        when we tried to do it that way.
 
2647
 
2489
2648
        :param format: The BzrDirFormat.
2490
2649
        :returns: the WorkingTree.
2491
2650
        """
2543
2702
        super(TestCaseWithTransport, self).setUp()
2544
2703
        self.__vfs_server = None
2545
2704
 
 
2705
    def disable_missing_extensions_warning(self):
 
2706
        """Some tests expect a precise stderr content.
 
2707
 
 
2708
        There is no point in forcing them to duplicate the extension related
 
2709
        warning.
 
2710
        """
 
2711
        config.GlobalConfig().set_user_option('ignore_missing_extensions', True)
 
2712
 
2546
2713
 
2547
2714
class ChrootedTestCase(TestCaseWithTransport):
2548
2715
    """A support class that provides readonly urls outside the local namespace.
2762
2929
              strict=False,
2763
2930
              runner_class=None,
2764
2931
              suite_decorators=None,
2765
 
              stream=None):
 
2932
              stream=None,
 
2933
              result_decorators=None,
 
2934
              ):
2766
2935
    """Run a test suite for bzr selftest.
2767
2936
 
2768
2937
    :param runner_class: The class of runner to use. Must support the
2783
2952
                            descriptions=0,
2784
2953
                            verbosity=verbosity,
2785
2954
                            bench_history=bench_history,
2786
 
                            list_only=list_only,
2787
2955
                            strict=strict,
 
2956
                            result_decorators=result_decorators,
2788
2957
                            )
2789
2958
    runner.stop_on_failure=stop_on_failure
2790
2959
    # built in decorator factories:
2805
2974
        decorators.append(CountingDecorator)
2806
2975
    for decorator in decorators:
2807
2976
        suite = decorator(suite)
 
2977
    if list_only:
 
2978
        # Done after test suite decoration to allow randomisation etc
 
2979
        # to take effect, though that is of marginal benefit.
 
2980
        if verbosity >= 2:
 
2981
            stream.write("Listing tests only ...\n")
 
2982
        for t in iter_suite_tests(suite):
 
2983
            stream.write("%s\n" % (t.id()))
 
2984
        return True
2808
2985
    result = runner.run(suite)
2809
 
    if list_only:
2810
 
        return True
2811
 
    result.done()
2812
2986
    if strict:
2813
2987
        return result.wasStrictlySuccessful()
2814
2988
    else:
3131
3305
    return result
3132
3306
 
3133
3307
 
3134
 
class BZRTransformingResult(unittest.TestResult):
 
3308
class ForwardingResult(unittest.TestResult):
3135
3309
 
3136
3310
    def __init__(self, target):
3137
3311
        unittest.TestResult.__init__(self)
3143
3317
    def stopTest(self, test):
3144
3318
        self.result.stopTest(test)
3145
3319
 
 
3320
    def startTestRun(self):
 
3321
        self.result.startTestRun()
 
3322
 
 
3323
    def stopTestRun(self):
 
3324
        self.result.stopTestRun()
 
3325
 
 
3326
    def addSkip(self, test, reason):
 
3327
        self.result.addSkip(test, reason)
 
3328
 
 
3329
    def addSuccess(self, test):
 
3330
        self.result.addSuccess(test)
 
3331
 
 
3332
    def addError(self, test, err):
 
3333
        self.result.addError(test, err)
 
3334
 
 
3335
    def addFailure(self, test, err):
 
3336
        self.result.addFailure(test, err)
 
3337
 
 
3338
 
 
3339
class BZRTransformingResult(ForwardingResult):
 
3340
 
3146
3341
    def addError(self, test, err):
3147
3342
        feature = self._error_looks_like('UnavailableFeature: ', err)
3148
3343
        if feature is not None:
3158
3353
        else:
3159
3354
            self.result.addFailure(test, err)
3160
3355
 
3161
 
    def addSkip(self, test, reason):
3162
 
        self.result.addSkip(test, reason)
3163
 
 
3164
 
    def addSuccess(self, test):
3165
 
        self.result.addSuccess(test)
3166
 
 
3167
3356
    def _error_looks_like(self, prefix, err):
3168
3357
        """Deserialize exception and returns the stringify value."""
3169
3358
        import subunit
3181
3370
        return value
3182
3371
 
3183
3372
 
 
3373
class ProfileResult(ForwardingResult):
 
3374
    """Generate profiling data for all activity between start and success.
 
3375
    
 
3376
    The profile data is appended to the test's _benchcalls attribute and can
 
3377
    be accessed by the forwarded-to TestResult.
 
3378
 
 
3379
    While it might be cleaner do accumulate this in stopTest, addSuccess is
 
3380
    where our existing output support for lsprof is, and this class aims to
 
3381
    fit in with that: while it could be moved it's not necessary to accomplish
 
3382
    test profiling, nor would it be dramatically cleaner.
 
3383
    """
 
3384
 
 
3385
    def startTest(self, test):
 
3386
        self.profiler = bzrlib.lsprof.BzrProfiler()
 
3387
        self.profiler.start()
 
3388
        ForwardingResult.startTest(self, test)
 
3389
 
 
3390
    def addSuccess(self, test):
 
3391
        stats = self.profiler.stop()
 
3392
        try:
 
3393
            calls = test._benchcalls
 
3394
        except AttributeError:
 
3395
            test._benchcalls = []
 
3396
            calls = test._benchcalls
 
3397
        calls.append(((test.id(), "", ""), stats))
 
3398
        ForwardingResult.addSuccess(self, test)
 
3399
 
 
3400
    def stopTest(self, test):
 
3401
        ForwardingResult.stopTest(self, test)
 
3402
        self.profiler = None
 
3403
 
 
3404
 
3184
3405
# Controlled by "bzr selftest -E=..." option
3185
3406
# Currently supported:
3186
3407
#   -Eallow_debug           Will no longer clear debug.debug_flags() so it
3207
3428
             starting_with=None,
3208
3429
             runner_class=None,
3209
3430
             suite_decorators=None,
 
3431
             stream=None,
 
3432
             lsprof_tests=False,
3210
3433
             ):
3211
3434
    """Run the whole test suite under the enhanced runner"""
3212
3435
    # XXX: Very ugly way to do this...
3229
3452
            keep_only = None
3230
3453
        else:
3231
3454
            keep_only = load_test_id_list(load_list)
 
3455
        if starting_with:
 
3456
            starting_with = [test_prefix_alias_registry.resolve_alias(start)
 
3457
                             for start in starting_with]
3232
3458
        if test_suite_factory is None:
 
3459
            # Reduce loading time by loading modules based on the starting_with
 
3460
            # patterns.
3233
3461
            suite = test_suite(keep_only, starting_with)
3234
3462
        else:
3235
3463
            suite = test_suite_factory()
 
3464
        if starting_with:
 
3465
            # But always filter as requested.
 
3466
            suite = filter_suite_by_id_startswith(suite, starting_with)
 
3467
        result_decorators = []
 
3468
        if lsprof_tests:
 
3469
            result_decorators.append(ProfileResult)
3236
3470
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
3237
3471
                     stop_on_failure=stop_on_failure,
3238
3472
                     transport=transport,
3245
3479
                     strict=strict,
3246
3480
                     runner_class=runner_class,
3247
3481
                     suite_decorators=suite_decorators,
 
3482
                     stream=stream,
 
3483
                     result_decorators=result_decorators,
3248
3484
                     )
3249
3485
    finally:
3250
3486
        default_transport = old_transport
3406
3642
test_prefix_alias_registry.register('bp', 'bzrlib.plugins')
3407
3643
 
3408
3644
 
 
3645
def _test_suite_testmod_names():
 
3646
    """Return the standard list of test module names to test."""
 
3647
    return [
 
3648
        'bzrlib.doc',
 
3649
        'bzrlib.tests.blackbox',
 
3650
        'bzrlib.tests.commands',
 
3651
        'bzrlib.tests.per_branch',
 
3652
        'bzrlib.tests.per_bzrdir',
 
3653
        'bzrlib.tests.per_interrepository',
 
3654
        'bzrlib.tests.per_intertree',
 
3655
        'bzrlib.tests.per_inventory',
 
3656
        'bzrlib.tests.per_interbranch',
 
3657
        'bzrlib.tests.per_lock',
 
3658
        'bzrlib.tests.per_transport',
 
3659
        'bzrlib.tests.per_tree',
 
3660
        'bzrlib.tests.per_pack_repository',
 
3661
        'bzrlib.tests.per_repository',
 
3662
        'bzrlib.tests.per_repository_chk',
 
3663
        'bzrlib.tests.per_repository_reference',
 
3664
        'bzrlib.tests.per_versionedfile',
 
3665
        'bzrlib.tests.per_workingtree',
 
3666
        'bzrlib.tests.test__annotator',
 
3667
        'bzrlib.tests.test__chk_map',
 
3668
        'bzrlib.tests.test__dirstate_helpers',
 
3669
        'bzrlib.tests.test__groupcompress',
 
3670
        'bzrlib.tests.test__known_graph',
 
3671
        'bzrlib.tests.test__rio',
 
3672
        'bzrlib.tests.test__walkdirs_win32',
 
3673
        'bzrlib.tests.test_ancestry',
 
3674
        'bzrlib.tests.test_annotate',
 
3675
        'bzrlib.tests.test_api',
 
3676
        'bzrlib.tests.test_atomicfile',
 
3677
        'bzrlib.tests.test_bad_files',
 
3678
        'bzrlib.tests.test_bencode',
 
3679
        'bzrlib.tests.test_bisect_multi',
 
3680
        'bzrlib.tests.test_branch',
 
3681
        'bzrlib.tests.test_branchbuilder',
 
3682
        'bzrlib.tests.test_btree_index',
 
3683
        'bzrlib.tests.test_bugtracker',
 
3684
        'bzrlib.tests.test_bundle',
 
3685
        'bzrlib.tests.test_bzrdir',
 
3686
        'bzrlib.tests.test__chunks_to_lines',
 
3687
        'bzrlib.tests.test_cache_utf8',
 
3688
        'bzrlib.tests.test_chk_map',
 
3689
        'bzrlib.tests.test_chk_serializer',
 
3690
        'bzrlib.tests.test_chunk_writer',
 
3691
        'bzrlib.tests.test_clean_tree',
 
3692
        'bzrlib.tests.test_commands',
 
3693
        'bzrlib.tests.test_commit',
 
3694
        'bzrlib.tests.test_commit_merge',
 
3695
        'bzrlib.tests.test_config',
 
3696
        'bzrlib.tests.test_conflicts',
 
3697
        'bzrlib.tests.test_counted_lock',
 
3698
        'bzrlib.tests.test_crash',
 
3699
        'bzrlib.tests.test_decorators',
 
3700
        'bzrlib.tests.test_delta',
 
3701
        'bzrlib.tests.test_debug',
 
3702
        'bzrlib.tests.test_deprecated_graph',
 
3703
        'bzrlib.tests.test_diff',
 
3704
        'bzrlib.tests.test_directory_service',
 
3705
        'bzrlib.tests.test_dirstate',
 
3706
        'bzrlib.tests.test_email_message',
 
3707
        'bzrlib.tests.test_eol_filters',
 
3708
        'bzrlib.tests.test_errors',
 
3709
        'bzrlib.tests.test_export',
 
3710
        'bzrlib.tests.test_extract',
 
3711
        'bzrlib.tests.test_fetch',
 
3712
        'bzrlib.tests.test_fifo_cache',
 
3713
        'bzrlib.tests.test_filters',
 
3714
        'bzrlib.tests.test_ftp_transport',
 
3715
        'bzrlib.tests.test_foreign',
 
3716
        'bzrlib.tests.test_generate_docs',
 
3717
        'bzrlib.tests.test_generate_ids',
 
3718
        'bzrlib.tests.test_globbing',
 
3719
        'bzrlib.tests.test_gpg',
 
3720
        'bzrlib.tests.test_graph',
 
3721
        'bzrlib.tests.test_groupcompress',
 
3722
        'bzrlib.tests.test_hashcache',
 
3723
        'bzrlib.tests.test_help',
 
3724
        'bzrlib.tests.test_hooks',
 
3725
        'bzrlib.tests.test_http',
 
3726
        'bzrlib.tests.test_http_response',
 
3727
        'bzrlib.tests.test_https_ca_bundle',
 
3728
        'bzrlib.tests.test_identitymap',
 
3729
        'bzrlib.tests.test_ignores',
 
3730
        'bzrlib.tests.test_index',
 
3731
        'bzrlib.tests.test_info',
 
3732
        'bzrlib.tests.test_inv',
 
3733
        'bzrlib.tests.test_inventory_delta',
 
3734
        'bzrlib.tests.test_knit',
 
3735
        'bzrlib.tests.test_lazy_import',
 
3736
        'bzrlib.tests.test_lazy_regex',
 
3737
        'bzrlib.tests.test_lock',
 
3738
        'bzrlib.tests.test_lockable_files',
 
3739
        'bzrlib.tests.test_lockdir',
 
3740
        'bzrlib.tests.test_log',
 
3741
        'bzrlib.tests.test_lru_cache',
 
3742
        'bzrlib.tests.test_lsprof',
 
3743
        'bzrlib.tests.test_mail_client',
 
3744
        'bzrlib.tests.test_memorytree',
 
3745
        'bzrlib.tests.test_merge',
 
3746
        'bzrlib.tests.test_merge3',
 
3747
        'bzrlib.tests.test_merge_core',
 
3748
        'bzrlib.tests.test_merge_directive',
 
3749
        'bzrlib.tests.test_missing',
 
3750
        'bzrlib.tests.test_msgeditor',
 
3751
        'bzrlib.tests.test_multiparent',
 
3752
        'bzrlib.tests.test_mutabletree',
 
3753
        'bzrlib.tests.test_nonascii',
 
3754
        'bzrlib.tests.test_options',
 
3755
        'bzrlib.tests.test_osutils',
 
3756
        'bzrlib.tests.test_osutils_encodings',
 
3757
        'bzrlib.tests.test_pack',
 
3758
        'bzrlib.tests.test_patch',
 
3759
        'bzrlib.tests.test_patches',
 
3760
        'bzrlib.tests.test_permissions',
 
3761
        'bzrlib.tests.test_plugins',
 
3762
        'bzrlib.tests.test_progress',
 
3763
        'bzrlib.tests.test_read_bundle',
 
3764
        'bzrlib.tests.test_reconcile',
 
3765
        'bzrlib.tests.test_reconfigure',
 
3766
        'bzrlib.tests.test_registry',
 
3767
        'bzrlib.tests.test_remote',
 
3768
        'bzrlib.tests.test_rename_map',
 
3769
        'bzrlib.tests.test_repository',
 
3770
        'bzrlib.tests.test_revert',
 
3771
        'bzrlib.tests.test_revision',
 
3772
        'bzrlib.tests.test_revisionspec',
 
3773
        'bzrlib.tests.test_revisiontree',
 
3774
        'bzrlib.tests.test_rio',
 
3775
        'bzrlib.tests.test_rules',
 
3776
        'bzrlib.tests.test_sampler',
 
3777
        'bzrlib.tests.test_script',
 
3778
        'bzrlib.tests.test_selftest',
 
3779
        'bzrlib.tests.test_serializer',
 
3780
        'bzrlib.tests.test_setup',
 
3781
        'bzrlib.tests.test_sftp_transport',
 
3782
        'bzrlib.tests.test_shelf',
 
3783
        'bzrlib.tests.test_shelf_ui',
 
3784
        'bzrlib.tests.test_smart',
 
3785
        'bzrlib.tests.test_smart_add',
 
3786
        'bzrlib.tests.test_smart_request',
 
3787
        'bzrlib.tests.test_smart_transport',
 
3788
        'bzrlib.tests.test_smtp_connection',
 
3789
        'bzrlib.tests.test_source',
 
3790
        'bzrlib.tests.test_ssh_transport',
 
3791
        'bzrlib.tests.test_status',
 
3792
        'bzrlib.tests.test_store',
 
3793
        'bzrlib.tests.test_strace',
 
3794
        'bzrlib.tests.test_subsume',
 
3795
        'bzrlib.tests.test_switch',
 
3796
        'bzrlib.tests.test_symbol_versioning',
 
3797
        'bzrlib.tests.test_tag',
 
3798
        'bzrlib.tests.test_testament',
 
3799
        'bzrlib.tests.test_textfile',
 
3800
        'bzrlib.tests.test_textmerge',
 
3801
        'bzrlib.tests.test_timestamp',
 
3802
        'bzrlib.tests.test_trace',
 
3803
        'bzrlib.tests.test_transactions',
 
3804
        'bzrlib.tests.test_transform',
 
3805
        'bzrlib.tests.test_transport',
 
3806
        'bzrlib.tests.test_transport_log',
 
3807
        'bzrlib.tests.test_tree',
 
3808
        'bzrlib.tests.test_treebuilder',
 
3809
        'bzrlib.tests.test_tsort',
 
3810
        'bzrlib.tests.test_tuned_gzip',
 
3811
        'bzrlib.tests.test_ui',
 
3812
        'bzrlib.tests.test_uncommit',
 
3813
        'bzrlib.tests.test_upgrade',
 
3814
        'bzrlib.tests.test_upgrade_stacked',
 
3815
        'bzrlib.tests.test_urlutils',
 
3816
        'bzrlib.tests.test_version',
 
3817
        'bzrlib.tests.test_version_info',
 
3818
        'bzrlib.tests.test_weave',
 
3819
        'bzrlib.tests.test_whitebox',
 
3820
        'bzrlib.tests.test_win32utils',
 
3821
        'bzrlib.tests.test_workingtree',
 
3822
        'bzrlib.tests.test_workingtree_4',
 
3823
        'bzrlib.tests.test_wsgi',
 
3824
        'bzrlib.tests.test_xml',
 
3825
        ]
 
3826
 
 
3827
 
 
3828
def _test_suite_modules_to_doctest():
 
3829
    """Return the list of modules to doctest."""   
 
3830
    return [
 
3831
        'bzrlib',
 
3832
        'bzrlib.branchbuilder',
 
3833
        'bzrlib.export',
 
3834
        'bzrlib.inventory',
 
3835
        'bzrlib.iterablefile',
 
3836
        'bzrlib.lockdir',
 
3837
        'bzrlib.merge3',
 
3838
        'bzrlib.option',
 
3839
        'bzrlib.symbol_versioning',
 
3840
        'bzrlib.tests',
 
3841
        'bzrlib.timestamp',
 
3842
        'bzrlib.version_info_formats.format_custom',
 
3843
        ]
 
3844
 
 
3845
 
3409
3846
def test_suite(keep_only=None, starting_with=None):
3410
3847
    """Build and return TestSuite for the whole of bzrlib.
3411
3848
 
3417
3854
    This function can be replaced if you need to change the default test
3418
3855
    suite on a global basis, but it is not encouraged.
3419
3856
    """
3420
 
    testmod_names = [
3421
 
                   'bzrlib.doc',
3422
 
                   'bzrlib.tests.blackbox',
3423
 
                   'bzrlib.tests.commands',
3424
 
                   'bzrlib.tests.per_branch',
3425
 
                   'bzrlib.tests.per_bzrdir',
3426
 
                   'bzrlib.tests.per_interrepository',
3427
 
                   'bzrlib.tests.per_intertree',
3428
 
                   'bzrlib.tests.per_inventory',
3429
 
                   'bzrlib.tests.per_interbranch',
3430
 
                   'bzrlib.tests.per_lock',
3431
 
                   'bzrlib.tests.per_transport',
3432
 
                   'bzrlib.tests.per_tree',
3433
 
                   'bzrlib.tests.per_pack_repository',
3434
 
                   'bzrlib.tests.per_repository',
3435
 
                   'bzrlib.tests.per_repository_chk',
3436
 
                   'bzrlib.tests.per_repository_reference',
3437
 
                   'bzrlib.tests.per_versionedfile',
3438
 
                   'bzrlib.tests.per_workingtree',
3439
 
                   'bzrlib.tests.test__annotator',
3440
 
                   'bzrlib.tests.test__chk_map',
3441
 
                   'bzrlib.tests.test__dirstate_helpers',
3442
 
                   'bzrlib.tests.test__groupcompress',
3443
 
                   'bzrlib.tests.test__known_graph',
3444
 
                   'bzrlib.tests.test__rio',
3445
 
                   'bzrlib.tests.test__walkdirs_win32',
3446
 
                   'bzrlib.tests.test_ancestry',
3447
 
                   'bzrlib.tests.test_annotate',
3448
 
                   'bzrlib.tests.test_api',
3449
 
                   'bzrlib.tests.test_atomicfile',
3450
 
                   'bzrlib.tests.test_bad_files',
3451
 
                   'bzrlib.tests.test_bencode',
3452
 
                   'bzrlib.tests.test_bisect_multi',
3453
 
                   'bzrlib.tests.test_branch',
3454
 
                   'bzrlib.tests.test_branchbuilder',
3455
 
                   'bzrlib.tests.test_btree_index',
3456
 
                   'bzrlib.tests.test_bugtracker',
3457
 
                   'bzrlib.tests.test_bundle',
3458
 
                   'bzrlib.tests.test_bzrdir',
3459
 
                   'bzrlib.tests.test__chunks_to_lines',
3460
 
                   'bzrlib.tests.test_cache_utf8',
3461
 
                   'bzrlib.tests.test_chk_map',
3462
 
                   'bzrlib.tests.test_chk_serializer',
3463
 
                   'bzrlib.tests.test_chunk_writer',
3464
 
                   'bzrlib.tests.test_clean_tree',
3465
 
                   'bzrlib.tests.test_commands',
3466
 
                   'bzrlib.tests.test_commit',
3467
 
                   'bzrlib.tests.test_commit_merge',
3468
 
                   'bzrlib.tests.test_config',
3469
 
                   'bzrlib.tests.test_conflicts',
3470
 
                   'bzrlib.tests.test_counted_lock',
3471
 
                   'bzrlib.tests.test_crash',
3472
 
                   'bzrlib.tests.test_decorators',
3473
 
                   'bzrlib.tests.test_delta',
3474
 
                   'bzrlib.tests.test_debug',
3475
 
                   'bzrlib.tests.test_deprecated_graph',
3476
 
                   'bzrlib.tests.test_diff',
3477
 
                   'bzrlib.tests.test_directory_service',
3478
 
                   'bzrlib.tests.test_dirstate',
3479
 
                   'bzrlib.tests.test_email_message',
3480
 
                   'bzrlib.tests.test_eol_filters',
3481
 
                   'bzrlib.tests.test_errors',
3482
 
                   'bzrlib.tests.test_export',
3483
 
                   'bzrlib.tests.test_extract',
3484
 
                   'bzrlib.tests.test_fetch',
3485
 
                   'bzrlib.tests.test_fifo_cache',
3486
 
                   'bzrlib.tests.test_filters',
3487
 
                   'bzrlib.tests.test_ftp_transport',
3488
 
                   'bzrlib.tests.test_foreign',
3489
 
                   'bzrlib.tests.test_generate_docs',
3490
 
                   'bzrlib.tests.test_generate_ids',
3491
 
                   'bzrlib.tests.test_globbing',
3492
 
                   'bzrlib.tests.test_gpg',
3493
 
                   'bzrlib.tests.test_graph',
3494
 
                   'bzrlib.tests.test_groupcompress',
3495
 
                   'bzrlib.tests.test_hashcache',
3496
 
                   'bzrlib.tests.test_help',
3497
 
                   'bzrlib.tests.test_hooks',
3498
 
                   'bzrlib.tests.test_http',
3499
 
                   'bzrlib.tests.test_http_response',
3500
 
                   'bzrlib.tests.test_https_ca_bundle',
3501
 
                   'bzrlib.tests.test_identitymap',
3502
 
                   'bzrlib.tests.test_ignores',
3503
 
                   'bzrlib.tests.test_index',
3504
 
                   'bzrlib.tests.test_info',
3505
 
                   'bzrlib.tests.test_inv',
3506
 
                   'bzrlib.tests.test_inventory_delta',
3507
 
                   'bzrlib.tests.test_knit',
3508
 
                   'bzrlib.tests.test_lazy_import',
3509
 
                   'bzrlib.tests.test_lazy_regex',
3510
 
                   'bzrlib.tests.test_lock',
3511
 
                   'bzrlib.tests.test_lockable_files',
3512
 
                   'bzrlib.tests.test_lockdir',
3513
 
                   'bzrlib.tests.test_log',
3514
 
                   'bzrlib.tests.test_lru_cache',
3515
 
                   'bzrlib.tests.test_lsprof',
3516
 
                   'bzrlib.tests.test_mail_client',
3517
 
                   'bzrlib.tests.test_memorytree',
3518
 
                   'bzrlib.tests.test_merge',
3519
 
                   'bzrlib.tests.test_merge3',
3520
 
                   'bzrlib.tests.test_merge_core',
3521
 
                   'bzrlib.tests.test_merge_directive',
3522
 
                   'bzrlib.tests.test_missing',
3523
 
                   'bzrlib.tests.test_msgeditor',
3524
 
                   'bzrlib.tests.test_multiparent',
3525
 
                   'bzrlib.tests.test_mutabletree',
3526
 
                   'bzrlib.tests.test_nonascii',
3527
 
                   'bzrlib.tests.test_options',
3528
 
                   'bzrlib.tests.test_osutils',
3529
 
                   'bzrlib.tests.test_osutils_encodings',
3530
 
                   'bzrlib.tests.test_pack',
3531
 
                   'bzrlib.tests.test_patch',
3532
 
                   'bzrlib.tests.test_patches',
3533
 
                   'bzrlib.tests.test_permissions',
3534
 
                   'bzrlib.tests.test_plugins',
3535
 
                   'bzrlib.tests.test_progress',
3536
 
                   'bzrlib.tests.test_read_bundle',
3537
 
                   'bzrlib.tests.test_reconcile',
3538
 
                   'bzrlib.tests.test_reconfigure',
3539
 
                   'bzrlib.tests.test_registry',
3540
 
                   'bzrlib.tests.test_remote',
3541
 
                   'bzrlib.tests.test_rename_map',
3542
 
                   'bzrlib.tests.test_repository',
3543
 
                   'bzrlib.tests.test_revert',
3544
 
                   'bzrlib.tests.test_revision',
3545
 
                   'bzrlib.tests.test_revisionspec',
3546
 
                   'bzrlib.tests.test_revisiontree',
3547
 
                   'bzrlib.tests.test_rio',
3548
 
                   'bzrlib.tests.test_rules',
3549
 
                   'bzrlib.tests.test_sampler',
3550
 
                   'bzrlib.tests.test_selftest',
3551
 
                   'bzrlib.tests.test_serializer',
3552
 
                   'bzrlib.tests.test_setup',
3553
 
                   'bzrlib.tests.test_sftp_transport',
3554
 
                   'bzrlib.tests.test_shelf',
3555
 
                   'bzrlib.tests.test_shelf_ui',
3556
 
                   'bzrlib.tests.test_smart',
3557
 
                   'bzrlib.tests.test_smart_add',
3558
 
                   'bzrlib.tests.test_smart_request',
3559
 
                   'bzrlib.tests.test_smart_transport',
3560
 
                   'bzrlib.tests.test_smtp_connection',
3561
 
                   'bzrlib.tests.test_source',
3562
 
                   'bzrlib.tests.test_ssh_transport',
3563
 
                   'bzrlib.tests.test_status',
3564
 
                   'bzrlib.tests.test_store',
3565
 
                   'bzrlib.tests.test_strace',
3566
 
                   'bzrlib.tests.test_subsume',
3567
 
                   'bzrlib.tests.test_switch',
3568
 
                   'bzrlib.tests.test_symbol_versioning',
3569
 
                   'bzrlib.tests.test_tag',
3570
 
                   'bzrlib.tests.test_testament',
3571
 
                   'bzrlib.tests.test_textfile',
3572
 
                   'bzrlib.tests.test_textmerge',
3573
 
                   'bzrlib.tests.test_timestamp',
3574
 
                   'bzrlib.tests.test_trace',
3575
 
                   'bzrlib.tests.test_transactions',
3576
 
                   'bzrlib.tests.test_transform',
3577
 
                   'bzrlib.tests.test_transport',
3578
 
                   'bzrlib.tests.test_transport_log',
3579
 
                   'bzrlib.tests.test_tree',
3580
 
                   'bzrlib.tests.test_treebuilder',
3581
 
                   'bzrlib.tests.test_tsort',
3582
 
                   'bzrlib.tests.test_tuned_gzip',
3583
 
                   'bzrlib.tests.test_ui',
3584
 
                   'bzrlib.tests.test_uncommit',
3585
 
                   'bzrlib.tests.test_upgrade',
3586
 
                   'bzrlib.tests.test_upgrade_stacked',
3587
 
                   'bzrlib.tests.test_urlutils',
3588
 
                   'bzrlib.tests.test_version',
3589
 
                   'bzrlib.tests.test_version_info',
3590
 
                   'bzrlib.tests.test_weave',
3591
 
                   'bzrlib.tests.test_whitebox',
3592
 
                   'bzrlib.tests.test_win32utils',
3593
 
                   'bzrlib.tests.test_workingtree',
3594
 
                   'bzrlib.tests.test_workingtree_4',
3595
 
                   'bzrlib.tests.test_wsgi',
3596
 
                   'bzrlib.tests.test_xml',
3597
 
                   ]
3598
3857
 
3599
3858
    loader = TestUtil.TestLoader()
3600
3859
 
3601
3860
    if keep_only is not None:
3602
3861
        id_filter = TestIdList(keep_only)
3603
3862
    if starting_with:
3604
 
        starting_with = [test_prefix_alias_registry.resolve_alias(start)
3605
 
                         for start in starting_with]
3606
3863
        # We take precedence over keep_only because *at loading time* using
3607
3864
        # both options means we will load less tests for the same final result.
3608
3865
        def interesting_module(name):
3631
3888
    suite = loader.suiteClass()
3632
3889
 
3633
3890
    # modules building their suite with loadTestsFromModuleNames
3634
 
    suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
3635
 
 
3636
 
    modules_to_doctest = [
3637
 
        'bzrlib',
3638
 
        'bzrlib.branchbuilder',
3639
 
        'bzrlib.export',
3640
 
        'bzrlib.inventory',
3641
 
        'bzrlib.iterablefile',
3642
 
        'bzrlib.lockdir',
3643
 
        'bzrlib.merge3',
3644
 
        'bzrlib.option',
3645
 
        'bzrlib.symbol_versioning',
3646
 
        'bzrlib.tests',
3647
 
        'bzrlib.timestamp',
3648
 
        'bzrlib.version_info_formats.format_custom',
3649
 
        ]
3650
 
 
3651
 
    for mod in modules_to_doctest:
 
3891
    suite.addTest(loader.loadTestsFromModuleNames(_test_suite_testmod_names()))
 
3892
 
 
3893
    for mod in _test_suite_modules_to_doctest():
3652
3894
        if not interesting_module(mod):
3653
3895
            # No tests to keep here, move along
3654
3896
            continue
3683
3925
            reload(sys)
3684
3926
            sys.setdefaultencoding(default_encoding)
3685
3927
 
3686
 
    if starting_with:
3687
 
        suite = filter_suite_by_id_startswith(suite, starting_with)
3688
 
 
3689
3928
    if keep_only is not None:
3690
3929
        # Now that the referred modules have loaded their tests, keep only the
3691
3930
        # requested ones.
3798
4037
    :param new_id: The id to assign to it.
3799
4038
    :return: The new test.
3800
4039
    """
3801
 
    from copy import deepcopy
3802
 
    new_test = deepcopy(test)
 
4040
    new_test = copy(test)
3803
4041
    new_test.id = lambda: new_id
3804
4042
    return new_test
3805
4043
 
3965
4203
HTTPSServerFeature = _HTTPSServerFeature()
3966
4204
 
3967
4205
 
 
4206
class _ParamikoFeature(Feature):
 
4207
    """Is paramiko available?"""
 
4208
 
 
4209
    def _probe(self):
 
4210
        try:
 
4211
            from bzrlib.transport.sftp import SFTPAbsoluteServer
 
4212
            return True
 
4213
        except errors.ParamikoNotPresent:
 
4214
            return False
 
4215
 
 
4216
    def feature_name(self):
 
4217
        return "Paramiko"
 
4218
 
 
4219
 
 
4220
ParamikoFeature = _ParamikoFeature()
 
4221
 
 
4222
 
3968
4223
class _UnicodeFilename(Feature):
3969
4224
    """Does the filesystem support Unicode filenames?"""
3970
4225
 
3996
4251
UTF8Filesystem = _UTF8Filesystem()
3997
4252
 
3998
4253
 
 
4254
class _BreakinFeature(Feature):
 
4255
    """Does this platform support the breakin feature?"""
 
4256
 
 
4257
    def _probe(self):
 
4258
        from bzrlib import breakin
 
4259
        if breakin.determine_signal() is None:
 
4260
            return False
 
4261
        if sys.platform == 'win32':
 
4262
            # Windows doesn't have os.kill, and we catch the SIGBREAK signal.
 
4263
            # We trigger SIGBREAK via a Console api so we need ctypes to
 
4264
            # access the function
 
4265
            if not have_ctypes:
 
4266
                return False
 
4267
        return True
 
4268
 
 
4269
    def feature_name(self):
 
4270
        return "SIGQUIT or SIGBREAK w/ctypes on win32"
 
4271
 
 
4272
 
 
4273
BreakinFeature = _BreakinFeature()
 
4274
 
 
4275
 
3999
4276
class _CaseInsCasePresFilenameFeature(Feature):
4000
4277
    """Is the file-system case insensitive, but case-preserving?"""
4001
4278