1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# Copyright (C) 2005 Canonical Ltd
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""\
Blackbox tests for version_info
"""
import os
import sys
from bzrlib.tests import TestCase, TestCaseInTempDir
class TestVersionInfo(TestCaseInTempDir):
def test_invalid_format(self):
bzr = self.run_bzr
bzr('version-info', '--format', 'quijibo', retcode=3)
def create_branch(self):
bzr = self.run_bzr
os.mkdir('branch')
os.chdir('branch')
bzr('init')
open('a', 'wb').write('a file\n')
bzr('add')
bzr('commit', '-m', 'adding a')
open('b', 'wb').write('b file\n')
bzr('add')
bzr('commit', '-m', 'adding b')
os.chdir('..')
def get_revisions(self):
os.chdir('branch')
revisions = self.run_bzr('revision-history')[0].strip().split('\n')
os.chdir('..')
return revisions
def test_rio(self):
self.create_branch()
def regen(*args):
return self.run_bzr('version-info', '--format', 'rio',
'branch', *args)[0]
revisions = self.get_revisions()
txt = regen()
self.assertContainsRe(txt, 'date:')
self.assertContainsRe(txt, 'revno: 2')
self.assertContainsRe(txt, 'revision_id: ' + revisions[-1])
txt = regen('--all')
self.assertContainsRe(txt, 'date:')
self.assertContainsRe(txt, 'revno: 2')
self.assertContainsRe(txt, 'revision_id: ' + revisions[-1])
self.assertContainsRe(txt, 'clean: True')
self.assertContainsRe(txt, 'revisions:')
for rev_id in revisions:
self.assertContainsRe(txt, 'id: ' + rev_id)
self.assertContainsRe(txt, 'message: adding a')
self.assertContainsRe(txt, 'message: adding b')
txt = regen('--check-clean')
self.assertContainsRe(txt, 'clean: True')
open('branch/c', 'wb').write('now unclean\n')
txt = regen('--check-clean')
self.assertContainsRe(txt, 'clean: False')
os.remove('branch/c')
# Make sure it works without a directory
os.chdir('branch')
txt = self.run_bzr('version-info', '--format', 'rio')
def test_python(self):
def bzr(*args, **kwargs):
return self.run_bzr(*args, **kwargs)[0]
def regen(*args):
txt = self.run_bzr('version-info', '--format', 'python',
'branch', *args)[0]
outf = open('test_version_information.py', 'wb')
outf.write(txt)
outf.close()
try:
sys.path.append(os.getcwdu())
import test_version_information as tvi
reload(tvi)
finally:
sys.path.pop()
# Make sure the module isn't cached
sys.modules.pop('tvi', None)
sys.modules.pop('test_version_information', None)
# Delete the compiled versions, because we are generating
# a new file fast enough that python doen't detect it
# needs to recompile, and using sleep() just makes the
# test slow
if os.path.exists('test_version_information.pyc'):
os.remove('test_version_information.pyc')
if os.path.exists('test_version_information.pyo'):
os.remove('test_version_information.pyo')
return tvi
self.create_branch()
revisions = self.get_revisions()
tvi = regen()
self.assertEqual(tvi.version_info['revno'], 2)
self.failUnless(tvi.version_info.has_key('date'))
self.assertEqual(revisions[-1], tvi.version_info['revision_id'])
tvi = regen('--all')
self.assertEqual([(revisions[0], 'adding a'),
(revisions[1], 'adding b')],
tvi.version_info['revisions'])
self.assertEqual(True, tvi.version_info['clean'])
|