38
40
from bzrlib.bundle.serializer.v4 import BundleSerializerV4
39
41
from bzrlib.branch import Branch
40
42
from bzrlib.diff import internal_diff
41
from bzrlib.errors import (BzrError, TestamentMismatch, NotABundle, BadBundle,
43
43
from bzrlib.merge import Merge3Merger
44
44
from bzrlib.repofmt import knitrepo
45
45
from bzrlib.osutils import sha_file, sha_string
437
437
def test_non_bundle(self):
438
self.assertRaises(NotABundle, read_bundle, StringIO('#!/bin/sh\n'))
438
self.assertRaises(errors.NotABundle,
439
read_bundle, StringIO('#!/bin/sh\n'))
440
441
def test_malformed(self):
441
self.assertRaises(BadBundle, read_bundle,
442
self.assertRaises(errors.BadBundle, read_bundle,
442
443
StringIO('# Bazaar revision bundle v'))
444
445
def test_crlf_bundle(self):
446
447
read_bundle(StringIO('# Bazaar revision bundle v0.8\r\n'))
448
except errors.BadBundle:
448
449
# It is currently permitted for bundles with crlf line endings to
449
450
# make read_bundle raise a BadBundle, but this should be fixed.
450
451
# Anything else, especially NotABundle, is an error.
618
619
self.tree1.commit('removed', rev_id='a@cset-0-3')
620
621
bundle = self.get_valid_bundle('a@cset-0-2', 'a@cset-0-3')
621
self.assertRaises((TestamentMismatch,
622
self.assertRaises((errors.TestamentMismatch,
622
623
errors.VersionedFileInvalidChecksum), self.get_invalid_bundle,
623
624
'a@cset-0-2', 'a@cset-0-3')
624
625
# Check a rollup bundle
796
797
# Handle international characters
799
f = open(u'b1/with Dod\xe9', 'wb')
800
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
800
801
except UnicodeEncodeError:
801
802
raise TestSkipped("Filesystem doesn't support unicode")
808
809
u'William Dod\xe9\n').encode('utf-8'))
811
self.tree1.add([u'with Dod\xe9'], ['withdod-id'])
812
self.tree1.add([u'with Dod\N{Euro Sign}'], ['withdod-id'])
812
813
self.tree1.commit(u'i18n commit from William Dod\xe9',
813
814
rev_id='i18n-1', committer=u'William Dod\xe9')
815
if sys.platform == 'darwin':
816
from bzrlib.workingtree import WorkingTree3
817
if type(self.tree1) is WorkingTree3:
818
self.knownFailure("Bug #141438: fails for WorkingTree3 on OSX")
820
# On Mac the '\xe9' gets changed to 'e\u0301'
821
self.assertEqual([u'.bzr', u'with Dode\u0301'],
822
sorted(os.listdir(u'b1')))
823
delta = self.tree1.changes_from(self.tree1.basis_tree())
824
self.assertEqual([(u'with Dod\xe9', 'withdod-id', 'file')],
826
self.knownFailure("Mac OSX doesn't preserve unicode"
827
" combining characters.")
830
817
bundle = self.get_valid_bundle('null:', 'i18n-1')
833
f = open(u'b1/with Dod\xe9', 'wb')
820
f = open(u'b1/with Dod\N{Euro Sign}', 'wb')
834
821
f.write(u'Modified \xb5\n'.encode('utf8'))
836
823
self.tree1.commit(u'modified', rev_id='i18n-2')
838
825
bundle = self.get_valid_bundle('i18n-1', 'i18n-2')
841
self.tree1.rename_one(u'with Dod\xe9', u'B\xe5gfors')
828
self.tree1.rename_one(u'with Dod\N{Euro Sign}', u'B\N{Euro Sign}gfors')
842
829
self.tree1.commit(u'renamed, the new i18n man', rev_id='i18n-3',
843
830
committer=u'Erik B\xe5gfors')
845
832
bundle = self.get_valid_bundle('i18n-2', 'i18n-3')
848
self.tree1.remove([u'B\xe5gfors'])
835
self.tree1.remove([u'B\N{Euro Sign}gfors'])
849
836
self.tree1.commit(u'removed', rev_id='i18n-4')
851
838
bundle = self.get_valid_bundle('i18n-3', 'i18n-4')
1583
1570
record = record_iter.next()
1584
1571
self.assertEqual((None, {'foo': 'bar', 'storage_kind': 'header'},
1585
1572
'info', None, None), record)
1586
self.assertRaises(BadBundle, record_iter.next)
1573
self.assertRaises(errors.BadBundle, record_iter.next)
1589
1576
class TestReadMergeableFromUrl(TestCaseWithTransport):
1602
1589
self.build_tree_contents([('./foo:bar', out.getvalue())])
1603
1590
self.assertRaises(errors.NotABundle, read_mergeable_from_url,
1593
def test_smart_server_connection_reset(self):
1594
"""If a smart server connection fails during the attempt to read a
1595
bundle, then the ConnectionReset error should be propagated.
1597
# Instantiate a server that will provoke a ConnectionReset
1598
sock_server = _DisconnectingTCPServer()
1600
self.addCleanup(sock_server.tearDown)
1601
url = sock_server.get_url()
1602
self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
1605
class _DisconnectingTCPServer(object):
1606
"""A TCP server that immediately closes any connection made to it."""
1609
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1610
self.sock.bind(('127.0.0.1', 0))
1612
self.port = self.sock.getsockname()[1]
1613
self.thread = threading.Thread(
1614
name='%s (port %d)' % (self.__class__.__name__, self.port),
1615
target=self.accept_and_close)
1618
def accept_and_close(self):
1619
conn, addr = self.sock.accept()
1620
conn.shutdown(socket.SHUT_RDWR)
1624
return 'bzr://127.0.0.1:%d/' % (self.port,)
1628
# make sure the thread dies by connecting to the listening socket,
1629
# just in case the test failed to do so.
1630
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1631
conn.connect(self.sock.getsockname())
1633
except socket.error: