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