|
@@ -54,20 +54,18 @@ from dulwich.server import (
|
|
|
from dulwich.tests import TestCase
|
|
|
from dulwich.tests.utils import (
|
|
|
make_commit,
|
|
|
- make_object,
|
|
|
make_tag,
|
|
|
- skipIfPY3,
|
|
|
)
|
|
|
from dulwich.protocol import (
|
|
|
ZERO_SHA,
|
|
|
)
|
|
|
|
|
|
-ONE = '1' * 40
|
|
|
-TWO = '2' * 40
|
|
|
-THREE = '3' * 40
|
|
|
-FOUR = '4' * 40
|
|
|
-FIVE = '5' * 40
|
|
|
-SIX = '6' * 40
|
|
|
+ONE = b'1' * 40
|
|
|
+TWO = b'2' * 40
|
|
|
+THREE = b'3' * 40
|
|
|
+FOUR = b'4' * 40
|
|
|
+FIVE = b'5' * 40
|
|
|
+SIX = b'6' * 40
|
|
|
|
|
|
|
|
|
class TestProto(object):
|
|
@@ -83,7 +81,7 @@ class TestProto(object):
|
|
|
if self._output:
|
|
|
data = self._output.pop(0)
|
|
|
if data is not None:
|
|
|
- return '%s\n' % data.rstrip()
|
|
|
+ return data.rstrip() + b'\n'
|
|
|
else:
|
|
|
|
|
|
return None
|
|
@@ -108,11 +106,11 @@ class TestGenericHandler(Handler):
|
|
|
|
|
|
@classmethod
|
|
|
def capabilities(cls):
|
|
|
- return ('cap1', 'cap2', 'cap3')
|
|
|
+ return (b'cap1', b'cap2', b'cap3')
|
|
|
|
|
|
@classmethod
|
|
|
def required_capabilities(cls):
|
|
|
- return ('cap2',)
|
|
|
+ return (b'cap2',)
|
|
|
|
|
|
|
|
|
class HandlerTestCase(TestCase):
|
|
@@ -128,81 +126,80 @@ class HandlerTestCase(TestCase):
|
|
|
self.fail(e)
|
|
|
|
|
|
def test_capability_line(self):
|
|
|
- self.assertEqual('cap1 cap2 cap3', self._handler.capability_line())
|
|
|
+ self.assertEqual(b'cap1 cap2 cap3', self._handler.capability_line())
|
|
|
|
|
|
def test_set_client_capabilities(self):
|
|
|
set_caps = self._handler.set_client_capabilities
|
|
|
- self.assertSucceeds(set_caps, ['cap2'])
|
|
|
- self.assertSucceeds(set_caps, ['cap1', 'cap2'])
|
|
|
+ self.assertSucceeds(set_caps, [b'cap2'])
|
|
|
+ self.assertSucceeds(set_caps, [b'cap1', b'cap2'])
|
|
|
|
|
|
|
|
|
- self.assertSucceeds(set_caps, ['cap3', 'cap1', 'cap2'])
|
|
|
+ self.assertSucceeds(set_caps, [b'cap3', b'cap1', b'cap2'])
|
|
|
|
|
|
|
|
|
- self.assertRaises(GitProtocolError, set_caps, ['capxxx', 'cap2'])
|
|
|
- self.assertRaises(GitProtocolError, set_caps, ['cap1', 'cap3'])
|
|
|
+ self.assertRaises(GitProtocolError, set_caps, [b'capxxx', b'cap2'])
|
|
|
+ self.assertRaises(GitProtocolError, set_caps, [b'cap1', b'cap3'])
|
|
|
|
|
|
|
|
|
- self.assertRaises(GitProtocolError, set_caps, ['cap2', 'ignoreme'])
|
|
|
- self.assertFalse('ignoreme' in self._handler.capabilities())
|
|
|
- self._handler.innocuous_capabilities = lambda: ('ignoreme',)
|
|
|
- self.assertSucceeds(set_caps, ['cap2', 'ignoreme'])
|
|
|
+ self.assertRaises(GitProtocolError, set_caps, [b'cap2', b'ignoreme'])
|
|
|
+ self.assertFalse(b'ignoreme' in self._handler.capabilities())
|
|
|
+ self._handler.innocuous_capabilities = lambda: (b'ignoreme',)
|
|
|
+ self.assertSucceeds(set_caps, [b'cap2', b'ignoreme'])
|
|
|
|
|
|
def test_has_capability(self):
|
|
|
- self.assertRaises(GitProtocolError, self._handler.has_capability, 'cap')
|
|
|
+ self.assertRaises(GitProtocolError, self._handler.has_capability, b'cap')
|
|
|
caps = self._handler.capabilities()
|
|
|
self._handler.set_client_capabilities(caps)
|
|
|
for cap in caps:
|
|
|
self.assertTrue(self._handler.has_capability(cap))
|
|
|
- self.assertFalse(self._handler.has_capability('capxxx'))
|
|
|
+ self.assertFalse(self._handler.has_capability(b'capxxx'))
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class UploadPackHandlerTestCase(TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
|
super(UploadPackHandlerTestCase, self).setUp()
|
|
|
self._repo = MemoryRepo.init_bare([], {})
|
|
|
- backend = DictBackend({'/': self._repo})
|
|
|
+ backend = DictBackend({b'/': self._repo})
|
|
|
self._handler = UploadPackHandler(
|
|
|
- backend, ['/', 'host=lolcathost'], TestProto())
|
|
|
+ backend, [b'/', b'host=lolcathost'], TestProto())
|
|
|
|
|
|
def test_progress(self):
|
|
|
caps = self._handler.required_capabilities()
|
|
|
self._handler.set_client_capabilities(caps)
|
|
|
- self._handler.progress('first message')
|
|
|
- self._handler.progress('second message')
|
|
|
- self.assertEqual('first message',
|
|
|
+ self._handler.progress(b'first message')
|
|
|
+ self._handler.progress(b'second message')
|
|
|
+ self.assertEqual(b'first message',
|
|
|
self._handler.proto.get_received_line(2))
|
|
|
- self.assertEqual('second message',
|
|
|
+ self.assertEqual(b'second message',
|
|
|
self._handler.proto.get_received_line(2))
|
|
|
self.assertRaises(IndexError, self._handler.proto.get_received_line, 2)
|
|
|
|
|
|
def test_no_progress(self):
|
|
|
- caps = list(self._handler.required_capabilities()) + ['no-progress']
|
|
|
+ caps = list(self._handler.required_capabilities()) + [b'no-progress']
|
|
|
self._handler.set_client_capabilities(caps)
|
|
|
- self._handler.progress('first message')
|
|
|
- self._handler.progress('second message')
|
|
|
+ self._handler.progress(b'first message')
|
|
|
+ self._handler.progress(b'second message')
|
|
|
self.assertRaises(IndexError, self._handler.proto.get_received_line, 2)
|
|
|
|
|
|
def test_get_tagged(self):
|
|
|
refs = {
|
|
|
- 'refs/tags/tag1': ONE,
|
|
|
- 'refs/tags/tag2': TWO,
|
|
|
- 'refs/heads/master': FOUR,
|
|
|
+ b'refs/tags/tag1': ONE,
|
|
|
+ b'refs/tags/tag2': TWO,
|
|
|
+ b'refs/heads/master': FOUR,
|
|
|
}
|
|
|
|
|
|
self._repo.object_store.add_object(make_commit(id=FOUR))
|
|
|
self._repo.refs._update(refs)
|
|
|
peeled = {
|
|
|
- 'refs/tags/tag1': '1234' * 10,
|
|
|
- 'refs/tags/tag2': '5678' * 10,
|
|
|
+ b'refs/tags/tag1': b'1234' * 10,
|
|
|
+ b'refs/tags/tag2': b'5678' * 10,
|
|
|
}
|
|
|
self._repo.refs._update_peeled(peeled)
|
|
|
|
|
|
- caps = list(self._handler.required_capabilities()) + ['include-tag']
|
|
|
+ caps = list(self._handler.required_capabilities()) + [b'include-tag']
|
|
|
self._handler.set_client_capabilities(caps)
|
|
|
- self.assertEqual({'1234' * 10: ONE, '5678' * 10: TWO},
|
|
|
+ self.assertEqual({b'1234' * 10: ONE, b'5678' * 10: TWO},
|
|
|
self._handler.get_tagged(refs, repo=self._repo))
|
|
|
|
|
|
|
|
@@ -211,7 +208,6 @@ class UploadPackHandlerTestCase(TestCase):
|
|
|
self.assertEqual({}, self._handler.get_tagged(refs, repo=self._repo))
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class FindShallowTests(TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
@@ -222,7 +218,7 @@ class FindShallowTests(TestCase):
|
|
|
self._store.add_object(commit)
|
|
|
return commit
|
|
|
|
|
|
- def make_linear_commits(self, n, message=''):
|
|
|
+ def make_linear_commits(self, n, message=b''):
|
|
|
commits = []
|
|
|
parents = []
|
|
|
for _ in range(n):
|
|
@@ -246,9 +242,9 @@ class FindShallowTests(TestCase):
|
|
|
_find_shallow(self._store, [c3.id], 3))
|
|
|
|
|
|
def test_multiple_independent(self):
|
|
|
- a = self.make_linear_commits(2, message='a')
|
|
|
- b = self.make_linear_commits(2, message='b')
|
|
|
- c = self.make_linear_commits(2, message='c')
|
|
|
+ a = self.make_linear_commits(2, message=b'a')
|
|
|
+ b = self.make_linear_commits(2, message=b'b')
|
|
|
+ c = self.make_linear_commits(2, message=b'c')
|
|
|
heads = [a[1].id, b[1].id, c[1].id]
|
|
|
|
|
|
self.assertEqual((set([a[0].id, b[0].id, c[0].id]), set(heads)),
|
|
@@ -277,7 +273,7 @@ class FindShallowTests(TestCase):
|
|
|
|
|
|
def test_tag(self):
|
|
|
c1, c2 = self.make_linear_commits(2)
|
|
|
- tag = make_tag(c2, name='tag')
|
|
|
+ tag = make_tag(c2, name=b'tag')
|
|
|
self._store.add_object(tag)
|
|
|
|
|
|
self.assertEqual((set([c1.id]), set([c2.id])),
|
|
@@ -289,37 +285,35 @@ class TestUploadPackHandler(UploadPackHandler):
|
|
|
def required_capabilities(self):
|
|
|
return ()
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class ReceivePackHandlerTestCase(TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
|
super(ReceivePackHandlerTestCase, self).setUp()
|
|
|
self._repo = MemoryRepo.init_bare([], {})
|
|
|
- backend = DictBackend({'/': self._repo})
|
|
|
+ backend = DictBackend({b'/': self._repo})
|
|
|
self._handler = ReceivePackHandler(
|
|
|
- backend, ['/', 'host=lolcathost'], TestProto())
|
|
|
+ backend, [b'/', b'host=lolcathost'], TestProto())
|
|
|
|
|
|
def test_apply_pack_del_ref(self):
|
|
|
refs = {
|
|
|
- 'refs/heads/master': TWO,
|
|
|
- 'refs/heads/fake-branch': ONE}
|
|
|
+ b'refs/heads/master': TWO,
|
|
|
+ b'refs/heads/fake-branch': ONE}
|
|
|
self._repo.refs._update(refs)
|
|
|
- update_refs = [[ONE, ZERO_SHA, 'refs/heads/fake-branch'], ]
|
|
|
+ update_refs = [[ONE, ZERO_SHA, b'refs/heads/fake-branch'], ]
|
|
|
status = self._handler._apply_pack(update_refs)
|
|
|
- self.assertEqual(status[0][0], 'unpack')
|
|
|
- self.assertEqual(status[0][1], 'ok')
|
|
|
- self.assertEqual(status[1][0], 'refs/heads/fake-branch')
|
|
|
- self.assertEqual(status[1][1], 'ok')
|
|
|
+ self.assertEqual(status[0][0], b'unpack')
|
|
|
+ self.assertEqual(status[0][1], b'ok')
|
|
|
+ self.assertEqual(status[1][0], b'refs/heads/fake-branch')
|
|
|
+ self.assertEqual(status[1][1], b'ok')
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class ProtocolGraphWalkerEmptyTestCase(TestCase):
|
|
|
def setUp(self):
|
|
|
super(ProtocolGraphWalkerEmptyTestCase, self).setUp()
|
|
|
self._repo = MemoryRepo.init_bare([], {})
|
|
|
- backend = DictBackend({'/': self._repo})
|
|
|
+ backend = DictBackend({b'/': self._repo})
|
|
|
self._walker = ProtocolGraphWalker(
|
|
|
- TestUploadPackHandler(backend, ['/', 'host=lolcats'], TestProto()),
|
|
|
+ TestUploadPackHandler(backend, [b'/', b'host=lolcats'], TestProto()),
|
|
|
self._repo.object_store, self._repo.get_peeled)
|
|
|
|
|
|
def test_empty_repository(self):
|
|
@@ -334,7 +328,6 @@ class ProtocolGraphWalkerEmptyTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
|
|
|
def setUp(self):
|
|
@@ -351,9 +344,9 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
make_commit(id=FIVE, parents=[THREE], commit_time=555),
|
|
|
]
|
|
|
self._repo = MemoryRepo.init_bare(commits, {})
|
|
|
- backend = DictBackend({'/': self._repo})
|
|
|
+ backend = DictBackend({b'/': self._repo})
|
|
|
self._walker = ProtocolGraphWalker(
|
|
|
- TestUploadPackHandler(backend, ['/', 'host=lolcats'], TestProto()),
|
|
|
+ TestUploadPackHandler(backend, [b'/', b'host=lolcats'], TestProto()),
|
|
|
self._repo.object_store, self._repo.get_peeled)
|
|
|
|
|
|
def test_all_wants_satisfied_no_haves(self):
|
|
@@ -390,20 +383,20 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
self.assertTrue(self._walker.all_wants_satisfied([TWO, THREE]))
|
|
|
|
|
|
def test_split_proto_line(self):
|
|
|
- allowed = ('want', 'done', None)
|
|
|
- self.assertEqual(('want', ONE),
|
|
|
- _split_proto_line('want %s\n' % ONE, allowed))
|
|
|
- self.assertEqual(('want', TWO),
|
|
|
- _split_proto_line('want %s\n' % TWO, allowed))
|
|
|
+ allowed = (b'want', b'done', None)
|
|
|
+ self.assertEqual((b'want', ONE),
|
|
|
+ _split_proto_line(b'want ' + ONE + b'\n', allowed))
|
|
|
+ self.assertEqual((b'want', TWO),
|
|
|
+ _split_proto_line(b'want ' + TWO + b'\n', allowed))
|
|
|
self.assertRaises(GitProtocolError, _split_proto_line,
|
|
|
- 'want xxxx\n', allowed)
|
|
|
+ b'want xxxx\n', allowed)
|
|
|
self.assertRaises(UnexpectedCommandError, _split_proto_line,
|
|
|
- 'have %s\n' % THREE, allowed)
|
|
|
+ b'have ' + THREE + b'\n', allowed)
|
|
|
self.assertRaises(GitProtocolError, _split_proto_line,
|
|
|
- 'foo %s\n' % FOUR, allowed)
|
|
|
- self.assertRaises(GitProtocolError, _split_proto_line, 'bar', allowed)
|
|
|
- self.assertEqual(('done', None), _split_proto_line('done\n', allowed))
|
|
|
- self.assertEqual((None, None), _split_proto_line('', allowed))
|
|
|
+ b'foo ' + FOUR + b'\n', allowed)
|
|
|
+ self.assertRaises(GitProtocolError, _split_proto_line, b'bar', allowed)
|
|
|
+ self.assertEqual((b'done', None), _split_proto_line(b'done\n', allowed))
|
|
|
+ self.assertEqual((None, None), _split_proto_line(b'', allowed))
|
|
|
|
|
|
def test_determine_wants(self):
|
|
|
self._walker.proto.set_output([None])
|
|
@@ -411,14 +404,14 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
self.assertEqual(None, self._walker.proto.get_received_line())
|
|
|
|
|
|
self._walker.proto.set_output([
|
|
|
- 'want %s multi_ack' % ONE,
|
|
|
- 'want %s' % TWO,
|
|
|
+ b'want ' + ONE + b' multi_ack',
|
|
|
+ b'want ' + TWO,
|
|
|
None,
|
|
|
])
|
|
|
heads = {
|
|
|
- 'refs/heads/ref1': ONE,
|
|
|
- 'refs/heads/ref2': TWO,
|
|
|
- 'refs/heads/ref3': THREE,
|
|
|
+ b'refs/heads/ref1': ONE,
|
|
|
+ b'refs/heads/ref2': TWO,
|
|
|
+ b'refs/heads/ref3': THREE,
|
|
|
}
|
|
|
self._repo.refs._update(heads)
|
|
|
self.assertEqual([ONE, TWO], self._walker.determine_wants(heads))
|
|
@@ -427,29 +420,29 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
self.assertEqual([], self._walker.determine_wants(heads))
|
|
|
self._walker.advertise_refs = False
|
|
|
|
|
|
- self._walker.proto.set_output(['want %s multi_ack' % FOUR, None])
|
|
|
+ self._walker.proto.set_output([b'want ' + FOUR + b' multi_ack', None])
|
|
|
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
|
|
|
|
|
|
self._walker.proto.set_output([None])
|
|
|
self.assertEqual([], self._walker.determine_wants(heads))
|
|
|
|
|
|
- self._walker.proto.set_output(['want %s multi_ack' % ONE, 'foo', None])
|
|
|
+ self._walker.proto.set_output([b'want ' + ONE + b' multi_ack', b'foo', None])
|
|
|
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
|
|
|
|
|
|
- self._walker.proto.set_output(['want %s multi_ack' % FOUR, None])
|
|
|
+ self._walker.proto.set_output([b'want ' + FOUR + b' multi_ack', None])
|
|
|
self.assertRaises(GitProtocolError, self._walker.determine_wants, heads)
|
|
|
|
|
|
def test_determine_wants_advertisement(self):
|
|
|
self._walker.proto.set_output([None])
|
|
|
|
|
|
heads = {
|
|
|
- 'refs/heads/ref4': FOUR,
|
|
|
- 'refs/heads/ref5': FIVE,
|
|
|
- 'refs/heads/tag6': SIX,
|
|
|
+ b'refs/heads/ref4': FOUR,
|
|
|
+ b'refs/heads/ref5': FIVE,
|
|
|
+ b'refs/heads/tag6': SIX,
|
|
|
}
|
|
|
self._repo.refs._update(heads)
|
|
|
self._repo.refs._update_peeled(heads)
|
|
|
- self._repo.refs._update_peeled({'refs/heads/tag6': FIVE})
|
|
|
+ self._repo.refs._update_peeled({b'refs/heads/tag6': FIVE})
|
|
|
self._walker.determine_wants(heads)
|
|
|
lines = []
|
|
|
while True:
|
|
@@ -457,21 +450,21 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
if line is None:
|
|
|
break
|
|
|
|
|
|
- if '\x00' in line:
|
|
|
- line = line[:line.index('\x00')]
|
|
|
+ if b'\x00' in line:
|
|
|
+ line = line[:line.index(b'\x00')]
|
|
|
lines.append(line.rstrip())
|
|
|
|
|
|
self.assertEqual([
|
|
|
- '%s refs/heads/ref4' % FOUR,
|
|
|
- '%s refs/heads/ref5' % FIVE,
|
|
|
- '%s refs/heads/tag6^{}' % FIVE,
|
|
|
- '%s refs/heads/tag6' % SIX,
|
|
|
+ FOUR + b' refs/heads/ref4',
|
|
|
+ FIVE + b' refs/heads/ref5',
|
|
|
+ FIVE + b' refs/heads/tag6^{}',
|
|
|
+ SIX + b' refs/heads/tag6',
|
|
|
], sorted(lines))
|
|
|
|
|
|
|
|
|
for i, line in enumerate(lines):
|
|
|
- if line.endswith(' refs/heads/tag6'):
|
|
|
- self.assertEqual('%s refs/heads/tag6^{}' % FIVE, lines[i+1])
|
|
|
+ if line.endswith(b' refs/heads/tag6'):
|
|
|
+ self.assertEqual(FIVE + b' refs/heads/tag6^{}', lines[i+1])
|
|
|
|
|
|
|
|
|
|
|
@@ -484,18 +477,18 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
expected, list(iter(self._walker.proto.get_received_line, None)))
|
|
|
|
|
|
def test_handle_shallow_request_no_client_shallows(self):
|
|
|
- self._handle_shallow_request(['deepen 1\n'], [FOUR, FIVE])
|
|
|
+ self._handle_shallow_request([b'deepen 1\n'], [FOUR, FIVE])
|
|
|
self.assertEqual(set([TWO, THREE]), self._walker.shallow)
|
|
|
self.assertReceived([
|
|
|
- 'shallow %s' % TWO,
|
|
|
- 'shallow %s' % THREE,
|
|
|
+ b'shallow ' + TWO,
|
|
|
+ b'shallow ' + THREE,
|
|
|
])
|
|
|
|
|
|
def test_handle_shallow_request_no_new_shallows(self):
|
|
|
lines = [
|
|
|
- 'shallow %s\n' % TWO,
|
|
|
- 'shallow %s\n' % THREE,
|
|
|
- 'deepen 1\n',
|
|
|
+ b'shallow ' + TWO + b'\n',
|
|
|
+ b'shallow ' + THREE + b'\n',
|
|
|
+ b'deepen 1\n',
|
|
|
]
|
|
|
self._handle_shallow_request(lines, [FOUR, FIVE])
|
|
|
self.assertEqual(set([TWO, THREE]), self._walker.shallow)
|
|
@@ -503,19 +496,18 @@ class ProtocolGraphWalkerTestCase(TestCase):
|
|
|
|
|
|
def test_handle_shallow_request_unshallows(self):
|
|
|
lines = [
|
|
|
- 'shallow %s\n' % TWO,
|
|
|
- 'deepen 2\n',
|
|
|
+ b'shallow ' + TWO + b'\n',
|
|
|
+ b'deepen 2\n',
|
|
|
]
|
|
|
self._handle_shallow_request(lines, [FOUR, FIVE])
|
|
|
self.assertEqual(set([ONE]), self._walker.shallow)
|
|
|
self.assertReceived([
|
|
|
- 'shallow %s' % ONE,
|
|
|
- 'unshallow %s' % TWO,
|
|
|
+ b'shallow ' + ONE,
|
|
|
+ b'unshallow ' + TWO,
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class TestProtocolGraphWalker(object):
|
|
|
|
|
|
def __init__(self):
|
|
@@ -531,11 +523,11 @@ class TestProtocolGraphWalker(object):
|
|
|
assert command in allowed
|
|
|
return command, sha
|
|
|
|
|
|
- def send_ack(self, sha, ack_type=''):
|
|
|
+ def send_ack(self, sha, ack_type=b''):
|
|
|
self.acks.append((sha, ack_type))
|
|
|
|
|
|
def send_nak(self):
|
|
|
- self.acks.append((None, 'nak'))
|
|
|
+ self.acks.append((None, b'nak'))
|
|
|
|
|
|
def all_wants_satisfied(self, haves):
|
|
|
return self.done
|
|
@@ -546,7 +538,6 @@ class TestProtocolGraphWalker(object):
|
|
|
return self.acks.pop(0)
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class AckGraphWalkerImplTestCase(TestCase):
|
|
|
"""Base setup and asserts for AckGraphWalker tests."""
|
|
|
|
|
@@ -554,10 +545,10 @@ class AckGraphWalkerImplTestCase(TestCase):
|
|
|
super(AckGraphWalkerImplTestCase, self).setUp()
|
|
|
self._walker = TestProtocolGraphWalker()
|
|
|
self._walker.lines = [
|
|
|
- ('have', TWO),
|
|
|
- ('have', ONE),
|
|
|
- ('have', THREE),
|
|
|
- ('done', None),
|
|
|
+ (b'have', TWO),
|
|
|
+ (b'have', ONE),
|
|
|
+ (b'have', THREE),
|
|
|
+ (b'done', None),
|
|
|
]
|
|
|
self._impl = self.impl_cls(self._walker)
|
|
|
|
|
@@ -569,17 +560,16 @@ class AckGraphWalkerImplTestCase(TestCase):
|
|
|
self.assertEqual((sha, ack_type), self._walker.pop_ack())
|
|
|
self.assertNoAck()
|
|
|
|
|
|
- def assertAck(self, sha, ack_type=''):
|
|
|
+ def assertAck(self, sha, ack_type=b''):
|
|
|
self.assertAcks([(sha, ack_type)])
|
|
|
|
|
|
def assertNak(self):
|
|
|
- self.assertAck(None, 'nak')
|
|
|
+ self.assertAck(None, b'nak')
|
|
|
|
|
|
def assertNextEquals(self, sha):
|
|
|
self.assertEqual(sha, next(self._impl))
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class SingleAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
impl_cls = SingleAckGraphWalkerImpl
|
|
@@ -648,7 +638,6 @@ class SingleAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
self.assertNak()
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
impl_cls = MultiAckGraphWalkerImpl
|
|
@@ -660,11 +649,11 @@ class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
self.assertNextEquals(ONE)
|
|
|
self._walker.done = True
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAck(ONE, 'continue')
|
|
|
+ self.assertAck(ONE, b'continue')
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self._impl.ack(THREE)
|
|
|
- self.assertAck(THREE, 'continue')
|
|
|
+ self.assertAck(THREE, b'continue')
|
|
|
|
|
|
self.assertNextEquals(None)
|
|
|
self.assertAck(THREE)
|
|
@@ -675,7 +664,7 @@ class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
self.assertNextEquals(ONE)
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAck(ONE, 'continue')
|
|
|
+ self.assertAck(ONE, b'continue')
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self.assertNoAck()
|
|
@@ -686,11 +675,11 @@ class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
def test_multi_ack_flush(self):
|
|
|
self._walker.lines = [
|
|
|
- ('have', TWO),
|
|
|
+ (b'have', TWO),
|
|
|
(None, None),
|
|
|
- ('have', ONE),
|
|
|
- ('have', THREE),
|
|
|
- ('done', None),
|
|
|
+ (b'have', ONE),
|
|
|
+ (b'have', THREE),
|
|
|
+ (b'done', None),
|
|
|
]
|
|
|
self.assertNextEquals(TWO)
|
|
|
self.assertNoAck()
|
|
@@ -700,11 +689,11 @@ class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
self._walker.done = True
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAck(ONE, 'continue')
|
|
|
+ self.assertAck(ONE, b'continue')
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self._impl.ack(THREE)
|
|
|
- self.assertAck(THREE, 'continue')
|
|
|
+ self.assertAck(THREE, b'continue')
|
|
|
|
|
|
self.assertNextEquals(None)
|
|
|
self.assertAck(THREE)
|
|
@@ -723,7 +712,6 @@ class MultiAckGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
self.assertNak()
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
impl_cls = MultiAckDetailedGraphWalkerImpl
|
|
@@ -735,11 +723,11 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
self.assertNextEquals(ONE)
|
|
|
self._walker.done = True
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAcks([(ONE, 'common'), (ONE, 'ready')])
|
|
|
+ self.assertAcks([(ONE, b'common'), (ONE, b'ready')])
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self._impl.ack(THREE)
|
|
|
- self.assertAck(THREE, 'ready')
|
|
|
+ self.assertAck(THREE, b'ready')
|
|
|
|
|
|
self.assertNextEquals(None)
|
|
|
self.assertAck(THREE)
|
|
@@ -750,7 +738,7 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
self.assertNextEquals(ONE)
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAck(ONE, 'common')
|
|
|
+ self.assertAck(ONE, b'common')
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self.assertNoAck()
|
|
@@ -762,11 +750,11 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
def test_multi_ack_flush(self):
|
|
|
|
|
|
self._walker.lines = [
|
|
|
- ('have', TWO),
|
|
|
+ (b'have', TWO),
|
|
|
(None, None),
|
|
|
- ('have', ONE),
|
|
|
- ('have', THREE),
|
|
|
- ('done', None),
|
|
|
+ (b'have', ONE),
|
|
|
+ (b'have', THREE),
|
|
|
+ (b'done', None),
|
|
|
]
|
|
|
self.assertNextEquals(TWO)
|
|
|
self.assertNoAck()
|
|
@@ -776,11 +764,11 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
|
|
|
self._walker.done = True
|
|
|
self._impl.ack(ONE)
|
|
|
- self.assertAcks([(ONE, 'common'), (ONE, 'ready')])
|
|
|
+ self.assertAcks([(ONE, b'common'), (ONE, b'ready')])
|
|
|
|
|
|
self.assertNextEquals(THREE)
|
|
|
self._impl.ack(THREE)
|
|
|
- self.assertAck(THREE, 'ready')
|
|
|
+ self.assertAck(THREE, b'ready')
|
|
|
|
|
|
self.assertNextEquals(None)
|
|
|
self.assertAck(THREE)
|
|
@@ -801,11 +789,11 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
def test_multi_ack_nak_flush(self):
|
|
|
|
|
|
self._walker.lines = [
|
|
|
- ('have', TWO),
|
|
|
+ (b'have', TWO),
|
|
|
(None, None),
|
|
|
- ('have', ONE),
|
|
|
- ('have', THREE),
|
|
|
- ('done', None),
|
|
|
+ (b'have', ONE),
|
|
|
+ (b'have', THREE),
|
|
|
+ (b'done', None),
|
|
|
]
|
|
|
self.assertNextEquals(TWO)
|
|
|
self.assertNoAck()
|
|
@@ -837,7 +825,6 @@ class MultiAckDetailedGraphWalkerImplTestCase(AckGraphWalkerImplTestCase):
|
|
|
self.assertNak()
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class FileSystemBackendTests(TestCase):
|
|
|
"""Tests for FileSystemBackend."""
|
|
|
|
|
@@ -866,25 +853,23 @@ class FileSystemBackendTests(TestCase):
|
|
|
lambda: backend.open_repository('/ups'))
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class DictBackendTests(TestCase):
|
|
|
"""Tests for DictBackend."""
|
|
|
|
|
|
def test_nonexistant(self):
|
|
|
repo = MemoryRepo.init_bare([], {})
|
|
|
- backend = DictBackend({'/': repo})
|
|
|
+ backend = DictBackend({b'/': repo})
|
|
|
self.assertRaises(NotGitRepository,
|
|
|
backend.open_repository, "/does/not/exist/unless/foo")
|
|
|
|
|
|
def test_bad_repo_path(self):
|
|
|
repo = MemoryRepo.init_bare([], {})
|
|
|
- backend = DictBackend({'/': repo})
|
|
|
+ backend = DictBackend({b'/': repo})
|
|
|
|
|
|
self.assertRaises(NotGitRepository,
|
|
|
lambda: backend.open_repository('/ups'))
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class ServeCommandTests(TestCase):
|
|
|
"""Tests for serve_command."""
|
|
|
|
|
@@ -893,24 +878,23 @@ class ServeCommandTests(TestCase):
|
|
|
self.backend = DictBackend({})
|
|
|
|
|
|
def serve_command(self, handler_cls, args, inf, outf):
|
|
|
- return serve_command(handler_cls, ["test"] + args, backend=self.backend,
|
|
|
+ return serve_command(handler_cls, [b"test"] + args, backend=self.backend,
|
|
|
inf=inf, outf=outf)
|
|
|
|
|
|
def test_receive_pack(self):
|
|
|
commit = make_commit(id=ONE, parents=[], commit_time=111)
|
|
|
- self.backend.repos["/"] = MemoryRepo.init_bare(
|
|
|
- [commit], {"refs/heads/master": commit.id})
|
|
|
+ self.backend.repos[b"/"] = MemoryRepo.init_bare(
|
|
|
+ [commit], {b"refs/heads/master": commit.id})
|
|
|
outf = BytesIO()
|
|
|
- exitcode = self.serve_command(ReceivePackHandler, ["/"], BytesIO("0000"), outf)
|
|
|
+ exitcode = self.serve_command(ReceivePackHandler, [b"/"], BytesIO(b"0000"), outf)
|
|
|
outlines = outf.getvalue().splitlines()
|
|
|
self.assertEqual(2, len(outlines))
|
|
|
- self.assertEqual("1111111111111111111111111111111111111111 refs/heads/master",
|
|
|
- outlines[0][4:].split("\x00")[0])
|
|
|
- self.assertEqual("0000", outlines[-1])
|
|
|
+ self.assertEqual(b"1111111111111111111111111111111111111111 refs/heads/master",
|
|
|
+ outlines[0][4:].split(b"\x00")[0])
|
|
|
+ self.assertEqual(b"0000", outlines[-1])
|
|
|
self.assertEqual(0, exitcode)
|
|
|
|
|
|
|
|
|
-@skipIfPY3
|
|
|
class UpdateServerInfoTests(TestCase):
|
|
|
"""Tests for update_server_info."""
|
|
|
|
|
@@ -928,9 +912,9 @@ class UpdateServerInfoTests(TestCase):
|
|
|
|
|
|
def test_simple(self):
|
|
|
commit_id = self.repo.do_commit(
|
|
|
- message="foo",
|
|
|
- committer="Joe Example <joe@example.com>",
|
|
|
- ref="refs/heads/foo")
|
|
|
+ message=b"foo",
|
|
|
+ committer=b"Joe Example <joe@example.com>",
|
|
|
+ ref=b"refs/heads/foo")
|
|
|
update_server_info(self.repo)
|
|
|
with open(os.path.join(self.path, ".git", "info", "refs"), 'rb') as f:
|
|
|
self.assertEqual(f.read(), commit_id + b'\trefs/heads/foo\n')
|