94
91
val = sio.getvalue()
95
92
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):
94
def test_rio_version_text(self):
105
95
wt = self.create_branch()
107
val = self.regen_text(wt)
99
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
101
builder.generate(sio)
108
106
self.assertContainsRe(val, 'build-date:')
109
107
self.assertContainsRe(val, 'date:')
110
108
self.assertContainsRe(val, 'revno: 3')
111
109
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)
111
val = regen(check_for_clean=True)
116
112
self.assertContainsRe(val, 'clean: True')
118
def test_no_clean(self):
119
wt = self.create_branch()
120
114
self.build_tree(['branch/c'])
121
val = self.regen_text(wt, check_for_clean=True)
115
val = regen(check_for_clean=True)
122
116
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)
117
os.remove('branch/c')
119
val = regen(include_revision_history=True)
128
120
self.assertContainsRe(val, 'id: r1')
129
121
self.assertContainsRe(val, 'message: a')
130
122
self.assertContainsRe(val, 'id: r2')
148
131
'revision', update_stanza, None)
149
132
wt = self.create_branch()
151
stanza = self.regen(wt)
136
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
138
builder.generate(sio)
140
stanzas = list(read_stanzas(sio))
141
self.assertEqual(1, len(stanzas))
152
145
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):
147
def test_rio_version(self):
160
148
wt = self.create_branch()
161
stanza = self.regen(wt)
152
builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
154
builder.generate(sio)
156
stanzas = list(read_stanzas(sio))
157
self.assertEqual(1, len(stanzas))
160
def get_one_stanza(stanza, key):
161
new_stanzas = list(read_stanzas(
162
StringIO(stanza[key].encode('utf8'))))
163
self.assertEqual(1, len(new_stanzas))
164
return new_stanzas[0]
162
167
self.assertTrue('date' in stanza)
163
168
self.assertTrue('build-date' in stanza)
164
169
self.assertEqual(['3'], stanza.get_all('revno'))
165
170
self.assertEqual(['r3'], stanza.get_all('revision-id'))
167
def test_not_clean(self):
168
wt = self.create_branch()
172
stanza = regen(check_for_clean=True)
173
self.assertEqual(['True'], stanza.get_all('clean'))
169
175
self.build_tree(['branch/c'])
170
stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
176
stanza = regen(check_for_clean=True, include_file_revisions=True)
171
177
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
179
# This assumes it's being run against a tree that does not update the
178
180
# root revision on every commit.
179
file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
181
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
180
182
self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
181
183
self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
182
184
file_rev_stanza.get_all('revision'))
185
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')
187
stanza = regen(include_revision_history=True)
188
revision_stanza = get_one_stanza(stanza, 'revisions')
188
189
self.assertEqual(['r1', 'r2', 'r3'], revision_stanza.get_all('id'))
189
190
self.assertEqual(['a', 'b', u'\xe52'], revision_stanza.get_all('message'))
190
191
self.assertEqual(3, len(revision_stanza.get_all('date')))
192
def test_file_revisions_with_rename(self):
193
193
# a was modified, so it should show up modified again
194
wt = self.create_branch()
195
194
self.build_tree(['branch/a', 'branch/c'])
197
196
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')
197
stanza = regen(check_for_clean=True, include_file_revisions=True)
198
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
200
199
self.assertEqual(['', 'a', 'b', 'c', 'd'],
201
200
file_rev_stanza.get_all('path'))
202
201
self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
203
202
'renamed from b'],
204
203
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
205
wt.commit('modified', rev_id='r4')
214
206
wt.remove(['c', 'd'])
215
207
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')
208
stanza = regen(check_for_clean=True, include_file_revisions=True)
209
file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
218
210
self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
219
211
self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
220
212
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
214
def test_python_null(self):
239
215
wt = self.make_branch_and_tree('branch')
255
231
val = sio.getvalue()
256
232
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')
283
234
def test_python_version(self):
284
235
wt = self.create_branch()
238
"""Create a test module, import and return it"""
239
outf = open('test_version_information.py', 'wb')
241
builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
243
builder.generate(outf)
246
module_info = imp.find_module('test_version_information',
248
tvi = imp.load_module('tvi', *module_info)
249
# Make sure the module isn't cached
250
sys.modules.pop('tvi', None)
251
sys.modules.pop('test_version_information', None)
252
# Delete the compiled versions, because we are generating
253
# a new file fast enough that python doesn't detect it
254
# needs to recompile, and using sleep() just makes the
256
if os.path.exists('test_version_information.pyc'):
257
os.remove('test_version_information.pyc')
258
if os.path.exists('test_version_information.pyo'):
259
os.remove('test_version_information.pyo')
287
263
self.assertEqual('3', tvi.version_info['revno'])
288
264
self.assertEqual('r3', tvi.version_info['revision_id'])
289
265
self.assertTrue(tvi.version_info.has_key('date'))
290
266
self.assertEqual(None, tvi.version_info['clean'])
292
tvi = self.regen(wt, check_for_clean=True)
268
tvi = regen(check_for_clean=True)
293
269
self.assertEqual(True, tvi.version_info['clean'])
295
271
self.build_tree(['branch/c'])
296
tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
272
tvi = regen(check_for_clean=True, include_file_revisions=True)
297
273
self.assertEqual(False, tvi.version_info['clean'])
298
274
self.assertEqual(['', 'a', 'b', 'c'],
299
275
sorted(tvi.file_revisions.keys()))
355
328
builder.generate(sio)
356
329
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):
331
def test_custom_version_text(self):
367
332
wt = self.create_branch()
369
val = self.regen(wt, 'build-date: "{build_date}"\ndate: "{date}"')
334
def regen(tpl, **kwargs):
336
builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
337
template=tpl, **kwargs)
338
builder.generate(sio)
342
val = regen('build-date: "{build_date}"\ndate: "{date}"')
370
343
self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
371
344
self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
373
def test_revno(self):
374
wt = self.create_branch()
375
val = self.regen(wt, 'revno: {revno}')
346
val = regen('revno: {revno}')
376
347
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}')
349
val = regen('revision-id: {revision_id}')
381
350
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)
352
val = regen('clean: {clean}', check_for_clean=True)
386
353
self.assertEqual(val, 'clean: 1')
388
def test_not_clean(self):
389
wt = self.create_branch()
391
355
self.build_tree(['branch/c'])
392
val = self.regen(wt, 'clean: {clean}', check_for_clean=True)
356
val = regen('clean: {clean}', check_for_clean=True)
393
357
self.assertEqual(val, 'clean: 0')
394
358
os.remove('branch/c')