bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
7476.2.1
by Jelmer Vernooij
Default to running Python 3. |
1 |
#!/usr/bin/env python3
|
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
2 |
# vim: expandtab
|
3 |
||
0.358.2
by Jelmer Vernooij
Refresh copyright headers, add my email. |
4 |
# Copyright (C) 2011-2018 Jelmer Vernooij <jelmer@jelmer.uk>
|
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
5 |
|
6 |
# This program is free software; you can redistribute it and/or modify
|
|
7 |
# it under the terms of the GNU General Public License as published by
|
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
|
9 |
# (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
0.358.1
by Jelmer Vernooij
Fix FSF address. |
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
19 |
|
0.358.3
by Jelmer Vernooij
Enable absolute import. |
20 |
"""Tests for the git remote helper."""
|
21 |
||
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
22 |
from io import BytesIO |
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
23 |
import os |
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
24 |
import subprocess |
7290.11.6
by Jelmer Vernooij
Use the same python executable as for brz. |
25 |
import sys |
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
26 |
|
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
27 |
from dulwich.repo import Repo |
28 |
||
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
29 |
from ...tests import ( |
0.200.1582
by Jelmer Vernooij
Print error when bzr-fastimport is not installed. |
30 |
TestCaseWithTransport, |
31 |
)
|
|
7290.11.4
by Jelmer Vernooij
Check whether git-remote-bzr actually exists. |
32 |
from ...tests.features import PathFeature |
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
33 |
|
0.200.1642
by Jelmer Vernooij
Use relative imports in tests. |
34 |
from ..object_store import get_object_store |
35 |
from ..git_remote_helper import ( |
|
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
36 |
RemoteHelper, |
37 |
open_local_dir, |
|
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
38 |
fetch, |
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
39 |
)
|
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
40 |
|
7045.4.17
by Jelmer Vernooij
Fix tests. |
41 |
from . import FastimportFeature |
42 |
||
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
43 |
|
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
44 |
def map_to_git_sha1(dir, bzr_revid): |
45 |
object_store = get_object_store(dir.open_repository()) |
|
0.200.1788
by Jelmer Vernooij
Use context managers. |
46 |
with object_store.lock_read(): |
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
47 |
return object_store._lookup_revision_sha1(bzr_revid) |
48 |
||
49 |
||
7290.11.4
by Jelmer Vernooij
Check whether git-remote-bzr actually exists. |
50 |
git_remote_bzr_path = os.path.abspath( |
51 |
os.path.join(os.path.dirname(__file__), '..', 'git-remote-bzr')) |
|
52 |
git_remote_bzr_feature = PathFeature(git_remote_bzr_path) |
|
53 |
||
54 |
||
0.200.1515
by Jelmer Vernooij
Add tests for git_remote_helper. |
55 |
class OpenLocalDirTests(TestCaseWithTransport): |
56 |
||
57 |
def test_from_env_dir(self): |
|
58 |
self.make_branch_and_tree('bla', format='git') |
|
59 |
self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git')) |
|
60 |
open_local_dir() |
|
61 |
||
62 |
def test_from_dir(self): |
|
63 |
self.make_branch_and_tree('.', format='git') |
|
64 |
open_local_dir() |
|
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
65 |
|
66 |
||
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
67 |
class FetchTests(TestCaseWithTransport): |
68 |
||
69 |
def setUp(self): |
|
70 |
super(FetchTests, self).setUp() |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
71 |
self.local_dir = self.make_branch_and_tree( |
72 |
'local', format='git').controldir |
|
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
73 |
self.remote_tree = self.make_branch_and_tree('remote') |
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
74 |
self.remote_dir = self.remote_tree.controldir |
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
75 |
self.shortname = 'bzr' |
76 |
||
77 |
def fetch(self, wants): |
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
78 |
outf = BytesIO() |
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
79 |
fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir) |
80 |
return outf.getvalue() |
|
81 |
||
82 |
def test_no_wants(self): |
|
83 |
r = self.fetch([]) |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
84 |
self.assertEqual(b"\n", r) |
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
85 |
|
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
86 |
def test_simple(self): |
87 |
self.build_tree(['remote/foo']) |
|
88 |
self.remote_tree.add("foo") |
|
89 |
revid = self.remote_tree.commit("msg") |
|
90 |
git_sha1 = map_to_git_sha1(self.remote_dir, revid) |
|
91 |
out = self.fetch([(git_sha1, 'HEAD')]) |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
92 |
self.assertEqual(out, b"\n") |
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
93 |
r = Repo('local') |
94 |
self.assertTrue(git_sha1 in r.object_store) |
|
7290.11.5
by Jelmer Vernooij
don't check for import, fastimport may not be installed. |
95 |
self.assertEqual({}, r.get_refs()) |
0.200.1586
by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper. |
96 |
|
0.200.1585
by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation. |
97 |
|
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
98 |
class ExecuteRemoteHelperTests(TestCaseWithTransport): |
99 |
||
100 |
def test_run(self): |
|
7290.11.4
by Jelmer Vernooij
Check whether git-remote-bzr actually exists. |
101 |
self.requireFeature(git_remote_bzr_feature) |
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
102 |
local_dir = self.make_branch_and_tree('local', format='git').controldir |
103 |
local_path = local_dir.control_transport.local_abspath('.') |
|
104 |
remote_tree = self.make_branch_and_tree('remote') |
|
105 |
remote_dir = remote_tree.controldir |
|
106 |
shortname = 'bzr' |
|
107 |
env = dict(os.environ) |
|
108 |
env['GIT_DIR'] = local_path |
|
7290.11.7
by Jelmer Vernooij
Set PYTHONPATH. |
109 |
env['PYTHONPATH'] = ':'.join(sys.path) |
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
110 |
p = subprocess.Popen( |
7290.11.6
by Jelmer Vernooij
Use the same python executable as for brz. |
111 |
[sys.executable, git_remote_bzr_path, local_path, remote_dir.user_url], |
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
112 |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
113 |
stderr=subprocess.PIPE, env=env) |
|
114 |
(out, err) = p.communicate(b'capabilities\n') |
|
115 |
lines = out.splitlines() |
|
7290.11.5
by Jelmer Vernooij
don't check for import, fastimport may not be installed. |
116 |
self.assertIn(b'push', lines, "no 'push' in %r, error: %r" % (lines, err)) |
7290.11.3
by Jelmer Vernooij
Add test for remote helper. |
117 |
self.assertEqual(b'', err) |
118 |
||
119 |
||
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
120 |
class RemoteHelperTests(TestCaseWithTransport): |
121 |
||
122 |
def setUp(self): |
|
123 |
super(RemoteHelperTests, self).setUp() |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
124 |
self.local_dir = self.make_branch_and_tree( |
125 |
'local', format='git').controldir |
|
0.200.1581
by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests. |
126 |
self.remote_tree = self.make_branch_and_tree('remote') |
0.200.1648
by Jelmer Vernooij
Fix compatibility with newer versions of breezy. |
127 |
self.remote_dir = self.remote_tree.controldir |
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
128 |
self.shortname = 'bzr' |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
129 |
self.helper = RemoteHelper( |
130 |
self.local_dir, self.shortname, self.remote_dir) |
|
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
131 |
|
132 |
def test_capabilities(self): |
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
133 |
f = BytesIO() |
0.200.1516
by Jelmer Vernooij
Add tests for capabilities command. |
134 |
self.helper.cmd_capabilities(f, []) |
135 |
capabs = f.getvalue() |
|
7018.3.2
by Jelmer Vernooij
Fix some git tests. |
136 |
base = b"fetch\noption\npush\n" |
7463.3.8
by Jelmer Vernooij
Fix test. |
137 |
self.assertTrue(capabs in (base + b"\n", base + b"import\nrefspec *:*\n\n"), capabs) |
0.200.1517
by Jelmer Vernooij
Add test for option command in git-remote-helper. |
138 |
|
139 |
def test_option(self): |
|
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
140 |
f = BytesIO() |
0.200.1517
by Jelmer Vernooij
Add test for option command in git-remote-helper. |
141 |
self.helper.cmd_option(f, []) |
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
142 |
self.assertEqual(b"unsupported\n", f.getvalue()) |
0.200.1517
by Jelmer Vernooij
Add test for option command in git-remote-helper. |
143 |
|
0.200.1518
by Jelmer Vernooij
Add basic test for list command. |
144 |
def test_list_basic(self): |
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
145 |
f = BytesIO() |
0.200.1518
by Jelmer Vernooij
Add basic test for list command. |
146 |
self.helper.cmd_list(f, []) |
6964.2.3
by Jelmer Vernooij
Review comments. |
147 |
self.assertEqual( |
7018.3.2
by Jelmer Vernooij
Fix some git tests. |
148 |
b'\n', |
0.200.1518
by Jelmer Vernooij
Add basic test for list command. |
149 |
f.getvalue()) |
0.200.1581
by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests. |
150 |
|
151 |
def test_import(self): |
|
7045.4.17
by Jelmer Vernooij
Fix tests. |
152 |
self.requireFeature(FastimportFeature) |
7018.3.8
by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport. |
153 |
self.build_tree_contents([("remote/afile", b"somecontent")]) |
0.200.1581
by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests. |
154 |
self.remote_tree.add(["afile"]) |
7018.3.8
by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport. |
155 |
self.remote_tree.commit(b"A commit message", timestamp=1330445983, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
156 |
timezone=0, committer=b'Somebody <jrandom@example.com>') |
6964.2.1
by Jelmer Vernooij
Initial work to support brz-git on python3. |
157 |
f = BytesIO() |
7027.5.2
by Jelmer Vernooij
Fix some more git tests. |
158 |
self.helper.cmd_import(f, ["import", "refs/heads/master"]) |
6964.2.3
by Jelmer Vernooij
Review comments. |
159 |
self.assertEqual( |
7194.1.3
by Jelmer Vernooij
Fix test. |
160 |
b'reset refs/heads/master\n' |
7018.3.8
by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport. |
161 |
b'commit refs/heads/master\n' |
162 |
b'mark :1\n' |
|
163 |
b'committer Somebody <jrandom@example.com> 1330445983 +0000\n' |
|
164 |
b'data 16\n' |
|
165 |
b'A commit message\n' |
|
166 |
b'M 644 inline afile\n' |
|
167 |
b'data 11\n' |
|
168 |
b'somecontent\n', |
|
0.200.1581
by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests. |
169 |
f.getvalue()) |