~bzr-pqm/bzr/bzr.dev

4273.1.19 by Aaron Bentley
Implement reference command
1
# Copyright (C) 2009 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
4273.1.21 by Aaron Bentley
Update from review
17
4273.1.19 by Aaron Bentley
Implement reference command
18
from bzrlib import (
19
    branch as _mod_branch,
20
    bzrdir,
21
    )
22
from bzrlib.tests import TestCaseWithTransport
23
4273.1.21 by Aaron Bentley
Update from review
24
4273.1.19 by Aaron Bentley
Implement reference command
25
class TestReference(TestCaseWithTransport):
26
27
    def make_branch(self, location, format=None):
28
        if format is None:
29
            format = bzrdir.format_registry.make_bzrdir('1.9')
30
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
31
        return TestCaseWithTransport.make_branch(self, location, format=format)
32
33
    def test_no_args_lists(self):
34
        branch = self.make_branch('branch')
35
        branch.set_reference_info('file-id', 'path', 'http://example.org')
36
        branch.set_reference_info('file-id2', 'lath', 'http://example.org/2')
37
        out, err = self.run_bzr('reference', working_dir='branch')
38
        lines = out.splitlines()
39
        self.assertEqual('lath http://example.org/2', lines[0])
40
        self.assertEqual('path http://example.org', lines[1])
41
42
    def make_tree_with_reference(self):
43
        tree = self.make_branch_and_tree('tree')
44
        self.build_tree(['tree/newpath'])
45
        tree.add('newpath', 'file-id')
46
        tree.branch.set_reference_info('file-id', 'path', 'http://example.org')
47
        tree.branch.set_reference_info('file-id2', 'lath',
48
                                       'http://example.org/2')
49
        return tree
50
51
    def test_uses_working_tree_location(self):
52
        tree = self.make_tree_with_reference()
53
        out, err = self.run_bzr('reference', working_dir='tree')
54
        self.assertContainsRe(out, 'newpath http://example.org\n')
55
56
    def test_uses_basis_tree_location(self):
57
        tree = self.make_tree_with_reference()
58
        tree.commit('add newpath')
59
        tree.bzrdir.destroy_workingtree()
60
        out, err = self.run_bzr('reference', working_dir='tree')
61
        self.assertContainsRe(out, 'newpath http://example.org\n')
62
63
    def test_one_arg_displays(self):
64
        tree = self.make_tree_with_reference()
65
        out, err = self.run_bzr('reference newpath', working_dir='tree')
66
        self.assertEqual('newpath http://example.org\n', out)
67
68
    def test_one_arg_uses_containing_tree(self):
69
        tree = self.make_tree_with_reference()
70
        out, err = self.run_bzr('reference tree/newpath')
71
        self.assertEqual('newpath http://example.org\n', out)
72
73
    def test_two_args_sets(self):
74
        tree = self.make_branch_and_tree('tree')
75
        self.build_tree(['tree/file'])
76
        tree.add('file', 'file-id')
77
        out, err = self.run_bzr('reference tree/file http://example.org')
78
        path, location = tree.branch.get_reference_info('file-id')
79
        self.assertEqual('http://example.org', location)
80
        self.assertEqual('file', path)
81
        self.assertEqual('', out)
82
        self.assertEqual('', err)
83
84
    def test_missing_file(self):
85
        tree = self.make_branch_and_tree('tree')
86
        out, err = self.run_bzr('reference file http://example.org',
87
                                working_dir='tree', retcode=3)
88
        self.assertEqual('bzr: ERROR: file is not versioned.\n', err)