~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bundle.py

  • Committer: Martin Packman
  • Date: 2012-03-27 17:32:19 UTC
  • mto: (6437.54.3 2.5)
  • mto: This revision was merged to the branch mainline in revision 6525.
  • Revision ID: martin.packman@canonical.com-20120327173219-401pil42gke8j0xh
Fall back to sys.prefix not /usr when looking for .mo files

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import os
19
 
import socket
 
19
import SocketServer
20
20
import sys
21
 
import threading
22
21
 
23
22
from bzrlib import (
24
23
    bzrdir,
28
27
    merge,
29
28
    osutils,
30
29
    revision as _mod_revision,
31
 
    symbol_versioning,
32
30
    tests,
33
31
    treebuilder,
34
32
    )
42
40
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
43
41
from bzrlib.repofmt import knitrepo
44
42
from bzrlib.tests import (
 
43
    features,
 
44
    test_commit,
45
45
    test_read_bundle,
46
 
    test_commit,
 
46
    test_server,
47
47
    )
48
48
from bzrlib.transform import TreeTransform
49
49
 
507
507
                new.unlock()
508
508
                old.unlock()
509
509
        if not _mod_revision.is_null(rev_id):
510
 
            rh = self.b1.revision_history()
511
 
            self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
512
 
                tree.branch.set_revision_history, rh[:rh.index(rev_id)+1])
 
510
            tree.branch.generate_revision_history(rev_id)
513
511
            tree.update()
514
512
            delta = tree.changes_from(self.b1.repository.revision_tree(rev_id))
