~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_repository.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the Repository facility that are not interface tests.
18
18
 
95
95
class SampleRepositoryFormat(repository.RepositoryFormat):
96
96
    """A sample format
97
97
 
98
 
    this format is initializable, unsupported to aid in testing the 
 
98
    this format is initializable, unsupported to aid in testing the
99
99
    open and open(unsupported=True) routines.
100
100
    """
101
101
 
122
122
    def test_find_format(self):
123
123
        # is the right format object found for a repository?
124
124
        # create a branch with a few known format objects.
125
 
        # this is not quite the same as 
 
125
        # this is not quite the same as
126
126
        self.build_tree(["foo/", "bar/"])
127
127
        def check_format(format, url):
128
128
            dir = format._matchingbzrdir.initialize(url)
131
131
            found_format = repository.RepositoryFormat.find_format(dir)
132
132
            self.failUnless(isinstance(found_format, format.__class__))
133
133
        check_format(weaverepo.RepositoryFormat7(), "bar")
134
 
        
 
134
 
135
135
    def test_find_format_no_repository(self):
136
136
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
137
137
        self.assertRaises(errors.NoRepositoryPresent,
167
167
        """Weaves need topological data insertion."""
168
168
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
169
169
        repo = weaverepo.RepositoryFormat6().initialize(control)
170
 
        self.assertEqual('topological', repo._fetch_order)
 
170
        self.assertEqual('topological', repo._format._fetch_order)
171
171
 
172
172
    def test_attribute__fetch_uses_deltas(self):
173
173
        """Weaves do not reuse deltas."""
174
174
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
175
175
        repo = weaverepo.RepositoryFormat6().initialize(control)
176
 
        self.assertEqual(False, repo._fetch_uses_deltas)
 
176
        self.assertEqual(False, repo._format._fetch_uses_deltas)
177
177
 
178
178
    def test_attribute__fetch_reconcile(self):
179
179
        """Weave repositories need a reconcile after fetch."""
180
180
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
181
181
        repo = weaverepo.RepositoryFormat6().initialize(control)
182
 
        self.assertEqual(True, repo._fetch_reconcile)
 
182
        self.assertEqual(True, repo._format._fetch_reconcile)
183
183
 
184
184
    def test_no_ancestry_weave(self):
185
185
        control = bzrdir.BzrDirFormat6().initialize(self.get_url())
202
202
        """Weaves need topological data insertion."""
203
203
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
204
204
        repo = weaverepo.RepositoryFormat7().initialize(control)
205
 
        self.assertEqual('topological', repo._fetch_order)
 
205
        self.assertEqual('topological', repo._format._fetch_order)
206
206
 
207
207
    def test_attribute__fetch_uses_deltas(self):
208
208
        """Weaves do not reuse deltas."""
209
209
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
210
210
        repo = weaverepo.RepositoryFormat7().initialize(control)
211
 
        self.assertEqual(False, repo._fetch_uses_deltas)
 
211
        self.assertEqual(False, repo._format._fetch_uses_deltas)
212
212
 
213
213
    def test_attribute__fetch_reconcile(self):
214
214
        """Weave repositories need a reconcile after fetch."""
215
215
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
216
216
        repo = weaverepo.RepositoryFormat7().initialize(control)
217
 
        self.assertEqual(True, repo._fetch_reconcile)
 
217
        self.assertEqual(True, repo._format._fetch_reconcile)
218
218
 
219
219
    def test_disk_layout(self):
220
220
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
284
284
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
285
285
        repo = weaverepo.RepositoryFormat7().initialize(control, shared=True)
286
286
        t = control.get_repository_transport(None)
287
 
        # TODO: Should check there is a 'lock' toplevel directory, 
 
287
        # TODO: Should check there is a 'lock' toplevel directory,
288
288
        # regardless of contents
289
289
        self.assertFalse(t.has('lock/held/info'))
290
290
        repo.lock_write()
343
343
 
344
344
 
345
345
class TestFormatKnit1(TestCaseWithTransport):
346
 
    
 
346
 
347
347
    def test_attribute__fetch_order(self):
348
348
        """Knits need topological data insertion."""
349
349
        repo = self.make_repository('.',
350
350
                format=bzrdir.format_registry.get('knit')())
351
 
        self.assertEqual('topological', repo._fetch_order)
 
351
        self.assertEqual('topological', repo._format._fetch_order)
352
352
 
353
353
    def test_attribute__fetch_uses_deltas(self):
354
354
        """Knits reuse deltas."""
355
355
        repo = self.make_repository('.',
356
356
                format=bzrdir.format_registry.get('knit')())
357
 
        self.assertEqual(True, repo._fetch_uses_deltas)
 
357
        self.assertEqual(True, repo._format._fetch_uses_deltas)
358
358
 
359
359
    def test_disk_layout(self):
360
360
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
497
497
    @staticmethod
498
498
    def is_compatible(repo_source, repo_target):
499
499
        """InterDummy is compatible with DummyRepository."""
500
 
        return (isinstance(repo_source, DummyRepository) and 
 
500
        return (isinstance(repo_source, DummyRepository) and
501
501
            isinstance(repo_target, DummyRepository))
502
502
 
503
503
 
516
516
 
517
517
    def assertGetsDefaultInterRepository(self, repo_a, repo_b):
518
518
        """Asserts that InterRepository.get(repo_a, repo_b) -> the default.
519
 
        
 
519
 
520
520
        The effective default is now InterSameDataRepository because there is
521
521
        no actual sane default in the presence of incompatible data models.
522
522
        """
606
606
 
607
607
 
608
608
class TestMisc(TestCase):
609
 
    
 
609
 
610
610
    def test_unescape_xml(self):
611
611
        """We get some kind of error when malformed entities are passed"""
612
 
        self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;') 
 
612
        self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;')
613
613
 
614
614
 
615
615
class TestRepositoryFormatKnit3(TestCaseWithTransport):
619
619
        format = bzrdir.BzrDirMetaFormat1()
620
620
        format.repository_format = knitrepo.RepositoryFormatKnit3()
621
621
        repo = self.make_repository('.', format=format)
622
 
        self.assertEqual('topological', repo._fetch_order)
 
622
        self.assertEqual('topological', repo._format._fetch_order)
623
623
 
624
624
    def test_attribute__fetch_uses_deltas(self):
625
625
        """Knits reuse deltas."""
626
626
        format = bzrdir.BzrDirMetaFormat1()
627
627
        format.repository_format = knitrepo.RepositoryFormatKnit3()
628
628
        repo = self.make_repository('.', format=format)
629
 
        self.assertEqual(True, repo._fetch_uses_deltas)
 
629
        self.assertEqual(True, repo._format._fetch_uses_deltas)
630
630
 
631
631
    def test_convert(self):
632
632
        """Ensure the upgrade adds weaves for roots"""
929
929
        tree.lock_read()
930
930
        self.addCleanup(tree.unlock)
931
931
        packs = tree.branch.repository._pack_collection
 
932
        packs.reset()
932
933
        packs.ensure_loaded()
933
934
        name = packs.names()[0]
934
935
        pack_1 = packs.get_pack_by_name(name)
1120
1121
        self.assertTrue(new_pack.inventory_index._optimize_for_size)
1121
1122
        self.assertTrue(new_pack.text_index._optimize_for_size)
1122
1123
        self.assertTrue(new_pack.signature_index._optimize_for_size)
1123
 
 
1124
 
 
1125
 
class TestInterDifferingSerializer(TestCaseWithTransport):
1126
 
 
1127
 
    def test_progress_bar(self):
1128
 
        tree = self.make_branch_and_tree('tree')
1129
 
        tree.commit('rev1', rev_id='rev-1')
1130
 
        tree.commit('rev2', rev_id='rev-2')
1131
 
        tree.commit('rev3', rev_id='rev-3')
1132
 
        repo = self.make_repository('repo')
1133
 
        inter_repo = repository.InterDifferingSerializer(
1134
 
            tree.branch.repository, repo)
1135
 
        pb = progress.InstrumentedProgress(to_file=StringIO())
1136
 
        pb.never_throttle = True
1137
 
        inter_repo.fetch('rev-1', pb)
1138
 
        self.assertEqual('Transferring revisions', pb.last_msg)
1139
 
        self.assertEqual(1, pb.last_cnt)
1140
 
        self.assertEqual(1, pb.last_total)
1141
 
        inter_repo.fetch('rev-3', pb)
1142
 
        self.assertEqual(2, pb.last_cnt)
1143
 
        self.assertEqual(2, pb.last_total)