~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2013-05-19 14:29:37 UTC
  • mfrom: (6437.63.9 2.5)
  • mto: (6437.63.10 2.5)
  • mto: This revision was merged to the branch mainline in revision 6575.
  • Revision ID: john@arbash-meinel.com-20130519142937-21ykz2n2y2f22za9
Merge in the actual 2.5 branch. It seems I failed before

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
 
 
18
from bzrlib import (
 
19
    branch as _mod_branch,
 
20
    bzrdir,
 
21
    )
 
22
from bzrlib.tests import TestCaseWithTransport
 
23
 
 
24
 
 
25
class TestReference(TestCaseWithTransport):
 
26
 
 
27
    def get_default_format(self):
 
28
        format = bzrdir.format_registry.make_bzrdir('1.9')
 
29
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
 
30
        return format
 
31
 
 
32
    def test_no_args_lists(self):
 
33
        branch = self.make_branch('branch')
 
34
        branch.set_reference_info('file-id', 'path', 'http://example.org')
 
35
        branch.set_reference_info('file-id2', 'lath', 'http://example.org/2')
 
36
        out, err = self.run_bzr('reference', working_dir='branch')
 
37
        lines = out.splitlines()
 
38
        self.assertEqual('lath http://example.org/2', lines[0])
 
39
        self.assertEqual('path http://example.org', lines[1])
 
40
 
 
41
    def make_tree_with_reference(self):
 
42
        tree = self.make_branch_and_tree('tree')
 
43
        self.build_tree(['tree/newpath'])
 
44
        tree.add('newpath', 'file-id')
 
45
        tree.branch.set_reference_info('file-id', 'path', 'http://example.org')
 
46
        tree.branch.set_reference_info('file-id2', 'lath',
 
47
                                       'http://example.org/2')
 
48
        return tree
 
49
 
 
50
    def test_uses_working_tree_location(self):
 
51
        tree = self.make_tree_with_reference()
 
52
        out, err = self.run_bzr('reference', working_dir='tree')
 
53
        self.assertContainsRe(out, 'newpath http://example.org\n')
 
54
 
 
55
    def test_uses_basis_tree_location(self):
 
56
        tree = self.make_tree_with_reference()
 
57
        tree.commit('add newpath')
 
58
        tree.bzrdir.destroy_workingtree()
 
59
        out, err = self.run_bzr('reference', working_dir='tree')
 
60
        self.assertContainsRe(out, 'newpath http://example.org\n')
 
61
 
 
62
    def test_one_arg_displays(self):
 
63
        tree = self.make_tree_with_reference()
 
64
        out, err = self.run_bzr('reference newpath', working_dir='tree')
 
65
        self.assertEqual('newpath http://example.org\n', out)
 
66
 
 
67
    def test_one_arg_uses_containing_tree(self):
 
68
        tree = self.make_tree_with_reference()
 
69
        out, err = self.run_bzr('reference tree/newpath')
 
70
        self.assertEqual('newpath http://example.org\n', out)
 
71
 
 
72
    def test_two_args_sets(self):
 
73
        tree = self.make_branch_and_tree('tree')
 
74
        self.build_tree(['tree/file'])
 
75
        tree.add('file', 'file-id')
 
76
        out, err = self.run_bzr('reference tree/file http://example.org')
 
77
        path, location = tree.branch.get_reference_info('file-id')
 
78
        self.assertEqual('http://example.org', location)
 
79
        self.assertEqual('file', path)
 
80
        self.assertEqual('', out)
 
81
        self.assertEqual('', err)
 
82
 
 
83
    def test_missing_file(self):
 
84
        tree = self.make_branch_and_tree('tree')
 
85
        out, err = self.run_bzr('reference file http://example.org',
 
86
                                working_dir='tree', retcode=3)
 
87
        self.assertEqual('bzr: ERROR: file is not versioned.\n', err)