/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_annotate.py

  • Committer: Aaron Bentley
  • Date: 2006-12-15 02:47:54 UTC
  • mfrom: (2158.2.1 bzrw1.1)
  • mto: This revision was merged to the branch mainline in revision 2189.
  • Revision ID: aaron.bentley@utoronto.ca-20061215024754-u067jln0jl714fpp
Windows tests cleanup.  (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr.
 
20
 
 
21
These check that it behaves properly when it's invoked through the regular
 
22
command-line interface. This doesn't actually run a new interpreter but 
 
23
rather starts again from the run_bzr function.
 
24
"""
 
25
 
 
26
 
 
27
import os
 
28
 
 
29
from bzrlib.tests import TestCaseWithTransport
 
30
 
 
31
 
 
32
class TestAnnotate(TestCaseWithTransport):
 
33
 
 
34
    def setUp(self):
 
35
        super(TestAnnotate, self).setUp()
 
36
        wt = self.make_branch_and_tree('.')
 
37
        b = wt.branch
 
38
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
 
39
                                  ('nomail.txt', 'nomail\n')])
 
40
        wt.add(['hello.txt'])
 
41
        self.revision_id_1 = wt.commit('add hello',
 
42
                              committer='test@user', timestamp=1165960000.00)
 
43
        wt.add(['nomail.txt'])
 
44
        self.revision_id_2 = wt.commit('add nomail',
 
45
                              committer='no mail', timestamp=1165970000.00)
 
46
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
47
                                                'your helicopter\n')])
 
48
        self.revision_id_3 = wt.commit('mod hello',
 
49
                              committer='user@test', timestamp=1166040000.00)
 
50
        self.build_tree_contents([('hello.txt', 'my helicopter\n'
 
51
                                                'your helicopter\n'
 
52
                                                'all of\n'
 
53
                                                'our helicopters\n'
 
54
                                  )])
 
55
        self.revision_id_4 = wt.commit('mod hello',
 
56
                              committer='user@test', timestamp=1166050000.00)
 
57
 
 
58
    def test_help_annotate(self):
 
59
        """Annotate command exists"""
 
60
        out, err = self.run_bzr('--no-plugins', 'annotate', '--help')
 
61
 
 
62
    def test_annotate_cmd(self):
 
63
        out, err = self.run_bzr('annotate', 'hello.txt')
 
64
        self.assertEqual('', err)
 
65
        self.assertEqualDiff('''\
 
66
1   test@us | my helicopter
 
67
3   user@te | your helicopter
 
68
4   user@te | all of
 
69
            | our helicopters
 
70
''', out)
 
71
 
 
72
    def test_annotate_cmd_full(self):
 
73
        out, err = self.run_bzr('annotate', 'hello.txt', '--all')
 
74
        self.assertEqual('', err)
 
75
        self.assertEqualDiff('''\
 
76
1   test@us | my helicopter
 
77
3   user@te | your helicopter
 
78
4   user@te | all of
 
79
4   user@te | our helicopters
 
80
''', out)
 
81
 
 
82
    def test_annotate_cmd_long(self):
 
83
        out, err = self.run_bzr('annotate', 'hello.txt', '--long')
 
84
        self.assertEqual('', err)
 
85
        self.assertEqualDiff('''\
 
86
1   test@user 20061212 | my helicopter
 
87
3   user@test 20061213 | your helicopter
 
88
4   user@test 20061213 | all of
 
89
                       | our helicopters
 
90
''', out)
 
91
 
 
92
    def test_annotate_cmd_show_ids(self):
 
93
        out, err = self.run_bzr('annotate', 'hello.txt', '--show-ids')
 
94
        max_len = max([len(self.revision_id_1),
 
95
                       len(self.revision_id_3),
 
96
                       len(self.revision_id_4)])
 
97
        self.assertEqual('', err)
 
98
        self.assertEqualDiff('''\
 
99
%*s | my helicopter
 
100
%*s | your helicopter
 
101
%*s | all of
 
102
%*s | our helicopters
 
103
''' % (max_len, self.revision_id_1,
 
104
       max_len, self.revision_id_3,
 
105
       max_len, self.revision_id_4,
 
106
       max_len, '',
 
107
      )
 
108
, out)
 
109
 
 
110
    def test_no_mail(self):
 
111
        out, err = self.run_bzr('annotate', 'nomail.txt')
 
112
        self.assertEqual('', err)
 
113
        self.assertEqualDiff('''\
 
114
2   no mail | nomail
 
115
''', out)
 
116
 
 
117
    def test_annotate_cmd_revision(self):
 
118
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1')
 
119
        self.assertEqual('', err)
 
120
        self.assertEqualDiff('''\
 
121
1   test@us | my helicopter
 
122
''', out)
 
123
 
 
124
    def test_annotate_cmd_revision3(self):
 
125
        out, err = self.run_bzr('annotate', 'hello.txt', '-r3')
 
126
        self.assertEqual('', err)
 
127
        self.assertEqualDiff('''\
 
128
1   test@us | my helicopter
 
129
3   user@te | your helicopter
 
130
''', out)
 
131
 
 
132
    def test_annotate_cmd_unknown_revision(self):
 
133
        out, err = self.run_bzr('annotate', 'hello.txt', '-r', '10',
 
134
                                retcode=3)
 
135
        self.assertEqual('', out)
 
136
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
 
137
 
 
138
    def test_annotate_cmd_two_revisions(self):
 
139
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1..2',
 
140
                                retcode=3)
 
141
        self.assertEqual('', out)
 
142
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
 
143
                         ' exactly 1 argument\n',
 
144
                         err)
 
145
 
 
146
    def test_annotate_empty_file(self):
 
147
        tree = self.make_branch_and_tree('tree')
 
148
        self.build_tree_contents([('tree/empty', '')])
 
149
        tree.add('empty')
 
150
        tree.commit('add empty file')
 
151
 
 
152
        os.chdir('tree')
 
153
        out, err = self.run_bzr('annotate', 'empty')
 
154
        self.assertEqual('', out)