~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2009-06-18 18:26:10 UTC
  • mto: This revision was merged to the branch mainline in revision 4466.
  • Revision ID: v.ladeuil+lp@free.fr-20090618182610-o59r8149nlzb3b68
Simplify gdfo computing by finding tails when at graph build time.

* bzrlib/_known_graph_pyx.pyx:
(KnownGraph._get_or_create_node): We need to know if the ndoe as
created.
(KnownGraph._initialize_nodes): Calulate tails ahead of time to
intialize gdfo computing.
(KnownGraph._find_gdfo): Use tails directly.

* bzrlib/_known_graph_py.py:
(KnownGraph._initialize_nodes): Calulate tails ahead of time to
intialize gdfo computing.
(KnownGraph._find_gdfo): Use tails directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
 
19
19
"""Black-box tests for bzr.
20
20
 
21
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 
 
22
command-line interface. This doesn't actually run a new interpreter but
23
23
rather starts again from the run_bzr function.
24
24
"""
25
25
 
26
26
 
27
27
import os
28
28
 
 
29
from bzrlib.branch import Branch
 
30
from bzrlib.config import extract_email_address
29
31
from bzrlib.tests import TestCaseWithTransport
30
32
 
31
33
 
61
63
 
62
64
    def test_help_annotate(self):
63
65
        """Annotate command exists"""
64
 
        out, err = self.run_bzr('--no-plugins', 'annotate', '--help')
 
66
        out, err = self.run_bzr('--no-plugins annotate --help')
65
67
 
66
68
    def test_annotate_cmd(self):
67
 
        out, err = self.run_bzr('annotate', 'hello.txt')
 
69
        out, err = self.run_bzr('annotate hello.txt')
68
70
        self.assertEqual('', err)
69
71
        self.assertEqualDiff('''\
70
72
1   test@us | my helicopter
74
76
''', out)
75
77
 
76
78
    def test_annotate_cmd_full(self):
77
 
        out, err = self.run_bzr('annotate', 'hello.txt', '--all')
 
79
        out, err = self.run_bzr('annotate hello.txt --all')
78
80
        self.assertEqual('', err)
79
81
        self.assertEqualDiff('''\
80
82
1   test@us | my helicopter
84
86
''', out)
85
87
 
86
88
    def test_annotate_cmd_long(self):
87
 
        out, err = self.run_bzr('annotate', 'hello.txt', '--long')
 
89
        out, err = self.run_bzr('annotate hello.txt --long')
88
90
        self.assertEqual('', err)
89
91
        self.assertEqualDiff('''\
90
92
1   test@user 20061212 | my helicopter
94
96
''', out)
95
97
 
96
98
    def test_annotate_cmd_show_ids(self):
97
 
        out, err = self.run_bzr('annotate', 'hello.txt', '--show-ids')
 
99
        out, err = self.run_bzr('annotate hello.txt --show-ids')
98
100
        max_len = max([len(self.revision_id_1),
99
101
                       len(self.revision_id_3),
100
102
                       len(self.revision_id_4)])
112
114
, out)
113
115
 
114
116
    def test_no_mail(self):
115
 
        out, err = self.run_bzr('annotate', 'nomail.txt')
 
117
        out, err = self.run_bzr('annotate nomail.txt')
116
118
        self.assertEqual('', err)
117
119
        self.assertEqualDiff('''\
118
120
2   no mail | nomail
119
121
''', out)
120
122
 
121
123
    def test_annotate_cmd_revision(self):
122
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1')
 
124
        out, err = self.run_bzr('annotate hello.txt -r1')
123
125
        self.assertEqual('', err)
124
126
        self.assertEqualDiff('''\
125
127
1   test@us | my helicopter
126
128
''', out)
127
129
 
128
130
    def test_annotate_cmd_revision3(self):
129
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r3')
 
131
        out, err = self.run_bzr('annotate hello.txt -r3')
130
132
        self.assertEqual('', err)
131
133
        self.assertEqualDiff('''\
132
134
1   test@us | my helicopter
134
136
''', out)
135
137
 
136
138
    def test_annotate_cmd_unknown_revision(self):
137
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r', '10',
 
139
        out, err = self.run_bzr('annotate hello.txt -r 10',
138
140
                                retcode=3)
139
141
        self.assertEqual('', out)
140
142
        self.assertContainsRe(err, 'Requested revision: \'10\' does not exist')
141
143
 
142
144
    def test_annotate_cmd_two_revisions(self):
143
 
        out, err = self.run_bzr('annotate', 'hello.txt', '-r1..2',
 
145
        out, err = self.run_bzr('annotate hello.txt -r1..2',
144
146
                                retcode=3)
145
147
        self.assertEqual('', out)
146
148
        self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
147
 
                         ' exactly 1 argument\n',
 
149
                         ' exactly one revision identifier\n',
148
150
                         err)
149
151
 
 
152
 
 
153
class TestSimpleAnnotate(TestCaseWithTransport):
 
154
    """Annotate tests with no complex setup."""
 
155
 
 
156
    def _setup_edited_file(self):
 
157
        """Create a tree with a locally edited file."""
 
158
        tree = self.make_branch_and_tree('.')
 