515
513
            self.assertFalse(delta.has_changed(),
651
649
        bundle = self.get_valid_bundle('null:', 'a@cset-0-4')
652
650
 
653
651
        # Modified files
654
 
        open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n')
655
 
        open('b1/sub/dir/ pre space', 'ab').write(
 
652
        with open('b1/sub/dir/WithCaps.txt', 'ab') as f: f.write('\nAdding some text\n')
 
653
        with open('b1/sub/dir/ pre space', 'ab') as f: f.write(
656
654
             '\r\nAdding some\r\nDOS format lines\r\n')
657
 
        open('b1/sub/dir/nolastnewline.txt', 'ab').write('\n')
 
655
        with open('b1/sub/dir/nolastnewline.txt', 'ab') as f: f.write('\n')
658
656
        self.tree1.rename_one('sub/dir/ pre space',
659
657
                              'sub/ start space')
660
658
        self.tree1.commit('Modified files', rev_id='a@cset-0-5')
682
680
    def _test_symlink_bundle(self, link_name, link_target, new_link_target):
683
681
        link_id = 'link-1'
684
682
 
685
 
        self.requireFeature(tests.SymlinkFeature)
 
683
        self.requireFeature(features.SymlinkFeature)
686
684
        self.tree1 = self.make_branch_and_tree('b1')
687
685
        self.b1 = self.tree1.branch
688
686
 
729
727
        self._test_symlink_bundle('link', 'bar/foo', 'mars')
730
728
 
731
729
    def test_unicode_symlink_bundle(self):
732
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
730
        self.requireFeature(features.UnicodeFilenameFeature)
733
731
        self._test_symlink_bundle(u'\N{Euro Sign}link',
734
732
                                  u'bar/\N{Euro Sign}foo',
735
733
                                  u'mars\N{Euro Sign}')
809
807
        self.tree1 = self.make_branch_and_tree('b1')
810
808
        self.b1 = self.tree1.branch
811
809
 
812
 
        open('b1/one', 'wb').write('one\n')
 
810
        with open('b1/one', 'wb') as f: f.write('one\n')
813
811
        self.tree1.add('one')
814
812
        self.tree1.commit('add file', rev_id='a@cset-0-1')
815
 
        open('b1/one', 'wb').write('two\n')
 
813
        with open('b1/one', 'wb') as f: f.write('two\n')
816
814
        self.tree1.commit('modify', rev_id='a@cset-0-2')
817
 
        open('b1/one', 'wb').write('three\n')
 
815
        with open('b1/one', 'wb') as f: f.write('three\n')
818
816
        self.tree1.commit('modify', rev_id='a@cset-0-3')
819
817
        bundle_file = StringIO()
820
818
        rev_ids = write_bundle(self.tree1.branch.repository, 'a@cset-0-3',
836
834
        return bundle_file.getvalue()
837
835
 
838
836
    def test_unicode_bundle(self):
839
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
837
        self.requireFeature(features.UnicodeFilenameFeature)
840
838
        # Handle international characters
841
839
        os.mkdir('b1')
842
840
        f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
899
897
        bundle = self.get_valid_bundle('null:', 'white-1')
900
898
 
901
899
        # Modified
902
 
        open('b1/trailing space ', 'ab').write('add some text\n')
 
900
        with open('b1/trailing space ', 'ab') as f: f.write('add some text\n')
903
901
        self.tree1.commit('add text', rev_id='white-2')
904
902
 
905
903
        bundle = self.get_valid_bundle('white-1', 'white-2')
1420
1418
            from bzrlib.testament import Testament
1421
1419
            # monkey patch gpg signing mechanism
1422
1420
            bzrlib.gpg.GPGStrategy = bzrlib.gpg.LoopbackGPGStrategy
1423
 
            new_config = test_commit.MustSignConfig(branch)
1424
 
            commit.Commit(config=new_config).commit(message="base",
 
1421
            new_config = test_commit.MustSignConfig()
 
1422
            commit.Commit(config_stack=new_config).commit(message="base",
1425
1423
                                                    allow_pointless=True,
1426
1424
                                                    rev_id='B',
1427
1425
                                                    working_tree=tree_a)
1836
1834
        bundle, then the ConnectionReset error should be propagated.
1837
1835
        """
1838
1836
        # Instantiate a server that will provoke a ConnectionReset
1839
 
        sock_server = _DisconnectingTCPServer()
 
1837
        sock_server = DisconnectingServer()
1840
1838
        self.start_server(sock_server)
1841
1839
        # We don't really care what the url is since the server will close the
1842
1840
        # connection without interpreting it
1844
1842
        self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1845
1843
 
1846
1844
 
1847
 
class _DisconnectingTCPServer(object):
1848
 
    """A TCP server that immediately closes any connection made to it."""
1849
 
 
1850
 
    def start_server(self):
1851
 
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1852
 
        self.sock.bind(('127.0.0.1', 0))
1853
 
        self.sock.listen(1)
1854
 
        self.port = self.sock.getsockname()[1]
1855
 
        self.thread = threading.Thread(
1856
 
            name='%s (port %d)' % (self.__class__.__name__, self.port),
1857
 
            target=self.accept_and_close)
1858
 
        self.thread.start()
1859
 
 
1860
 
    def accept_and_close(self):
1861
 
        conn, addr = self.sock.accept()
1862
 
        conn.shutdown(socket.SHUT_RDWR)
1863
 
        conn.close()
 
1845
class DisconnectingHandler(SocketServer.BaseRequestHandler):
 
1846
    """A request handler that immediately closes any connection made to it."""
 
1847
 
 
1848
    def handle(self):
 
1849
        self.request.close()
 
1850
 
 
1851
 
 
1852
class DisconnectingServer(test_server.TestingTCPServerInAThread):
 
1853
 
 
1854
    def __init__(self):
 
1855
        super(DisconnectingServer, self).__init__(
 
1856
            ('127.0.0.1', 0),
 
1857
            test_server.TestingTCPServer,
 
1858
            DisconnectingHandler)
1864
1859
 
1865
1860
    def get_url(self):
1866
 
        return 'bzr://127.0.0.1:%d/' % (self.port,)
1867
 
 
1868
 
    def stop_server(self):
1869
 
        try:
1870
 
            # make sure the thread dies by connecting to the listening socket,
1871
 
            # just in case the test failed to do so.
1872
 
            conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1873
 
            conn.connect(self.sock.getsockname())
1874
 
            conn.close()
1875
 
        except socket.error:
1876
 
            pass
1877
 
        self.sock.close()
1878
 
        self.thread.join()
 
1861
        """Return the url of the server"""
 
1862
        return "bzr://%s:%d/" % self.server.server_address