~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007 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
27
27
    inventory,
28
28
    merge,
29
29
    osutils,
 
30
    repository,
30
31
    revision as _mod_revision,
31
 
    symbol_versioning,
32
32
    tests,
33
33
    treebuilder,
34
34
    )
35
35
from bzrlib.bundle import read_mergeable_from_url
36
36
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
37
37
from bzrlib.bundle.bundle_data import BundleTree
 
38
from bzrlib.bzrdir import BzrDir
38
39
from bzrlib.directory_service import directories
39
40
from bzrlib.bundle.serializer import write_bundle, read_bundle, v09, v4
40
41
from bzrlib.bundle.serializer.v08 import BundleSerializerV08
41
42
from bzrlib.bundle.serializer.v09 import BundleSerializerV09
42
43
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
 
44
from bzrlib.branch import Branch
43
45
from bzrlib.repofmt import knitrepo
44
46
from bzrlib.tests import (
45
47
    test_read_bundle,
112
114
            ie = InventoryDirectory(file_id, name, parent_id)
113
115
        elif kind == 'file':
114
116
            ie = InventoryFile(file_id, name, parent_id)
115
 
            ie.text_sha1 = text_sha_1
116
 
            ie.text_size = text_size
117
117
        elif kind == 'symlink':
118
118
            ie = InventoryLink(file_id, name, parent_id)
119
119
        else:
120
120
            raise errors.BzrError('unknown kind %r' % kind)
 
121
        ie.text_sha1 = text_sha_1
 
122
        ie.text_size = text_size
121
123
        return ie
122
124
 
123
125
    def add_dir(self, file_id, path):
143
145
        result.seek(0,0)
144
146
        return result
145
147
 
146
 
    def get_file_revision(self, file_id):
147
 
        return self.inventory[file_id].revision
148
 
 
149
148
    def contents_stats(self, file_id):
150
149
        if file_id not in self.contents:
151
150
            return None, None
507
506
                old.unlock()
508
507
        if not _mod_revision.is_null(rev_id):
509
508
            rh = self.b1.revision_history()
510
 
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
511
 
                tree.branch.set_revision_history, rh[:rh.index(rev_id)+1])
 
509
            tree.branch.set_revision_history(rh[:rh.index(rev_id)+1])
512
510
            tree.update()
513
511
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
514
512
            self.assertFalse(delta.has_changed(),
1041
1039
        bundle = read_bundle(self.create_bundle_text('null:', 'rev2')[0])
1042
1040
        repo = self.make_repository('repo', format='dirstate-with-subtree')
1043
1041
        bundle.install_revisions(repo)
1044
 
        inv_text = repo._get_inventory_xml('rev2')
 
1042
        inv_text = repo.get_inventory_xml('rev2')
1045
1043
        self.assertNotContainsRe(inv_text, 'format="5"')
1046
1044
        self.assertContainsRe(inv_text, 'format="7"')
1047
1045
 
1067
1065
 
1068
1066
    def test_inv_hash_across_serializers(self):
1069
1067
        repo = self.make_repo_with_installed_revisions()
1070
 
        recorded_inv_sha1 = repo.get_revision('rev2').inventory_sha1
1071
 
        xml = repo._get_inventory_xml('rev2')
 
1068
        recorded_inv_sha1 = repo.get_inventory_sha1('rev2')
 
1069
        xml = repo.get_inventory_xml('rev2')
1072
1070
        self.assertEqual(osutils.sha_string(xml), recorded_inv_sha1)
1073
1071
 
1074
1072
    def test_across_models_incompatible(self):
1414
1412
        branch = tree_a.branch
1415
1413
        repo_a = branch.repository
1416
1414
        tree_a.commit("base", allow_pointless=True, rev_id='A')
1417
 
        self.assertFalse(branch.repository.has_signature_for_revision_id('A'))
 
1415
        self.failIf(branch.repository.has_signature_for_revision_id('A'))
1418
1416
        try:
1419
1417
            from bzrlib.testament import Testament
1420
1418
            # monkey patch gpg signing mechanism
1444
1442
        install_bundle(repo_b, serializer.read(s))
1445
1443
 
1446
1444
 
 
1445
class V4WeaveBundleTester(V4BundleTester):
 
1446
 
 
1447
    def bzrdir_format(self):
 
1448
        return 'metaweave'
 
1449
 
 
1450
 
1447
1451
class V4_2aBundleTester(V4BundleTester):
1448
1452
 
1449
1453
    def bzrdir_format(self):
1816
1820
            def look_up(self, name, url):
1817
1821
                return 'source'
1818
1822
        directories.register('foo:', FooService, 'Testing directory service')
1819
 
        self.addCleanup(directories.remove, 'foo:')
 
1823
        self.addCleanup(lambda: directories.remove('foo:'))
1820
1824
        self.build_tree_contents([('./foo:bar', out.getvalue())])
1821
1825
        self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1822
1826
                          'foo:bar')
1846
1850
class _DisconnectingTCPServer(object):
1847
1851
    """A TCP server that immediately closes any connection made to it."""
1848
1852
 
1849
 
    def start_server(self):
 
1853
    def setUp(self):
1850
1854
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1851
1855
        self.sock.bind(('127.0.0.1', 0))
1852
1856
        self.sock.listen(1)
1864
1868
    def get_url(self):
1865
1869
        return 'bzr://127.0.0.1:%d/' % (self.port,)
1866
1870
 
1867
 
    def stop_server(self):
 
1871
    def tearDown(self):
1868
1872
        try:
1869
1873
            # make sure the thread dies by connecting to the listening socket,
1870
1874
            # just in case the test failed to do so.
1875
1879
            pass
1876
1880
        self.sock.close()
1877
1881
        self.thread.join()
 
1882