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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# Copyright (C) 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Blackbox tests for version_info"""
import os
from bzrlib.tests import TestCaseWithTransport
class TestVersionInfo(TestCaseWithTransport):
def test_invalid_format(self):
self.run_bzr('version-info --format quijibo', retcode=3)
def create_tree(self):
wt = self.make_branch_and_tree('branch')
self.build_tree(['branch/a'])
wt.add('a')
wt.commit('adding a', rev_id='r1')
self.build_tree(['branch/b'])
wt.add('b')
wt.commit('adding b', rev_id='r2')
self.revisions = wt.branch.revision_history()
return wt
def test_basic(self):
self.create_tree()
txt = self.run_bzr('version-info branch')[0]
self.assertContainsRe(txt, 'date:')
self.assertContainsRe(txt, 'build-date:')
self.assertContainsRe(txt, 'revno: 2')
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
def test_all(self):
"""'--all' includes clean, revision history, and file revisions"""
self.create_tree()
txt = self.run_bzr('version-info branch --all')[0]
self.assertContainsRe(txt, 'date:')
self.assertContainsRe(txt, 'revno: 2')
self.assertContainsRe(txt, 'revision-id: ' + self.revisions[-1])
self.assertContainsRe(txt, 'clean: True')
self.assertContainsRe(txt, 'revisions:')
for rev_id in self.revisions:
self.assertContainsRe(txt, 'id: ' + rev_id)
self.assertContainsRe(txt, 'message: adding a')
self.assertContainsRe(txt, 'message: adding b')
self.assertContainsRe(txt, 'file-revisions:')
self.assertContainsRe(txt, 'path: a')
self.assertContainsRe(txt, 'path: b')
def test_clean(self):
"""Test that --check-clean includes the right info"""
self.create_tree()
txt = self.run_bzr('version-info branch --check-clean')[0]
self.assertContainsRe(txt, 'clean: True')
self.build_tree_contents([('branch/c', 'now unclean\n')])
txt = self.run_bzr('version-info branch --check-clean')[0]
self.assertContainsRe(txt, 'clean: False')
txt = self.run_bzr('version-info branch --check-clean'
' --include-file-revisions')[0]
self.assertContainsRe(txt, 'revision: unversioned')
os.remove('branch/c')
def test_no_working_tree(self):
tree = self.create_tree()
branch = self.make_branch('just_branch')
branch.pull(tree.branch)
txt = self.run_bzr('version-info just_branch')[0]
self.assertStartsWith(txt, 'revision-id: r2\n')
def assertEqualNoBuildDate(self, text1, text2):
"""Compare 2 texts, but ignore the build-date field.
build-date is the current timestamp, accurate to seconds. But the
clock is always ticking, and it may have ticked between the time
that text1 and text2 were generated.
"""
lines1 = text1.splitlines(True)
lines2 = text2.splitlines(True)
for line1, line2 in zip(lines1, lines2):
if line1.startswith('build-date: '):
self.assertStartsWith(line2, 'build-date: ')
else:
self.assertEqual(line1, line2)
self.assertEqual(len(lines1), len(lines2))
def test_no_branch(self):
"""Test that bzr defaults to the local working directory"""
self.create_tree()
txt1 = self.run_bzr('version-info branch')[0]
os.chdir('branch')
txt2 = self.run_bzr('version-info')[0]
self.assertEqualNoBuildDate(txt1, txt2)
def test_rio(self):
"""Test that we can pass --format=rio"""
self.create_tree()
txt = self.run_bzr('version-info branch')[0]
txt1 = self.run_bzr('version-info --format rio branch')[0]
txt2 = self.run_bzr('version-info --format=rio branch')[0]
self.assertEqualNoBuildDate(txt, txt1)
self.assertEqualNoBuildDate(txt, txt2)
def test_python(self):
"""Test that we can do --format=python"""
self.create_tree()
txt = self.run_bzr('version-info --format python branch')[0]
self.assertContainsRe(txt, 'version_info = {')
def test_custom_without_template(self):
wt = self.make_branch_and_tree('branch')
out, err = self.run_bzr('version-info --custom', retcode=3)
self.assertContainsRe(err, r'ERROR: No template specified\.')
def test_custom_implies_all(self):
self.create_tree()
out, err = self.run_bzr('version-info --custom --template='
'"{revno} {branch_nick} {clean}\n" branch')
self.assertEqual("2 branch 1\n", out)
self.assertEqual("", err)
self.build_tree_contents([('branch/c', 'now unclean\n')])
out, err = self.run_bzr('version-info --custom --template='
'"{revno} {branch_nick} {clean}\n" branch')
self.assertEqual("2 branch 0\n", out)
self.assertEqual("", err)
|