159
        self.build_tree_contents([('file', 'foo\ngam\n')])
 
160
        tree.add('file')
 
161
        tree.commit('add file', committer="test@host", rev_id="rev1")
 
162
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
163
        tree.branch.get_config().set_user_option('email', 'current@host2')
 
164
 
 
165
    def test_annotate_edited_file(self):
 
166
        tree = self._setup_edited_file()
 
167
        out, err = self.run_bzr('annotate file')
 
168
        self.assertEqual(
 
169
            '1   test@ho | foo\n'
 
170
            '2?  current | bar\n'
 
171
            '1   test@ho | gam\n',
 
172
            out)
 
173
 
 
174
    def test_annotate_edited_file_show_ids(self):
 
175
        tree = self._setup_edited_file()
 
176
        out, err = self.run_bzr('annotate file --show-ids')
 
177
        self.assertEqual(
 
178
            '    rev1 | foo\n'
 
179
            'current: | bar\n'
 
180
            '    rev1 | gam\n',
 
181
            out)
 
182
 
 
183
    def _create_merged_file(self):
 
184
        """Create a file with a pending merge and local edit."""
 
185
        tree = self.make_branch_and_tree('.')
 
186
        self.build_tree_contents([('file', 'foo\ngam\n')])
 
187
        tree.add('file')
 
188
        tree.commit('add file', rev_id="rev1", committer="test@host")
 
189
        # right side
 
190
        self.build_tree_contents([('file', 'foo\nbar\ngam\n')])
 
191
        tree.commit("right", rev_id="rev1.1.1", committer="test@host")
 
192
        tree.pull(tree.branch, True, "rev1")
 
193
        # left side
 
194
        self.build_tree_contents([('file', 'foo\nbaz\ngam\n')])
 
195
        tree.commit("left", rev_id="rev2", committer="test@host")
 
196
        # merge
 
197
        tree.merge_from_branch(tree.branch, "rev1.1.1")
 
198
        # edit the file to be 'resolved' and have a further local edit
 
199
        self.build_tree_contents([('file', 'local\nfoo\nbar\nbaz\ngam\n')])
 
200
 
 
201
    def test_annotated_edited_merged_file_revnos(self):
 
202
        self._create_merged_file()
 
203
        out, err = self.run_bzr('annotate file')
 
204
        email = extract_email_address(Branch.open('.').get_config().username())
 
205
        self.assertEqual(
 
206
            '3?    %-7s | local\n'
 
207
            '1     test@ho | foo\n'
 
208
            '1.1.1 test@ho | bar\n'
 
209
            '2     test@ho | baz\n'
 
210
            '1     test@ho | gam\n' % email[:7],
 
211
            out)
 
212
 
 
213
    def test_annotated_edited_merged_file_ids(self):
 
214
        self._create_merged_file()
 
215
        out, err = self.run_bzr('annotate file --show-ids')
 
216
        self.assertEqual(
 
217
            'current: | local\n'
 
218
            '    rev1 | foo\n'
 
219
            'rev1.1.1 | bar\n'
 
220
            '    rev2 | baz\n'
 
221
            '    rev1 | gam\n',
 
222
            out)
 
223
 
150
224
    def test_annotate_empty_file(self):
151
225
        tree = self.make_branch_and_tree('tree')
152
226
        self.build_tree_contents([('tree/empty', '')])
154
228
        tree.commit('add empty file')
155
229
 
156
230
        os.chdir('tree')
157
 
        out, err = self.run_bzr('annotate', 'empty')
 
231
        out, err = self.run_bzr('annotate empty')
 
232
        self.assertEqual('', out)
 
233
 
 
234
    def test_annotate_empty_file_show_ids(self):
 
235
        tree = self.make_branch_and_tree('tree')
 
236
        self.build_tree_contents([('tree/empty', '')])
 
237
        tree.add('empty')
 
238
        tree.commit('add empty file')
 
239
 
 
240
        os.chdir('tree')
 
241
        out, err = self.run_bzr(['annotate', '--show-ids', 'empty'])
 
242
        self.assertEqual('', out)
 
243
 
 
244
    def test_annotate_nonexistant_file(self):
 
245
        tree = self.make_branch_and_tree('tree')
 
246
        self.build_tree(['tree/file'])
 
247
        tree.add(['file'])
 
248
        tree.commit('add a file')
 
249
 
 
250
        os.chdir('tree')
 
251
        out, err = self.run_bzr("annotate doesnotexist", retcode=3)
 
252
        self.assertEqual('', out)
 
253
        self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
 
254
 
 
255
    def test_annotate_without_workingtree(self):
 
256
        tree = self.make_branch_and_tree('branch')
 
257
        self.build_tree_contents([('branch/empty', '')])
 
258
        tree.add('empty')
 
259
        tree.commit('add empty file')
 
260
        bzrdir = tree.branch.bzrdir
 
261
        bzrdir.destroy_workingtree()
 
262
        self.assertFalse(bzrdir.has_workingtree())
 
263
 
 
264
        os.chdir('branch')
 
265
        out, err = self.run_bzr('annotate empty')
158
266
        self.assertEqual('', out)