/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
1
#!/usr/bin/env python
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
22
from __future__ import absolute_import
23
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
24
from io import BytesIO
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
25
import os
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
    TestSkipped,
32
    )
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.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
38
    fastexporter,
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
39
    fetch,
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
40
    )
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
41
42
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
43
def map_to_git_sha1(dir, bzr_revid):
44
    object_store = get_object_store(dir.open_repository())
0.200.1788 by Jelmer Vernooij
Use context managers.
45
    with object_store.lock_read():
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
46
        return object_store._lookup_revision_sha1(bzr_revid)
47
48
0.200.1515 by Jelmer Vernooij
Add tests for git_remote_helper.
49
class OpenLocalDirTests(TestCaseWithTransport):
50
51
    def test_from_env_dir(self):
52
        self.make_branch_and_tree('bla', format='git')
53
        self.overrideEnv('GIT_DIR', os.path.join(self.test_dir, 'bla', '.git'))
54
        open_local_dir()
55
56
    def test_from_dir(self):
57
        self.make_branch_and_tree('.', format='git')
58
        open_local_dir()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
59
60
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
61
class FetchTests(TestCaseWithTransport):
62
63
    def setUp(self):
64
        super(FetchTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
65
        self.local_dir = self.make_branch_and_tree('local', format='git').controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
66
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
67
        self.remote_dir = self.remote_tree.controldir
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
68
        self.shortname = 'bzr'
69
70
    def fetch(self, wants):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
71
        outf = BytesIO()
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
72
        fetch(outf, wants, self.shortname, self.remote_dir, self.local_dir)
73
        return outf.getvalue()
74
75
    def test_no_wants(self):
76
        r = self.fetch([])
6964.2.3 by Jelmer Vernooij
Review comments.
77
        self.assertEqual("\n", r)
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
78
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
79
    def test_simple(self):
80
        self.build_tree(['remote/foo'])
81
        self.remote_tree.add("foo")
82
        revid = self.remote_tree.commit("msg")
83
        git_sha1 = map_to_git_sha1(self.remote_dir, revid)
84
        out = self.fetch([(git_sha1, 'HEAD')])
6964.2.3 by Jelmer Vernooij
Review comments.
85
        self.assertEqual(out, "\n")
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
86
        r = Repo('local')
87
        self.assertTrue(git_sha1 in r.object_store)
6964.2.3 by Jelmer Vernooij
Review comments.
88
        self.assertEqual({
0.310.9 by Jelmer Vernooij
Some controldir fixes.
89
            }, r.get_refs())
0.200.1586 by Jelmer Vernooij
Fixes duplicate tag warnings in 'git-remote-bzr' helper.
90
0.200.1585 by Jelmer Vernooij
Add really basic test for remote helper 'fetch' implementation.
91
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
92
class RemoteHelperTests(TestCaseWithTransport):
93
94
    def setUp(self):
95
        super(RemoteHelperTests, self).setUp()
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
96
        self.local_dir = self.make_branch_and_tree('local', format='git').controldir
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
97
        self.remote_tree = self.make_branch_and_tree('remote')
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
98
        self.remote_dir = self.remote_tree.controldir
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
99
        self.shortname = 'bzr'
100
        self.helper = RemoteHelper(self.local_dir, self.shortname, self.remote_dir)
101
102
    def test_capabilities(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
103
        f = BytesIO()
0.200.1516 by Jelmer Vernooij
Add tests for capabilities command.
104
        self.helper.cmd_capabilities(f, [])
105
        capabs = f.getvalue()
106
        base = "fetch\noption\npush\n"
107
        self.assertTrue(capabs in (base+"\n", base+"import\n\n"), capabs)
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
108
109
    def test_option(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
110
        f = BytesIO()
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
111
        self.helper.cmd_option(f, [])
6964.2.3 by Jelmer Vernooij
Review comments.
112
        self.assertEqual("unsupported\n", f.getvalue())
0.200.1517 by Jelmer Vernooij
Add test for option command in git-remote-helper.
113
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
114
    def test_list_basic(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
115
        f = BytesIO()
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
116
        self.helper.cmd_list(f, [])
6964.2.3 by Jelmer Vernooij
Review comments.
117
        self.assertEqual(
0.377.1 by Jelmer Vernooij
Fix some remote operations and add more tests.
118
            '\n',
0.200.1518 by Jelmer Vernooij
Add basic test for list command.
119
            f.getvalue())
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
120
121
    def test_import(self):
0.200.1582 by Jelmer Vernooij
Print error when bzr-fastimport is not installed.
122
        if fastexporter is None:
123
            raise TestSkipped("bzr-fastimport not available")
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
124
        self.build_tree_contents([("remote/afile", "somecontent")])
125
        self.remote_tree.add(["afile"])
126
        self.remote_tree.commit("A commit message", timestamp=1330445983,
127
            timezone=0, committer='Somebody <jrandom@example.com>')
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
128
        f = BytesIO()
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
129
        self.helper.cmd_import(f, ["import", "refs/heads/master"])
6964.2.3 by Jelmer Vernooij
Review comments.
130
        self.assertEqual(
0.200.1581 by Jelmer Vernooij
Fix support for newer versions of bzr-fastimport, add more tests.
131
            'commit refs/heads/master\n'
132
            'mark :1\n'
133
            'committer Somebody <jrandom@example.com> 1330445983 +0000\n'
134
            'data 16\n'
135
            'A commit message\n'
136
            'M 644 inline afile\n'
137
            'data 11\n'
138
            'somecontent\n',
139
            f.getvalue())