~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Jonathan Riddell
  • Date: 2011-09-16 11:13:47 UTC
  • mto: This revision was merged to the branch mainline in revision 6144.
  • Revision ID: jriddell@canonical.com-20110916111347-fyjk426bkl0jrbfu
gettext() show_warning usage

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    chk_map,
62
62
    commands as _mod_commands,
63
63
    config,
 
64
    i18n,
64
65
    debug,
65
66
    errors,
66
67
    hooks,
1005
1006
        self._counters = {}
1006
1007
        if 'config_stats' in selftest_debug_flags:
1007
1008
            self._install_config_stats_hooks()
 
1009
        # Do not use i18n for tests (unless the test reverses this)
 
1010
        i18n.disable_i18n()
1008
1011
 
1009
1012
    def debug(self):
1010
1013
        # debug a frame up.
1011
1014
        import pdb
1012
 
        pdb.Pdb().set_trace(sys._getframe().f_back)
 
1015
        # The sys preserved stdin/stdout should allow blackbox tests debugging
 
1016
        pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__
 
1017
                ).set_trace(sys._getframe().f_back)
1013
1018
 
1014
1019
    def discardDetail(self, name):
1015
1020
        """Extend the addDetail, getDetails api so we can remove a detail.
2431
2436
 
2432
2437
        :param relpath: a path relative to the base url.
2433
2438
        """
2434
 
        t = _mod_transport.get_transport(self.get_readonly_url(relpath))
 
2439
        t = _mod_transport.get_transport_from_url(
 
2440
            self.get_readonly_url(relpath))
2435
2441
        self.assertTrue(t.is_readonly())
2436
2442
        return t
2437
2443
 
2558
2564
        real branch.
2559
2565
        """
2560
2566
        root = TestCaseWithMemoryTransport.TEST_ROOT
2561
 
        wt = bzrdir.BzrDir.create_standalone_workingtree(root)
 
2567
        try:
 
2568
            # Make sure we get a readable and accessible home for .bzr.log
 
2569
            # and/or config files, and not fallback to weird defaults (see
 
2570
            # http://pad.lv/825027).
 
2571
            self.assertIs(None, os.environ.get('BZR_HOME', None))
 
2572
            os.environ['BZR_HOME'] = root
 
2573
            wt = bzrdir.BzrDir.create_standalone_workingtree(root)
 
2574
            del os.environ['BZR_HOME']
 
2575
        except Exception, e:
 
2576
            self.fail("Fail to initialize the safety net: %r\nExiting\n" % (e,))
2562
2577
        # Hack for speed: remember the raw bytes of the dirstate file so that
2563
2578
        # we don't need to re-open the wt to check it hasn't changed.
2564
2579
        TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE = (
2571
2586
        propagating. This method ensures than a test did not leaked.
2572
2587
        """
2573
2588
        root = TestCaseWithMemoryTransport.TEST_ROOT
2574
 
        t = _mod_transport.get_transport(root)
 
2589
        t = _mod_transport.get_transport_from_path(root)
2575
2590
        self.permit_url(t.base)
2576
2591
        if (t.get_bytes('.bzr/checkout/dirstate') != 
2577
2592
                TestCaseWithMemoryTransport._SAFETY_NET_PRISTINE_DIRSTATE):
2615
2630
    def make_branch(self, relpath, format=None):
2616
2631
        """Create a branch on the transport at relpath."""
2617
2632
        repo = self.make_repository(relpath, format=format)
2618
 
        return repo.bzrdir.create_branch()
 
2633
        return repo.bzrdir.create_branch(append_revisions_only=False)
 
2634
 
 
2635
    def resolve_format(self, format):
 
2636
        """Resolve an object to a ControlDir format object.
 
2637
 
 
2638
        The initial format object can either already be
 
2639
        a ControlDirFormat, None (for the default format),
 
2640
        or a string with the name of the control dir format.
 
2641
 
 
2642
        :param format: Object to resolve
 
2643
        :return A ControlDirFormat instance
 
2644
        """
 
2645
        if format is None:
 
2646
            format = 'default'
 
2647
        if isinstance(format, basestring):
 
2648
            format = bzrdir.format_registry.make_bzrdir(format)
 
2649
        return format
 
2650
 
 
2651
    def resolve_format(self, format):
 
2652
        """Resolve an object to a ControlDir format object.
 
2653
 
 
2654
        The initial format object can either already be
 
2655
        a ControlDirFormat, None (for the default format),
 
2656
        or a string with the name of the control dir format.
 
2657
 
 
2658
        :param format: Object to resolve
 
2659
        :return A ControlDirFormat instance
 
2660
        """
 
2661
        if format is None:
 
2662
            format = 'default'
 
2663
        if isinstance(format, basestring):
 
2664
            format = bzrdir.format_registry.make_bzrdir(format)
 
2665
        return format
2619
2666
 
2620
2667
    def make_bzrdir(self, relpath, format=None):
2621
2668
        try:
2625
2672
            t = _mod_transport.get_transport(maybe_a_url)
2626
2673
            if len(segments) > 1 and segments[-1] not in ('', '.'):
2627
2674
                t.ensure_base()
2628
 
            if format is None:
2629
 
                format = 'default'
2630
 
            if isinstance(format, basestring):
2631
 
                format = bzrdir.format_registry.make_bzrdir(format)
 
2675
            format = self.resolve_format(format)
2632
2676
            return format.initialize_on_transport(t)
2633
2677
        except errors.UninitializableFormat:
2634
2678
            raise TestSkipped("Format %s is not initializable." % format)
2822
2866
                "a list or a tuple. Got %r instead" % (shape,))
2823
2867
        # It's OK to just create them using forward slashes on windows.
2824
2868
        if transport is None or transport.is_readonly():
2825
 
            transport = _mod_transport.get_transport(".")
 
2869
            transport = _mod_transport.get_transport_from_path(".")
2826
2870
        for name in shape:
2827
2871
            self.assertIsInstance(name, basestring)
2828
2872
            if name[-1] == '/':
3943
3987
        'bzrlib.tests.test_email_message',
3944
3988
        'bzrlib.tests.test_eol_filters',
3945
3989
        'bzrlib.tests.test_errors',
 
3990
        'bzrlib.tests.test_estimate_compressed_size',
3946
3991
        'bzrlib.tests.test_export',
3947
3992
        'bzrlib.tests.test_export_pot',
3948
3993
        'bzrlib.tests.test_extract',