Debian Codegraph @

lib/tests/test_tree_branch.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 #
5 # Contributor:
6 # Alexander Belchenko, 2009
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22 """Tests for TreeBranch wrapper object."""
23
24 from breezy import (
25 errors,
26 osutils,
27 tests,
28 )
29 from breezy.transport import memory
30 from breezy.plugins.qbrz.lib import tree_branch
31 from breezy.plugins.qbrz.lib.tests import mock
32
33
34 class TestTreeBranch(tests.TestCaseWithTransport):
35
36 def test_errors_no_ui_mode_no_branch(self):
37 self.vfs_transport_factory = memory.MemoryServer
38 mf = mock.MockFunction()
39 self.assertRaises(errors.NotBranchError,
40 tree_branch.TreeBranch.open_containing,
41 self.get_url('non/existent/path'),
42 ui_mode=False, _critical_dialog=mf)
43 self.assertEqual(0, mf.count)
44
45 def test_errors_no_ui_mode_no_tree(self):
46 mf = mock.MockFunction()
47 self.make_branch('a')
48 self.assertRaises(errors.NoWorkingTree,
49 tree_branch.TreeBranch.open_containing, 'a', require_tree=True,
50 ui_mode=False, _critical_dialog=mf)
51 self.assertEqual(0, mf.count)
52
53 def test_errors_ui_mode_no_branch(self):
54 self.vfs_transport_factory = memory.MemoryServer
55 mf = mock.MockFunction()
56 tb = tree_branch.TreeBranch.open_containing(
57 self.get_url('non/existent/path'),
58 ui_mode=True, _critical_dialog=mf)
59 self.assertEqual(None, tb)
60 self.assertEqual(1, mf.count)
61
62
63 def test_errors_ui_mode_no_tree(self):
64 mf = mock.MockFunction()
65 self.make_branch('a')
66 mf = mock.MockFunction()
67 tb = tree_branch.TreeBranch.open_containing('a',
68 require_tree=True, ui_mode=True, _critical_dialog=mf)
69 self.assertEqual(None, tb)
70 self.assertEqual(1, mf.count)
71
72 def test_open(self):
73 self.make_branch('a')
74 mf = mock.MockFunction()
75 tb = tree_branch.TreeBranch.open_containing('a',
76 require_tree=False, ui_mode=False, _critical_dialog=mf)
77 self.assertNotEqual(None, tb)
78 self.assertEqual('a', tb.location)
79 self.assertNotEqual(None, tb.branch)
80 self.assertEqual(None, tb.tree)
81 self.assertEqual('', tb.relpath)
82 self.assertEqual(0, mf.count)
83 #
84 self.make_branch_and_tree('b')
85 tb = tree_branch.TreeBranch.open_containing('b',
86 require_tree=True, ui_mode=False, _critical_dialog=mf)
87 self.assertNotEqual(None, tb)
88 self.assertEqual('b', tb.location)
89 self.assertNotEqual(None, tb.branch)
90 self.assertNotEqual(None, tb.tree)
91 self.assertEqual('', tb.relpath)
92 self.assertEqual(0, mf.count)
93 #
94 self.build_tree(['b/dir/'])
95 tb = tree_branch.TreeBranch.open_containing('b/dir',
96 require_tree=True, ui_mode=False, _critical_dialog=mf)
97 self.assertNotEqual(None, tb)
98 self.assertEqual('b/dir', tb.location)
99 self.assertNotEqual(None, tb.branch)
100 self.assertNotEqual(None, tb.tree)
101 self.assertEqual('dir', tb.relpath)
102 self.assertEqual(0, mf.count)
103
104 def test_get_type(self):
105 self.make_branch('a')
106 mf = mock.MockFunction()
107 tb = tree_branch.TreeBranch.open_containing('a',
108 require_tree=False, ui_mode=False, _critical_dialog=mf)
109 self.assertEqual('branch', tb.get_type())
110 #
111 self.make_branch_and_tree('master')
112 tb = tree_branch.TreeBranch.open_containing('master',
113 require_tree=True, ui_mode=False, _critical_dialog=mf)
114 self.assertEqual('tree', tb.get_type())
115 self.run_bzr('checkout master slave')
116 tb = tree_branch.TreeBranch.open_containing('slave',
117 require_tree=True, ui_mode=False, _critical_dialog=mf)
118 self.assertEqual('bound', tb.get_type())
119 self.run_bzr('checkout --lightweight master light')
120 tb = tree_branch.TreeBranch.open_containing('light',
121 require_tree=True, ui_mode=False, _critical_dialog=mf)
122 self.assertEqual('light-checkout', tb.get_type())
123
124 def test_get_root(self):
125 mf = mock.MockFunction()
126 self.make_branch('a')
127 tb = tree_branch.TreeBranch.open_containing('a',
128 require_tree=False, ui_mode=False, _critical_dialog=mf)
129 self.assertEqual(osutils.abspath('a')+'/', tb.get_root())
130 #
131 self.make_branch_and_tree('b')
132 root = osutils.abspath('b')
133 tb = tree_branch.TreeBranch.open_containing('b',
134 require_tree=True, ui_mode=False, _critical_dialog=mf)
135 self.assertEqual(root, tb.get_root())
136 #
137 self.build_tree(['b/dir/'])
138 tb = tree_branch.TreeBranch.open_containing('b/dir',
139 require_tree=True, ui_mode=False, _critical_dialog=mf)
140 self.assertEqual(root, tb.get_root())
141 #
142 self.run_bzr('checkout --lightweight b c')
143 tb = tree_branch.TreeBranch.open_containing('c',
144 require_tree=True, ui_mode=False, _critical_dialog=mf)
145 self.assertEqual(osutils.abspath('c'), tb.get_root())