/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
7
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
12
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
17
"""The basic test suite for bzr-git."""
18
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
19
from cStringIO import StringIO
20
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
21
import time
0.200.19 by John Arbash Meinel
More refactoring. Add some direct tests for GitModel.
22
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
23
from bzrlib import (
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
24
    errors as bzr_errors,
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
25
    tests,
26
    )
0.200.255 by Jelmer Vernooij
Fix formatting.
27
from bzrlib.plugins.git import (
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
28
    import_dulwich,
0.200.255 by Jelmer Vernooij
Fix formatting.
29
    )
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
30
31
TestCase = tests.TestCase
32
TestCaseInTempDir = tests.TestCaseInTempDir
33
TestCaseWithTransport = tests.TestCaseWithTransport
0.202.2 by David Allouche
GitRepository.get_inventory and .revision_tree work for the null revision. Support for testing GitRepository without disk data.
34
TestCaseWithMemoryTransport = tests.TestCaseWithMemoryTransport
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
35
0.200.987 by Jelmer Vernooij
Add DulwichFeature.
36
class _DulwichFeature(tests.Feature):
37
38
    def _probe(self):
39
        try:
40
            import_dulwich()
41
        except bzr_errors.DependencyNotPresent:
42
            return False
43
        return True
44
45
    def feature_name(self):
46
        return 'dulwich'
47
48
49
DulwichFeature = _DulwichFeature()
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
50
51
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
52
class GitBranchBuilder(object):
53
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
54
    def __init__(self, stream=None):
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
55
        self.commit_info = []
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
56
        self.orig_stream = stream
57
        if stream is None:
58
            self.stream = StringIO()
59
        else:
60
            self.stream = stream
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
61
        self._counter = 0
0.200.33 by David Allouche
Fix GitBranchBuilder to use refs/heads/master instead of refs/head/master.
62
        self._branch = 'refs/heads/master'
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
63
64
    def set_branch(self, branch):
65
        """Set the branch we are committing."""
66
        self._branch = branch
67
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
68
    def _write(self, text):
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
69
        self.stream.write(text)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
70
71
    def _writelines(self, lines):
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
72
        self.stream.writelines(lines)
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
73
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
74
    def _create_blob(self, content):
75
        self._counter += 1
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
76
        self._write('blob\n')
77
        self._write('mark :%d\n' % (self._counter,))
78
        self._write('data %d\n' % (len(content),))
79
        self._write(content)
80
        self._write('\n')
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
81
        return self._counter
82
0.200.551 by Jelmer Vernooij
Properly set InventoryEntry revision when changing symlink targets.
83
    def set_symlink(self, path, content):
84
        """Create or update symlink at a given path."""
85
        mark = self._create_blob(content)
86
        mode = '120000'
87
        self.commit_info.append('M %s :%d %s\n'
88
                % (mode, mark, self._encode_path(path)))
89
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
90
    def set_file(self, path, content, executable):
91
        """Create or update content at a given path."""
92
        mark = self._create_blob(content)
93
        if executable:
94
            mode = '100755'
95
        else:
96
            mode = '100644'
97
        self.commit_info.append('M %s :%d %s\n'
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
98
                                % (mode, mark, self._encode_path(path)))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
99
100
    def set_link(self, path, link_target):
101
        """Create or update a link at a given path."""
102
        mark = self._create_blob(link_target)
103
        self.commit_info.append('M 120000 :%d %s\n'
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
104
                                % (mark, self._encode_path(path)))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
105
106
    def delete_entry(self, path):
107
        """This will delete files or symlinks at the given location."""
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
108
        self.commit_info.append('D %s\n' % (self._encode_path(path),))
109
110
    @staticmethod
111
    def _encode_path(path):
112
        if '\n' in path or path[0] == '"':
113
            path = path.replace('\\', '\\\\')
114
            path = path.replace('\n', '\\n')
115
            path = path.replace('"', '\\"')
