1
# Copyright (C) 2005, 2006 Canonical Ltd
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.
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.
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
17
"""Blackbox tests for version_info"""
23
from bzrlib.tests import TestCase, TestCaseWithTransport
26
class TestVersionInfo(TestCaseWithTransport):
28
def test_invalid_format(self):
31
bzr('version-info', '--format', 'quijibo', retcode=3)
33
def create_branch(self):
34
wt = self.make_branch_and_tree('branch')
36
self.build_tree(['branch/a'])
38
wt.commit('adding a', rev_id='r1')
40
self.build_tree(['branch/b'])
42
wt.commit('adding b', rev_id='r2')
44
self.revisions = wt.branch.revision_history()
46
def test_default(self):
47
# smoketest that not supplying a --format still works
50
info = self.run_bzr('version-info', 'branch')[0]
56
return self.run_bzr('version-info', '--format', 'rio',
60
self.assertContainsRe(txt, 'date:')
61
self.assertContainsRe(txt, 'build-date:')
62
self.assertContainsRe(txt, 'revno: 2')
63
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
66
self.assertContainsRe(txt, 'date:')
67
self.assertContainsRe(txt, 'revno: 2')
68
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
69
self.assertContainsRe(txt, 'clean: True')
70
self.assertContainsRe(txt, 'revisions:')
71
for rev_id in self.revisions:
72
self.assertContainsRe(txt, 'id: ' + rev_id)
73
self.assertContainsRe(txt, 'message: adding a')
74
self.assertContainsRe(txt, 'message: adding b')
75
self.assertContainsRe(txt, 'file-revisions:')
76
self.assertContainsRe(txt, 'path: a')
77
self.assertContainsRe(txt, 'path: b')
79
txt = regen('--check-clean')
80
self.assertContainsRe(txt, 'clean: True')
82
open('branch/c', 'wb').write('now unclean\n')
83
txt = regen('--check-clean')
84
self.assertContainsRe(txt, 'clean: False')
86
txt = regen('--check-clean', '--include-file-revisions')
87
self.assertContainsRe(txt, 'revision: unversioned')
91
# Make sure it works without a directory
93
txt = self.run_bzr('version-info', '--format', 'rio')
95
def test_python(self):
96
def bzr(*args, **kwargs):
97
return self.run_bzr(*args, **kwargs)[0]
100
txt = self.run_bzr('version-info', '--format', 'python',
102
outf = open('test_version_information.py', 'wb')
105
module_info = imp.find_module('test_version_information',
107
tvi = imp.load_module('tvi', *module_info)
108
# Make sure the module isn't cached
109
sys.modules.pop('tvi', None)
110
sys.modules.pop('test_version_information', None)
111
# Delete the compiled versions, because we are generating
112
# a new file fast enough that python doesn't detect it
113
# needs to recompile, and using sleep() just makes the
115
if os.path.exists('test_version_information.pyc'):
116
os.remove('test_version_information.pyc')
117
if os.path.exists('test_version_information.pyo'):
118
os.remove('test_version_information.pyo')
124
self.assertEqual(tvi.version_info['revno'], 2)
125
self.failUnless(tvi.version_info.has_key('date'))
126
self.assertEqual(self.revisions[-1], tvi.version_info['revision_id'])
127
self.assertEqual({}, tvi.revisions)
128
self.assertEqual({}, tvi.file_revisions)
131
rev_info = [(rev, message) for rev, message, timestamp, timezone
133
self.assertEqual([(self.revisions[0], 'adding a'),
134
(self.revisions[1], 'adding b')],
136
self.assertEqual(True, tvi.version_info['clean'])
138
for path in sorted(tvi.file_revisions.keys()):
139
file_revisions.append((path, tvi.file_revisions[path]))
140
self.assertEqual([('a', self.revisions[0]), ('b', self.revisions[1])],
143
open('branch/c', 'wb').write('now unclean\n')
144
tvi = regen('--check-clean', '--include-file-revisions')
145
self.assertEqual(False, tvi.version_info['clean'])
146
self.assertEqual('unversioned', tvi.file_revisions['c'])
147
os.remove('branch/c')