/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/__init__.py

Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""The basic test suite for bzr-git."""
18
18
 
19
 
import subprocess
 
19
from cStringIO import StringIO
 
20
 
20
21
import time
21
22
 
22
23
from bzrlib import (
23
 
    osutils,
 
24
    errors as bzr_errors,
24
25
    tests,
25
 
    trace,
26
26
    )
27
27
from bzrlib.plugins.git import (
28
 
    errors,
 
28
    import_dulwich,
29
29
    )
30
30
 
31
31
TestCase = tests.TestCase
33
33
TestCaseWithTransport = tests.TestCaseWithTransport
34
34
TestCaseWithMemoryTransport = tests.TestCaseWithMemoryTransport
35
35
 
36
 
class _GitCommandFeature(tests.Feature):
 
36
class _DulwichFeature(tests.Feature):
37
37
 
38
38
    def _probe(self):
39
39
        try:
40
 
            p = subprocess.Popen(['git', '--version'], stdout=subprocess.PIPE)
41
 
        except IOError:
 
40
            import_dulwich()
 
41
        except bzr_errors.DependencyNotPresent:
42
42
            return False
43
 
        out, err = p.communicate()
44
 
        trace.mutter('Using: %s', out.rstrip('\n'))
45
43
        return True
46
44
 
47
45
    def feature_name(self):
48
 
        return 'git'
49
 
 
50
 
GitCommandFeature = _GitCommandFeature()
51
 
 
52
 
 
53
 
def run_git(*args):
54
 
    cmd = ['git'] + list(args)
55
 
    p = subprocess.Popen(cmd,
56
 
                         stdout=subprocess.PIPE,
57
 
                         stderr=subprocess.PIPE)
58
 
    out, err = p.communicate()
59
 
    if p.returncode != 0:
60
 
        raise AssertionError('Bad return code: %d for %s:\n%s'
61
 
                             % (p.returncode, ' '.join(cmd), err))
62
 
    return out
 
46
        return 'dulwich'
 
47
 
 
48
 
 
49
DulwichFeature = _DulwichFeature()
63
50
 
64
51
 
65
52
class GitBranchBuilder(object):
66
53
 
67
54
    def __init__(self, stream=None):
68
55
        self.commit_info = []
69
 
        self.stream = stream
70
 
        self._process = None
 
56
        self.orig_stream = stream
 
57
        if stream is None:
 
58
            self.stream = StringIO()
 
59
        else:
 
60
            self.stream = stream
71
61
        self._counter = 0
72
62
        self._branch = 'refs/heads/master'
73
 
        if stream is None:
74
 
            # Write the marks file into the git sandbox.
75
 
            self._marks_file_name = osutils.abspath('marks')
76
 
            self._process = subprocess.Popen(
77
 
                ['git', 'fast-import', '--quiet',
78
 
                 # GIT doesn't support '--export-marks foo'
79
 
                 # it only supports '--export-marks=foo'
80
 
                 # And gives a 'unknown option' otherwise.
81
 
                 '--export-marks=' + self._marks_file_name,
82
 
                ],
83
 
                stdout=subprocess.PIPE,
84
 
                stderr=subprocess.PIPE,
85
 
                stdin=subprocess.PIPE,
86
 
                )
87
 
            self.stream = self._process.stdin
88
 
        else:
89
 
            self._process = None
90
63
 
91
64
    def set_branch(self, branch):
92
65
        """Set the branch we are committing."""
93
66
        self._branch = branch
94
67
 
95
68
    def _write(self, text):
96
 
        try:
97
 
            self.stream.write(text)
98
 
        except IOError, e:
99
 
            if self._process is None:
100
 
                raise
101
 
            raise errors.GitCommandError(self._process.returncode,
102
 
                                         'git fast-import',
103
 
                                         self._process.stderr.read())
 
69
        self.stream.write(text)
104
70
 
105
71
    def _writelines(self, lines):
106
 
        try:
107
 
            self.stream.writelines(lines)
108
 
        except IOError, e:
109
 
            if self._process is None:
110
 
                raise
111
 
            raise errors.GitCommandError(self._process.returncode,
112
 
                                         'git fast-import',
113
 
                                         self._process.stderr.read())
 
72
        self.stream.writelines(lines)
114
73
 
115
74
    def _create_blob(self, content):
116
75
        self._counter += 1
213
172
 
214
173
    def finish(self):
215
174
        """We are finished building, close the stream, get the id mapping"""
216
 
        self.stream.close()
217
 
        if self._process is None:
218
 
            return {}
219
 
        if self._process.wait() != 0:
220
 
            raise errors.GitCommandError(self._process.returncode,
221
 
                                         'git fast-import',
222
 
                                         self._process.stderr.read())
223
 
        marks_file = open(self._marks_file_name)
224
 
        mapping = {}
225
 
        for line in marks_file:
226
 
            mark, shasum = line.split()
227
 
            assert mark.startswith(':')
228
 
            mapping[int(mark[1:])] = shasum
229
 
        marks_file.close()
230
 
        return mapping
 
175
        self.stream.seek(0)
 
176
        if self.orig_stream is None:
 
177
            from dulwich.repo import Repo
 
178
            r = Repo(".")
 
179
            from dulwich.fastexport import FastImporter
 
180
            importer = FastImporter(r)
 
181
            return importer.import_stream(self.stream)
231
182
 
232
183
 
233
184
def test_suite():
234
 
    loader = tests.TestLoader()
 
185
    loader = tests.TestUtil.TestLoader()
235
186
 
236
 
    suite = tests.TestSuite()
 
187
    suite = tests.TestUtil.TestSuite()
237
188
 
238
189
    testmod_names = [
239
190
        'test_blackbox',