/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
1
# Copyright (C) 2007 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
16
17
"""Test our ability to build up test repositories"""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
21
from io import BytesIO
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
22
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
23
from dulwich.repo import Repo as GitRepo
24
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
25
from .. import tests
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
26
27
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
28
class TestGitBranchBuilder(tests.TestCase):
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
29
30
    def test__create_blob(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
31
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
32
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
33
        self.assertEqual(1, builder._create_blob(b'foo\nbar\n'))
34
        self.assertEqualDiff(b'blob\nmark :1\ndata 8\nfoo\nbar\n\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
35
                             stream.getvalue())
36
37
    def test_set_file(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
38
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
39
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
40
        builder.set_file('foobar', b'foo\nbar\n', False)
41
        self.assertEqualDiff(b'blob\nmark :1\ndata 8\nfoo\nbar\n\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
42
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
43
        self.assertEqual([b'M 100644 :1 foobar\n'], builder.commit_info)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
44
45
    def test_set_file_unicode(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
46
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
47
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
48
        builder.set_file(u'f\xb5/bar', b'contents\nbar\n', False)
49
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nbar\n\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
50
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
51
        self.assertEqual([b'M 100644 :1 f\xc2\xb5/bar\n'], builder.commit_info)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
52
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
53
    def test_set_file_newline(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
54
        stream = BytesIO()
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
55
        builder = tests.GitBranchBuilder(stream)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
56
        builder.set_file(u'foo\nbar', b'contents\nbar\n', False)
57
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nbar\n\n',
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
58
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
59
        self.assertEqual([b'M 100644 :1 "foo\\nbar"\n'], builder.commit_info)
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
60
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
61
    def test_set_file_executable(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
62
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
63
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
64
        builder.set_file(u'f\xb5/bar', b'contents\nbar\n', True)
65
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nbar\n\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
66
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
67
        self.assertEqual([b'M 100755 :1 f\xc2\xb5/bar\n'], builder.commit_info)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
68
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
69
    def test_set_symlink(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
70
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
71
        builder = tests.GitBranchBuilder(stream)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
72
        builder.set_symlink(u'f\xb5/bar', b'link/contents')
7018.3.2 by Jelmer Vernooij
Fix some git tests.
73
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\nlink/contents\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
74
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
75
        self.assertEqual([b'M 120000 :1 f\xc2\xb5/bar\n'], builder.commit_info)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
76
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
77
    def test_set_symlink_newline(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
78
        stream = BytesIO()
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
79
        builder = tests.GitBranchBuilder(stream)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
80
        builder.set_symlink(u'foo\nbar', 'link/contents')
7018.3.2 by Jelmer Vernooij
Fix some git tests.
81
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\nlink/contents\n',
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
82
                             stream.getvalue())
7018.3.2 by Jelmer Vernooij
Fix some git tests.
83
        self.assertEqual([b'M 120000 :1 "foo\\nbar"\n'], builder.commit_info)
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
84
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
85
    def test_delete_entry(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
86
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
87
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
88
        builder.delete_entry(u'path/to/f\xb5')
7018.3.2 by Jelmer Vernooij
Fix some git tests.
89
        self.assertEqual([b'D path/to/f\xc2\xb5\n'], builder.commit_info)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
90
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
91
    def test_delete_entry_newline(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
92
        stream = BytesIO()
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
93
        builder = tests.GitBranchBuilder(stream)
94
        builder.delete_entry(u'path/to/foo\nbar')
7018.3.2 by Jelmer Vernooij
Fix some git tests.
95
        self.assertEqual([b'D "path/to/foo\\nbar"\n'], builder.commit_info)
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
96
97
    def test_encode_path(self):
98
        encode = tests.GitBranchBuilder._encode_path
99
        # Unicode is encoded to utf-8
7018.3.2 by Jelmer Vernooij
Fix some git tests.
100
        self.assertEqual(encode(u'f\xb5'), b'f\xc2\xb5')
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
101
        # The name must be quoted if it starts by a double quote or contains a
102
        # newline.
7018.3.2 by Jelmer Vernooij
Fix some git tests.
103
        self.assertEqual(encode(u'"foo'), b'"\\"foo"')
104
        self.assertEqual(encode(u'fo\no'), b'"fo\\no"')
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
105
        # When the name is quoted, all backslash and quote chars must be
106
        # escaped.
7018.3.2 by Jelmer Vernooij
Fix some git tests.
107
        self.assertEqual(encode(u'fo\\o\nbar'), b'"fo\\\\o\\nbar"')
108
        self.assertEqual(encode(u'fo"o"\nbar'), b'"fo\\"o\\"\\nbar"')
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
109
        # Other control chars, such as \r, need not be escaped.
7018.3.2 by Jelmer Vernooij
Fix some git tests.
110
        self.assertEqual(encode(u'foo\r\nbar'), b'"foo\r\\nbar"')
0.200.36 by David Allouche
GitBranchBuilder now handles file names with newlines correctly.
111
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
112
    def test_add_and_commit(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
113
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
114
        builder = tests.GitBranchBuilder(stream)
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
115
7018.3.2 by Jelmer Vernooij
Fix some git tests.
116
        builder.set_file(u'f\xb5/bar', b'contents\nbar\n', False)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
117
        self.assertEqual(b'2', builder.commit(b'Joe Foo <joe@foo.com>',
7143.15.2 by Jelmer Vernooij
Run autopep8.
118
                                              u'committing f\xb5/bar',
119
                                              timestamp=1194586400,
120
                                              timezone=b'+0100'))
7018.3.2 by Jelmer Vernooij
Fix some git tests.
121
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nbar\n\n'
122
                             b'commit refs/heads/master\n'
123
                             b'mark :2\n'
124
                             b'committer Joe Foo <joe@foo.com> 1194586400 +0100\n'
125
                             b'data 18\n'
126
                             b'committing f\xc2\xb5/bar'
127
                             b'\n'
128
                             b'M 100644 :1 f\xc2\xb5/bar\n'
129
                             b'\n',
0.200.22 by John Arbash Meinel
Initial work on a GitCommitBuilder to make the test suite run in no-glacial time.
130
                             stream.getvalue())
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
131
132
    def test_commit_base(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
133
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
134
        builder = tests.GitBranchBuilder(stream)
135
7018.3.2 by Jelmer Vernooij
Fix some git tests.
136
        builder.set_file(u'foo', b'contents\nfoo\n', False)
137
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'first',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
138
                            timestamp=1194586400)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
139
        r2 = builder.commit(b'Joe Foo <joe@foo.com>', u'second',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
140
                            timestamp=1194586405)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
141
        r3 = builder.commit(b'Joe Foo <joe@foo.com>', u'third',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
142
                            timestamp=1194586410,
143
                            base=r1)
144
7018.3.2 by Jelmer Vernooij
Fix some git tests.
145
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
146
                             b'commit refs/heads/master\n'
147
                             b'mark :2\n'
148
                             b'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
149
                             b'data 5\n'
150
                             b'first'
151
                             b'\n'
152
                             b'M 100644 :1 foo\n'
153
                             b'\n'
154
                             b'commit refs/heads/master\n'
155
                             b'mark :3\n'
156
                             b'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
157
                             b'data 6\n'
158
                             b'second'
159
                             b'\n'
160
                             b'\n'
161
                             b'commit refs/heads/master\n'
162
                             b'mark :4\n'
163
                             b'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
164
                             b'data 5\n'
165
                             b'third'
166
                             b'\n'
167
                             b'from :2\n'
168
                             b'\n', stream.getvalue())
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
169
170
    def test_commit_merge(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
171
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
172
        builder = tests.GitBranchBuilder(stream)
173
7018.3.2 by Jelmer Vernooij
Fix some git tests.
174
        builder.set_file(u'foo', b'contents\nfoo\n', False)
175
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'first',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
176
                            timestamp=1194586400)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
177
        r2 = builder.commit(b'Joe Foo <joe@foo.com>', u'second',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
178
                            timestamp=1194586405)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
179
        r3 = builder.commit(b'Joe Foo <joe@foo.com>', u'third',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
180
                            timestamp=1194586410,
181
                            base=r1)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
182
        r4 = builder.commit(b'Joe Foo <joe@foo.com>', u'Merge',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
183
                            timestamp=1194586415,
184
                            merge=[r2])
185
7018.3.2 by Jelmer Vernooij
Fix some git tests.
186
        self.assertEqualDiff(b'blob\nmark :1\ndata 13\ncontents\nfoo\n\n'
187
                             b'commit refs/heads/master\n'
188
                             b'mark :2\n'
189
                             b'committer Joe Foo <joe@foo.com> 1194586400 +0000\n'
190
                             b'data 5\n'
191
                             b'first'
192
                             b'\n'
193
                             b'M 100644 :1 foo\n'
194
                             b'\n'
195
                             b'commit refs/heads/master\n'
196
                             b'mark :3\n'
197
                             b'committer Joe Foo <joe@foo.com> 1194586405 +0000\n'
198
                             b'data 6\n'
199
                             b'second'
200
                             b'\n'
201
                             b'\n'
202
                             b'commit refs/heads/master\n'
203
                             b'mark :4\n'
204
                             b'committer Joe Foo <joe@foo.com> 1194586410 +0000\n'
205
                             b'data 5\n'
206
                             b'third'
207
                             b'\n'
208
                             b'from :2\n'
209
                             b'\n'
210
                             b'commit refs/heads/master\n'
211
                             b'mark :5\n'
212
                             b'committer Joe Foo <joe@foo.com> 1194586415 +0000\n'
213
                             b'data 5\n'
214
                             b'Merge'
215
                             b'\n'
216
                             b'merge :3\n'
217
                             b'\n', stream.getvalue())
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
218
219
    def test_auto_timestamp(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
220
        stream = BytesIO()
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
221
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
222
        builder.commit(b'Joe Foo <joe@foo.com>', u'message')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
223
        self.assertContainsRe(stream.getvalue(),
7018.3.2 by Jelmer Vernooij
Fix some git tests.
224
                              br'committer Joe Foo <joe@foo\.com> \d+ \+0000')
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
225
0.200.34 by David Allouche
GitBranchBuilder.reset()
226
    def test_reset(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
227
        stream = BytesIO()
0.200.34 by David Allouche
GitBranchBuilder.reset()
228
        builder = tests.GitBranchBuilder(stream)
229
        builder.reset()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
230
        self.assertEqualDiff(b'reset refs/heads/master\n\n', stream.getvalue())
0.200.34 by David Allouche
GitBranchBuilder.reset()
231
232
    def test_reset_named_ref(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
233
        stream = BytesIO()
0.200.34 by David Allouche
GitBranchBuilder.reset()
234
        builder = tests.GitBranchBuilder(stream)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
235
        builder.reset(b'refs/heads/branch')
236
        self.assertEqualDiff(b'reset refs/heads/branch\n\n', stream.getvalue())
0.200.34 by David Allouche
GitBranchBuilder.reset()
237
238
    def test_reset_revision(self):
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
239
        stream = BytesIO()
0.200.34 by David Allouche
GitBranchBuilder.reset()
240
        builder = tests.GitBranchBuilder(stream)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
241
        builder.reset(mark=b'123')
0.200.34 by David Allouche
GitBranchBuilder.reset()
242
        self.assertEqualDiff(
7018.3.2 by Jelmer Vernooij
Fix some git tests.
243
            b'reset refs/heads/master\n'
244
            b'from :123\n'
245
            b'\n', stream.getvalue())
0.200.34 by David Allouche
GitBranchBuilder.reset()
246
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
247
248
class TestGitBranchBuilderReal(tests.TestCaseInTempDir):
249
250
    def test_create_real_branch(self):
0.200.992 by Jelmer Vernooij
Avoid invoking git directly.
251
        GitRepo.init(".")
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
252
253
        builder = tests.GitBranchBuilder()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
254
        builder.set_file(u'foo', b'contents\nfoo\n', False)
255
        r1 = builder.commit(b'Joe Foo <joe@foo.com>', u'first',
0.200.23 by John Arbash Meinel
Clean up the builder, start using it for big speed gains.
256
                            timestamp=1194586400)
257
        mapping = builder.finish()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
258
        self.assertEqual({b'1': b'44411e8e9202177dd19b6599d7a7991059fa3cb4',
259
                          b'2': b'b0b62e674f67306fddcf72fa888c3b56df100d64',
7143.15.2 by Jelmer Vernooij
Run autopep8.
260
                          }, mapping)