~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin
  • Date: 2010-07-04 07:09:09 UTC
  • mto: This revision was merged to the branch mainline in revision 5333.
  • Revision ID: gzlist@googlemail.com-20100704070909-r51s2leny0wjcqtn
Use same timestamp rounding logic as Inno, just in case

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    branch,
28
28
    bzrdir,
29
 
    controldir,
30
29
    errors,
31
30
    help_topics,
32
31
    repository,
70
69
        old_format = bzrdir.BzrDirFormat.get_default_format()
71
70
        # default is BzrDirFormat6
72
71
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
73
 
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
 
72
        bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
74
73
        # creating a bzr dir should now create an instrumented dir.
75
74
        try:
76
75
            result = bzrdir.BzrDir.create('memory:///')
77
76
            self.failUnless(isinstance(result, SampleBzrDir))
78
77
        finally:
79
 
            controldir.ControlDirFormat._set_default_format(old_format)
 
78
            bzrdir.BzrDirFormat._set_default_format(old_format)
80
79
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
81
80
 
82
81
 
83
82
class TestFormatRegistry(TestCase):
84
83
 
85
84
    def make_format_registry(self):
86
 
        my_format_registry = controldir.ControlDirFormatRegistry()
 
85
        my_format_registry = bzrdir.BzrDirFormatRegistry()
87
86
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
88
87
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
89
88
            ' repositories', deprecated=True)
90
89
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
91
90
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
92
 
        bzrdir.register_metadir(my_format_registry, 'knit',
 
91
        my_format_registry.register_metadir('knit',
93
92
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
94
93
            'Format using knits',
95
94
            )
96
95
        my_format_registry.set_default('knit')
97
 
        bzrdir.register_metadir(my_format_registry,
 
96
        my_format_registry.register_metadir(
98
97
            'branch6',
99
98
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
100
99
            'Experimental successor to knit.  Use at your own risk.',
101
100
            branch_format='bzrlib.branch.BzrBranchFormat6',
102
101
            experimental=True)
103
 
        bzrdir.register_metadir(my_format_registry,
 
102
        my_format_registry.register_metadir(
104
103
            'hidden format',
105
104
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
106
105
            'Experimental successor to knit.  Use at your own risk.',
175
174
            bzrdir.format_registry.set_default_repository(old_default)
176
175
 
177
176
    def test_aliases(self):
178
 
        a_registry = controldir.ControlDirFormatRegistry()
 
177
        a_registry = bzrdir.BzrDirFormatRegistry()
179
178
        a_registry.register('weave', bzrdir.BzrDirFormat6,
180
179
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
181
180
            ' repositories', deprecated=True)
1059
1058
    def _known_formats(self):
1060
1059
        return set([NotBzrDirFormat()])
1061
1060
 
1062
 
 
1063
 
class NotBzrDirProber(controldir.Prober):
1064
 
 
 
1061
    @classmethod
1065
1062
    def probe_transport(self, transport):
1066
1063
        """Our format is present if the transport ends in '.not/'."""
1067
1064
        if transport.has('.not'):
1081
1078
        dir = format.initialize(self.get_url())
1082
1079
        self.assertIsInstance(dir, NotBzrDir)
1083
1080
        # now probe for it.
1084
 
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
 
1081
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
1085
1082
        try:
1086
1083
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
1087
1084
                get_transport(self.get_url()))
1088
1085
            self.assertIsInstance(found, NotBzrDirFormat)
1089
1086
        finally:
1090
 
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
 
1087
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
1091
1088
 
1092
1089
    def test_included_in_known_formats(self):
1093
 
        not_format = NotBzrDirFormat()
1094
 
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
 
1090
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
1095
1091
        try:
1096
1092
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1097
1093
            for format in formats:
1099
1095
                    return
1100
1096
            self.fail("No NotBzrDirFormat in %s" % formats)
1101
1097
        finally:
1102
 
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
 
1098
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
1103
1099
 
1104
1100
 
1105
1101
class NonLocalTests(TestCaseWithTransport):
1405
1401
        self.assertIsInstance(params, RepoInitHookParams)
1406
1402
        self.assertTrue(hasattr(params, 'bzrdir'))
1407
1403
        self.assertTrue(hasattr(params, 'repository'))
1408
 
 
1409
 
    def test_post_repo_init_hook_repr(self):
1410
 
        param_reprs = []
1411
 
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1412
 
            lambda params: param_reprs.append(repr(params)), None)
1413
 
        self.make_repository('foo')
1414
 
        self.assertLength(1, param_reprs)
1415
 
        param_repr = param_reprs[0]
1416
 
        self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1417
 
 
1418
 
 
1419
 
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1420
 
 
1421
 
    def setUp(self):
1422
 
        super(TestGenerateBackupName, self).setUp()
1423
 
        self._transport = get_transport(self.get_url())
1424
 
        bzrdir.BzrDir.create(self.get_url(),
1425
 
            possible_transports=[self._transport])
1426
 
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1427
 
 
1428
 
    def test_new(self):
1429
 
        self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
1430
 
 
1431
 
    def test_exiting(self):
1432
 
        self._transport.put_bytes("a.~1~", "some content")
1433
 
        self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))