56
def create_tree_with_dotted_revno(self):
57
wt = self.make_branch_and_tree('branch')
58
self.build_tree(['branch/a'])
60
wt.commit('a', rev_id='r1')
62
other = wt.bzrdir.sprout('other').open_workingtree()
63
self.build_tree(['other/b.a'])
65
other.commit('b.a', rev_id='o2')
68
self.run_bzr('merge ../other')
69
wt.commit('merge', rev_id='merge')
71
wt.update(revision='o2')
76
class TestVersionInfoRio(VersionInfoTestCase):
78
def test_rio_null(self):
79
wt = self.make_branch_and_tree('branch')
82
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
85
self.assertContainsRe(val, 'build-date:')
86
self.assertContainsRe(val, 'revno: 0')
88
def test_rio_dotted_revno(self):
89
wt = self.create_tree_with_dotted_revno()
92
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
95
self.assertContainsRe(val, 'revno: 1.1.1')
97
def regen_text(self, wt, **kwargs):
99
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
100
builder.generate(sio)
104
def test_simple(self):
56
def test_rio_version_text(self):
105
57
wt = self.create_branch()
107
val = self.regen_text(wt)
61
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
108
68
self.assertContainsRe(val, 'build-date:')
109
69
self.assertContainsRe(val, 'date:')
110
70
self.assertContainsRe(val, 'revno: 3')
111
71
self.assertContainsRe(val, 'revision-id: r3')
113
def test_clean(self):
114
wt = self.create_branch()
115
val = self.regen_text(wt, check_for_clean=True)
73
val = regen(check_for_clean=True)
116
74
self.assertContainsRe(val, 'clean: True')
118
def test_no_clean(self):
119
wt = self.create_branch()
120
76
self.build_tree(['branch/c'])
121
val = self.regen_text(wt, check_for_clean=True)
77
val = regen(check_for_clean=True)
122
78
self.assertContainsRe(val, 'clean: False')
124
def test_history(self):
125
wt = self.create_branch()
127
val = self.regen_text(wt, include_revision_history=True)
81
val = regen(include_revision_history=True)
128
82
self.assertContainsRe(val, 'id: r1')
129
83
self.assertContainsRe(val, 'message: a')
130
84
self.assertContainsRe(val, 'id: r2')
132
86
self.assertContainsRe(val, 'id: r3')
133
87
self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
135
def regen(self, wt, **kwargs):
137
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
138
builder.generate(sio)
140
stanzas = list(read_stanzas(sio))
141
self.assertEqual(1, len(stanzas))
144
def test_rio_version_hook(self):
145
def update_stanza(rev, stanza):
146
stanza.add('bla', 'bloe')
147
RioVersionInfoBuilder.hooks.install_named_hook(
148
'revision', update_stanza, None)
149
wt = self.create_branch()
151
stanza = self.regen(wt)
152
self.assertEqual(['bloe'], stanza.get_all('bla'))
154
def get_one_stanza(self, stanza, key):
155
new_stanzas = list(read_stanzas(StringIO(stanza[key].encode('utf8'))))
156
self.assertEqual(1, len(new_stanzas))
157
return new_stanzas[0]
159
def test_build_date(self):
160
wt = self.create_branch()
161
stanza = self.regen(wt)
162
self.assertTrue('date' in stanza)
163
self.assertTrue('build-date' in stanza)
89
def test_rio_version(self):
90
wt = self.create_branch()
94
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
98
stanzas = list(read_stanzas(sio))
99
self.assertEqual(1, len(stanzas))
102
def get_one_stanza(stanza, key):
103
new_stanzas = list(read_stanzas(
104
StringIO(stanza[key].encode('utf8'))))
105
self.assertEqual(1, len(new_stanzas))
106
return new_stanzas[0]
109
self.failUnless('date' in stanza)
110
self.failUnless('build-date' in stanza)
164
111
self.assertEqual(['3'], stanza.get_all('revno'))
165
112
self.assertEqual(['r3'], stanza.get_all('revision-id'))
167
def test_not_clean(self):
168
wt = self.create_branch()
114
stanza = regen(check_for_clean=True)
115
self.assertEqual(['True'], stanza.get_all('clean'))
169
117
self.build_tree(['branch/c'])
170
stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
118
stanza = regen(check_for_clean=True, include_file_revisions=True)
171
119
self.assertEqual(['False'], stanza.get_all('clean'))
173
def test_file_revisions(self):
174
wt = self.create_branch()
175
self.build_tree(['branch/c'])
176
stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
177
# This assumes it's being run against a tree that does not update the
178
# root revision on every commit.
179
file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
121
# XXX: This assumes it's being run against a repository that updates
122
# the root revision on every commit. Newer ones that use
123
# RootCommitBuilder won't update it on each commit.
124
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
180
125
self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
181
self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
126
self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
182
127
file_rev_stanza.get_all('revision'))
128
os.remove('branch/c')
184
def test_revision_history(self):
185
wt = self.create_branch()
186
stanza = self.regen(wt, include_revision_history=True)
187
revision_stanza = self.get_one_stanza(stanza, 'revisions')
130
stanza = regen(include_revision_history=True)
131
revision_stanza = get_one_stanza(stanza, 'revisions')
188
132
self.assertEqual(['r1', 'r2', 'r3'], revision_stanza.get_all('id'))
189
133
self.assertEqual(['a', 'b', u'\xe52'], revision_stanza.get_all('message'))
190
134
self.assertEqual(3, len(revision_stanza.get_all('date')))
192
def test_file_revisions_with_rename(self):
193
136
# a was modified, so it should show up modified again
194
wt = self.create_branch()
195
137
self.build_tree(['branch/a', 'branch/c'])
197
139
wt.rename_one('b', 'd')
198
stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
199
file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
200
self.assertEqual(['', 'a', 'b', 'c', 'd'],
140
stanza = regen(check_for_clean=True, include_file_revisions=True)
141
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
142
self.assertEqual(['', 'a', 'b', 'c', 'd'],
201
143
file_rev_stanza.get_all('path'))
202
self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
144
self.assertEqual(['r3', 'modified', 'renamed to d', 'new',
203
145
'renamed from b'],
204
146
file_rev_stanza.get_all('revision'))
206
def test_file_revisions_with_removal(self):
207
wt = self.create_branch()
208
self.build_tree(['branch/a', 'branch/c'])
210
wt.rename_one('b', 'd')
212
148
wt.commit('modified', rev_id='r4')
214
149
wt.remove(['c', 'd'])
215
150
os.remove('branch/d')
216
stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
217
file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
151
stanza = regen(check_for_clean=True, include_file_revisions=True)
152
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
218
153
self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
219
self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
220
file_rev_stanza.get_all('revision'))
222
def test_revision(self):
223
wt = self.create_branch()
224
self.build_tree(['branch/a', 'branch/c'])
226
wt.rename_one('b', 'd')
228
stanza = self.regen(wt, check_for_clean=True,
229
include_file_revisions=True, revision_id=wt.last_revision())
230
file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
231
self.assertEqual(['', 'a', 'b'], file_rev_stanza.get_all('path'))
232
self.assertEqual(['r1', 'r3', 'r2'],
233
file_rev_stanza.get_all('revision'))
236
class PythonVersionInfoTests(VersionInfoTestCase):
238
def test_python_null(self):
239
wt = self.make_branch_and_tree('branch')
242
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
243
builder.generate(sio)
245
self.assertContainsRe(val, "'revision_id': None")
246
self.assertContainsRe(val, "'revno': '0'")
247
self.assertNotContainsString(val, '\n\n\n\n')
249
def test_python_dotted_revno(self):
250
wt = self.create_tree_with_dotted_revno()
253
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
254
builder.generate(sio)
256
self.assertContainsRe(val, "'revno': '1.1.1'")
258
def regen(self, wt, **kwargs):
259
"""Create a test module, import and return it"""
260
outf = open('test_version_information.py', 'wb')
262
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
264
builder.generate(outf)
267
module_info = imp.find_module('test_version_information',
269
tvi = imp.load_module('tvi', *module_info)
270
# Make sure the module isn't cached
271
sys.modules.pop('tvi', None)
272
sys.modules.pop('test_version_information', None)
273
# Delete the compiled versions, because we are generating
274
# a new file fast enough that python doesn't detect it
275
# needs to recompile, and using sleep() just makes the
277
if os.path.exists('test_version_information.pyc'):
278
os.remove('test_version_information.pyc')
279
if os.path.exists('test_version_information.pyo'):
280
os.remove('test_version_information.pyo')
154
self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
155
file_rev_stanza.get_all('revision'))
283
157
def test_python_version(self):
284
158
wt = self.create_branch()
287
self.assertEqual('3', tvi.version_info['revno'])
161
"""Create a test module, import and return it"""
162
outf = open('test_version_information.py', 'wb')
164
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
166
builder.generate(outf)
169
module_info = imp.find_module('test_version_information',
171
tvi = imp.load_module('tvi', *module_info)
172
# Make sure the module isn't cached
173
sys.modules.pop('tvi', None)
174
sys.modules.pop('test_version_information', None)
175
# Delete the compiled versions, because we are generating
176
# a new file fast enough that python doesn't detect it
177
# needs to recompile, and using sleep() just makes the
179
if os.path.exists('test_version_information.pyc'):
180
os.remove('test_version_information.pyc')
181
if os.path.exists('test_version_information.pyo'):
182
os.remove('test_version_information.pyo')
186
self.assertEqual(3, tvi.version_info['revno'])
288
187
self.assertEqual('r3', tvi.version_info['revision_id'])
289
self.assertTrue(tvi.version_info.has_key('date'))
188
self.failUnless(tvi.version_info.has_key('date'))
290
189
self.assertEqual(None, tvi.version_info['clean'])
292
tvi = self.regen(wt, check_for_clean=True)
191
tvi = regen(check_for_clean=True)
293
192
self.assertEqual(True, tvi.version_info['clean'])
295
194
self.build_tree(['branch/c'])
296
tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
195
tvi = regen(check_for_clean=True, include_file_revisions=True)
297
196
self.assertEqual(False, tvi.version_info['clean'])
298
self.assertEqual(['', 'a', 'b', 'c'],
197
self.assertEqual(['', 'a', 'b', 'c'],
299
198
sorted(tvi.file_revisions.keys()))
300
199
self.assertEqual('r3', tvi.file_revisions['a'])
301
200
self.assertEqual('r2', tvi.file_revisions['b'])
302
201
self.assertEqual('unversioned', tvi.file_revisions['c'])
303
202
os.remove('branch/c')
305
tvi = self.regen(wt, include_revision_history=True)
204
tvi = regen(include_revision_history=True)
307
206
rev_info = [(rev, message) for rev, message, timestamp, timezone
308
207
in tvi.revisions]
323
222
wt.commit('modified', rev_id='r4')
324
223
wt.remove(['c', 'd'])
325
224
os.remove('branch/d')
326
tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
327
self.assertEqual(['', 'a', 'c', 'd'],
225
tvi = regen(check_for_clean=True, include_file_revisions=True)
226
self.assertEqual(['', 'a', 'c', 'd'],
328
227
sorted(tvi.file_revisions.keys()))
329
228
self.assertEqual('r4', tvi.file_revisions['a'])
330
229
self.assertEqual('unversioned', tvi.file_revisions['c'])
331
230
self.assertEqual('removed', tvi.file_revisions['d'])
334
class CustomVersionInfoTests(VersionInfoTestCase):
336
def test_custom_null(self):
338
wt = self.make_branch_and_tree('branch')
339
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
340
template='revno: {revno}')
341
builder.generate(sio)
342
self.assertEquals("revno: 0", sio.getvalue())
344
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
345
template='{revno} revid: {revision_id}')
346
# revision_id is not available yet
347
self.assertRaises(errors.MissingTemplateVariable,
348
builder.generate, sio)
350
def test_custom_dotted_revno(self):
352
wt = self.create_tree_with_dotted_revno()
353
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
354
template='{revno} revid: {revision_id}')
355
builder.generate(sio)
356
self.assertEquals("1.1.1 revid: o2", sio.getvalue())
358
def regen(self, wt, tpl, **kwargs):
360
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
361
template=tpl, **kwargs)
362
builder.generate(sio)
366
def test_build_date(self):
232
def test_custom_version_text(self):
367
233
wt = self.create_branch()
369
val = self.regen(wt, 'build-date: "{build_date}"\ndate: "{date}"')
235
def regen(tpl, **kwargs):
237
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
238
template=tpl, **kwargs)
239
builder.generate(sio)
243
val = regen('build-date: "{build_date}"\ndate: "{date}"')
370
244
self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
371
245
self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
373
def test_revno(self):
374
wt = self.create_branch()
375
val = self.regen(wt, 'revno: {revno}')
247
val = regen('revno: {revno}')
376
248
self.assertEqual(val, 'revno: 3')
378
def test_revision_id(self):
379
wt = self.create_branch()
380
val = self.regen(wt, 'revision-id: {revision_id}')
250
val = regen('revision-id: {revision_id}')
381
251
self.assertEqual(val, 'revision-id: r3')
383
def test_clean(self):
384
wt = self.create_branch()
385
val = self.regen(wt, 'clean: {clean}', check_for_clean=True)
253
val = regen('clean: {clean}', check_for_clean=True)
386
254
self.assertEqual(val, 'clean: 1')
388
def test_not_clean(self):
389
wt = self.create_branch()
391
256
self.build_tree(['branch/c'])
392
val = self.regen(wt, 'clean: {clean}', check_for_clean=True)
257
val = regen('clean: {clean}', check_for_clean=True)
393
258
self.assertEqual(val, 'clean: 0')
394
259
os.remove('branch/c')