27
from cStringIO import StringIO
33
from bzrlib.branch import Branch
34
from bzrlib.errors import BzrCommandError
35
from bzrlib.osutils import has_symlinks
36
from bzrlib.tests import TestCaseInTempDir, BzrTestBase
37
from bzrlib.annotate import annotate_file
40
class TestAnnotate(TestCaseInTempDir):
29
from bzrlib.tests import TestCaseWithTransport
32
class TestAnnotate(TestCaseWithTransport):
42
35
super(TestAnnotate, self).setUp()
43
b = Branch.initialize(u'.')
36
wt = self.make_branch_and_tree('.')
44
38
self.build_tree_contents([('hello.txt', 'my helicopter\n'),
45
39
('nomail.txt', 'nomail\n')])
46
b.working_tree().add(['hello.txt'])
47
b.working_tree().commit('add hello',
48
committer='test@user')
49
b.working_tree().add(['nomail.txt'])
50
b.working_tree().commit('add nomail', committer='no mail')
41
self.revision_id_1 = wt.commit('add hello',
42
committer='test@user',
43
timestamp=1165960000.00, timezone=0)
44
wt.add(['nomail.txt'])
45
self.revision_id_2 = wt.commit('add nomail',
47
timestamp=1165970000.00, timezone=0)
48
self.build_tree_contents([('hello.txt', 'my helicopter\n'
49
'your helicopter\n')])
50
self.revision_id_3 = wt.commit('mod hello',
51
committer='user@test',
52
timestamp=1166040000.00, timezone=0)
53
self.build_tree_contents([('hello.txt', 'my helicopter\n'
58
self.revision_id_4 = wt.commit('mod hello',
59
committer='user@test',
60
timestamp=1166050000.00, timezone=0)
52
62
def test_help_annotate(self):
53
63
"""Annotate command exists"""
54
out, err = self.run_bzr_captured(['--no-plugins', 'annotate', '--help'])
64
out, err = self.run_bzr('--no-plugins annotate --help')
56
66
def test_annotate_cmd(self):
57
out, err = self.run_bzr_captured(['annotate', 'hello.txt'])
58
self.assertEquals(err, '')
59
self.assertEqualDiff(out, '''\
60
1 test@us | my helicopter
67
out, err = self.run_bzr('annotate hello.txt')
68
self.assertEqual('', err)
69
self.assertEqualDiff('''\
70
1 test@us | my helicopter
71
3 user@te | your helicopter
76
def test_annotate_cmd_full(self):
77
out, err = self.run_bzr('annotate hello.txt --all')
78
self.assertEqual('', err)
79
self.assertEqualDiff('''\
80
1 test@us | my helicopter
81
3 user@te | your helicopter
83
4 user@te | our helicopters
86
def test_annotate_cmd_long(self):
87
out, err = self.run_bzr('annotate hello.txt --long')
88
self.assertEqual('', err)
89
self.assertEqualDiff('''\
90
1 test@user 20061212 | my helicopter
91
3 user@test 20061213 | your helicopter
92
4 user@test 20061213 | all of
96
def test_annotate_cmd_show_ids(self):
97
out, err = self.run_bzr('annotate hello.txt --show-ids')
98
max_len = max([len(self.revision_id_1),
99
len(self.revision_id_3),
100
len(self.revision_id_4)])
101
self.assertEqual('', err)
102
self.assertEqualDiff('''\
104
%*s | your helicopter
106
%*s | our helicopters
107
''' % (max_len, self.revision_id_1,
108
max_len, self.revision_id_3,
109
max_len, self.revision_id_4,
63
114
def test_no_mail(self):
64
out, err = self.run_bzr_captured(['annotate', 'nomail.txt'])
65
self.assertEquals(err, '')
66
self.assertEqualDiff(out, '''\
115
out, err = self.run_bzr('annotate nomail.txt')
116
self.assertEqual('', err)
117
self.assertEqualDiff('''\
121
def test_annotate_cmd_revision(self):
122
out, err = self.run_bzr('annotate hello.txt -r1')
123
self.assertEqual('', err)
124
self.assertEqualDiff('''\
125
1 test@us | my helicopter
128
def test_annotate_cmd_revision3(self):
129
out, err = self.run_bzr('annotate hello.txt -r3')
130
self.assertEqual('', err)
131
self.assertEqualDiff('''\
132
1 test@us | my helicopter
133
3 user@te | your helicopter
136
def test_annotate_cmd_unknown_revision(self):
137
out, err = self.run_bzr('annotate hello.txt -r 10',
139
self.assertEqual('', out)
140
self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
142
def test_annotate_cmd_two_revisions(self):
143
out, err = self.run_bzr('annotate hello.txt -r1..2',
145
self.assertEqual('', out)
146
self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
147
' exactly 1 argument\n',
150
def test_annotate_empty_file(self):
151
tree = self.make_branch_and_tree('tree')
152
self.build_tree_contents([('tree/empty', '')])
154
tree.commit('add empty file')
157
out, err = self.run_bzr('annotate empty')
158
self.assertEqual('', out)
160
def test_annotate_nonexistant_file(self):
161
tree = self.make_branch_and_tree('tree')
162
self.build_tree(['tree/file'])
164
tree.commit('add a file')
167
out, err = self.run_bzr("annotate doesnotexist", retcode=3)
168
self.assertEqual('', out)
169
self.assertEqual("bzr: ERROR: doesnotexist is not versioned\n", err)