116
            path = '"' + path + '"'
117
        return path.encode('utf-8')
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
118
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
119
    # TODO: Author
120
    # TODO: Author timestamp+timezone
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
121
    def commit(self, committer, message, timestamp=None,
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
122
               timezone='+0000', author=None,
123
               merge=None, base=None):
124
        """Commit the new content.
125
126
        :param committer: The name and address for the committer
127
        :param message: The commit message
128
        :param timestamp: The timestamp for the commit
129
        :param timezone: The timezone of the commit, such as '+0000' or '-1000'
130
        :param author: The name and address of the author (if different from
131
            committer)
132
        :param merge: A list of marks if this should merge in another commit
133
        :param base: An id for the base revision (primary parent) if that
134
            is not the last commit.
135
        :return: A mark which can be used in the future to reference this
136
            commit.
137
        """
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
138
        self._counter += 1
139
        mark = self._counter
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
140
        if timestamp is None:
141
            timestamp = int(time.time())
142
        self._write('commit %s\n' % (self._branch,))
143
        self._write('mark :%d\n' % (mark,))
144
        self._write('committer %s %s %s\n'
145
                    % (committer, timestamp, timezone))
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
146
        message = message.encode('UTF-8')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
147
        self._write('data %d\n' % (len(message),))
148
        self._write(message)
149
        self._write('\n')
150
        if base is not None:
151
            self._write('from :%d\n' % (base,))
152
        if merge is not None:
153
            for m in merge:
154
                self._write('merge :%d\n' % (m,))
155
        self._writelines(self.commit_info)
156
        self._write('\n')
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
157
        self.commit_info = []
158
        return mark
159
0.200.34 by David Allouche
GitBranchBuilder.reset()
160
    def reset(self, ref=None, mark=None):
161
        """Create or recreate the named branch.
162
163
        :param ref: branch name, defaults to the current branch.
164
        :param mark: commit the branch will point to.
165
        """
166
        if ref is None:
167
            ref = self._branch
168
        self._write('reset %s\n' % (ref,))
169
        if mark is not None:
170
            self._write('from :%d\n' % mark)
171
        self._write('\n')
172
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
173
    def finish(self):
174
        """We are finished building, close the stream, get the id mapping"""
0.200.993 by Jelmer Vernooij
Remove all remaining dependencies on C git.
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)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
182
183
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
184
def test_suite():
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
185
    loader = tests.TestLoader()
186
187
    suite = tests.TestSuite()
188
189
    testmod_names = [
0.200.813 by Jelmer Vernooij
Add tests for revspec.
190
        'test_blackbox',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
191
        'test_builder',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
192
        'test_branch',
0.200.938 by Jelmer Vernooij
Rename shamap to cache, as it can also do content caching now.
193
        'test_cache',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
194
        'test_dir',
0.200.196 by Jelmer Vernooij
Add simple tests and docstrings for GraphWalker.
195
        'test_fetch',
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
196
        'test_mapping',
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
197
        'test_object_store',
0.200.967 by Jelmer Vernooij
Add initial test for push.
198
        'test_push',
0.200.709 by Jelmer Vernooij
When unpacking URLs, strip leftmost slash to match gits behaviour.
199
        'test_remote',
0.200.94 by Jelmer Vernooij
Eliminate (duplicate) git_ prefix.
200
        'test_repository',
0.200.872 by Jelmer Vernooij
Move refs code to separate module.
201
        'test_refs',
0.200.813 by Jelmer Vernooij
Add tests for revspec.
202
        'test_revspec',
0.252.1 by Jelmer Vernooij
Support storing revision id data.
203
        'test_roundtrip',
0.200.936 by Jelmer Vernooij
Test transportgit.
204
        'test_transportgit',
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
205
        ]
206
    testmod_names = ['%s.%s' % (__name__, t) for t in testmod_names]
207
    suite.addTests(loader.loadTestsFromModuleNames(testmod_names))
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
208
209
    return suite