~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_annotate.py

  • Committer: Robert Collins
  • Date: 2006-03-01 03:26:23 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060301032623-9d3c073e102f2239
Move WeaveStore down into bzrlib.store.versioned.weave.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
 
#
 
3
 
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
6
6
# the Free Software Foundation; either version 2 of the License, or
7
7
# (at your option) any later version.
8
 
#
 
8
 
9
9
# This program is distributed in the hope that it will be useful,
10
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
12
# GNU General Public License for more details.
13
 
#
 
13
 
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
24
"""
25
25
 
26
26
 
 
27
from cStringIO import StringIO
 
28
import os
 
29
import shutil
 
30
import sys
27
31
import os
28
32
 
 
33
from bzrlib.branch import Branch
 
34
from bzrlib.errors import BzrCommandError
 
35
from bzrlib.osutils import has_symlinks
29
36
from bzrlib.tests import TestCaseWithTransport
 
37
from bzrlib.annotate import annotate_file
30
38
 
31
39
 
32
40
class TestAnnotate(TestCaseWithTransport):
38
46
        self.build_tree_contents([('hello.txt', 'my helicopter\n'),
39
47
                                  ('nomail.txt', 'nomail\n')])
40
48
        wt.add(['hello.txt'])
41
 
        self.revision_id_1 = wt.commit('add hello',
42
 
                              committer='test@user',
43
 
                              timestamp=1165960000.00, timezone=0)
 
49
        wt.commit('add hello', 
 
50
                                committer='test@user')
44
51
        wt.add(['nomail.txt'])
45
 
        self.revision_id_2 = wt.commit('add nomail',
46
 
                              committer='no mail',
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'
54
 
                                                'your helicopter\n'
55
 
                                                'all of\n'
56
 
                                                'our helicopters\n'
57
 
                                  )])
58
 
        self.revision_id_4 = wt.commit('mod hello',
59
 
                              committer='user@test',
60
 
                              timestamp=1166050000.00, timezone=0)
 
52
        wt.commit('add nomail', committer='no mail')
61
53
 
62
54
    def test_help_annotate(self):
63
55
        """Annotate command exists"""
64
 
        out, err = self.run_bzr('--no-plugins', 'annotate', '--help')
 
56
        out, err = self.run_bzr_captured(['--no-plugins', 'annotate', '--help'])
65
57
 
66
58
    def test_annotate_cmd(self):
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
72
 
4   user@te | all of
73
 
            | our helicopters
74
 
''', out)
75
 
 
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
82
 
4   user@te | all of
83
 
4   user@te | our helicopters
84
 
''', out)
85
 
 
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
93
 
                       | our helicopters
94
 
''', out)
95
 
 
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('''\
103
 
%*s | my helicopter
104
 
%*s | your helicopter
105
 
%*s | all of
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,
110
 
       max_len, '',
111
 
      )
112
 
, out)
 
59
        out, err = self.run_bzr_captured(['annotate', 'hello.txt'])
 
60
        self.assertEquals(err, '')
 
61
        self.assertEqualDiff(out, '''\
 
62
    1 test@us | my helicopter
 
63
''')
113
64
 
114
65
    def test_no_mail(self):
115
 
        out, err = self.run_bzr('annotate', 'nomail.txt')
116
 
        self.assertEqual('', err)
117
 
        self.assertEqualDiff('''\
118
 
2   no mail | nomail
119
 
''', out)
120
 
 
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
126
 
''', out)
127
 
 
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
134
 
''', out)
135
 
 
136
 
    def test_annotate_cmd_unknown_revision(self):
137
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r', '10',
138
 
                                retcode=3)
139
 
        self.assertEqual('', out)
140
 
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
141
 
 
142
 
    def test_annotate_cmd_two_revisions(self):
143
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1..2',
144
 
                                retcode=3)
145
 
        self.assertEqual('', out)
146
 
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
147
 
                         ' exactly 1 argument\n',
148
 
                         err)
149
 
 
150
 
    def test_annotate_empty_file(self):
151
 
        tree = self.make_branch_and_tree('tree')
152
 
        self.build_tree_contents([('tree/empty', '')])
153
 
        tree.add('empty')
154
 
        tree.commit('add empty file')
155
 
 
156
 
        os.chdir('tree')
157
 
        out, err = self.run_bzr('annotate', 'empty')
158
 
        self.assertEqual('', out)
 
66
        out, err = self.run_bzr_captured(['annotate', 'nomail.txt'])
 
67
        self.assertEquals(err, '')
 
68
        self.assertEqualDiff(out, '''\
 
69
    2 no mail | nomail
 
70
''')