| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
from breezy.tests import TestCase, TestCaseWithTransport |
| 20 |
from breezy import errors |
| 21 |
from breezy.transport import memory |
| 22 |
|
| 23 |
from PyQt5 import QtCore |
| 24 |
|
| 25 |
from breezy.plugins.qbrz.lib import tests as qtests |
| 26 |
from breezy.plugins.qbrz.lib.log import LogWindow |
| 27 |
|
| 28 |
|
| 29 |
class TestLogSmokeTests(qtests.QTestCase): |
| 30 |
|
| 31 |
def test_show_log_blank_branch(self): |
| 32 |
tree1 = self.make_branch_and_tree('tree1') |
| 33 |
|
| 34 |
win = LogWindow(['tree1'], None) |
| 35 |
self.addCleanup(win.close) |
| 36 |
win.show() |
| 37 |
QtCore.QCoreApplication.processEvents() |
| 38 |
QtCore.QCoreApplication.processEvents() |
| 39 |
|
| 40 |
def test_show_log_simple_commit(self): |
| 41 |
wt = self.make_branch_and_tree('.') |
| 42 |
wt.commit('empty commit') |
| 43 |
self.build_tree(['hello']) |
| 44 |
wt.add('hello') |
| 45 |
wt.commit('add one file', committer='\u013d\xf3r\xe9m \xcdp\u0161\xfam <[email protected]>') |
| 46 |
|
| 47 |
win = LogWindow(['.'], None) |
| 48 |
self.addCleanup(win.close) |
| 49 |
win.show() |
| 50 |
QtCore.QCoreApplication.processEvents() |
| 51 |
QtCore.QCoreApplication.processEvents() |
| 52 |
|
| 53 |
|
| 54 |
class TestLogGetBranchesAndFileIds(qtests.QTestCase): |
| 55 |
|
| 56 |
def test_with_branch(self): |
| 57 |
tree = self.make_branch_and_tree("branch") |
| 58 |
win = LogWindow(branch=tree.branch, tree=tree) |
| 59 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 60 |
self.assertLength(1, branches) |
| 61 |
bi = branches[0] |
| 62 |
|
| 63 |
|
| 64 |
self.assertEqual(tree, bi.tree) |
| 65 |
self.assertEqual(tree.branch, bi.branch) |
| 66 |
|
| 67 |
|
| 68 |
self.assertEqual(branches[0], primary_bi) |
| 69 |
self.assertEqual(None, file_ids) |
| 70 |
|
| 71 |
def test_open_branch_without_passing_tree(self): |
| 72 |
tree = self.make_branch_and_tree("branch") |
| 73 |
win = LogWindow(branch=tree.branch) |
| 74 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 75 |
self.assertEqual(tree.basedir, branches[0].tree.basedir) |
| 76 |
|
| 77 |
def test_open_branch_without_tree(self): |
| 78 |
branch = self.make_branch("branch") |
| 79 |
win = LogWindow(branch=branch) |
| 80 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 81 |
bi = branches[0] |
| 82 |
self.assertEqual(None, bi.tree) |
| 83 |
self.assertEqual(branch, bi.branch) |
| 84 |
|
| 85 |
def make_branch_and_tree_with_files_and_dir(self): |
| 86 |
tree = self.make_branch_and_tree("branch") |
| 87 |
self.build_tree(['branch/file1', 'branch/dir/', 'branch/file3']) |
| 88 |
tree.add('file1', ids=b'file1-id') |
| 89 |
tree.add('dir', ids=b'dir-id') |
| 90 |
tree.add('file3', ids=b'file3-id') |
| 91 |
tree.commit(message='add files') |
| 92 |
return tree |
| 93 |
|
| 94 |
def check_open_branch_files(self, tree, branch): |
| 95 |
win = LogWindow(branch=branch, specific_file_ids = ['file1-id']) |
| 96 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 97 |
|
| 98 |
self.assertLength(1, branches) |
| 99 |
bi = branches[0] |
| 100 |
self.assertEqual(branch, bi.branch) |
| 101 |
|
| 102 |
self.assertEqual(['file1-id'], file_ids) |
| 103 |
|
| 104 |
def test_open_branch_files(self): |
| 105 |
tree = self.make_branch_and_tree_with_files_and_dir() |
| 106 |
self.check_open_branch_files(tree, tree.branch) |
| 107 |
|
| 108 |
def test_open_branch_files_with_tree(self): |
| 109 |
tree = self.make_branch_and_tree_with_files_and_dir() |
| 110 |
branch = tree.branch |
| 111 |
tree.controldir.destroy_workingtree() |
| 112 |
self.check_open_branch_files(None, branch) |
| 113 |
|
| 114 |
def branches_to_base(self, branches): |
| 115 |
for bi in branches: |
| 116 |
if bi.tree is None: |
| 117 |
yield (None, bi.branch.base, bi.index) |
| 118 |
else: |
| 119 |
yield (bi.tree.basedir, bi.branch.base, bi.index) |
| 120 |
|
| 121 |
def test_open_locations_standalone_branches(self): |
| 122 |
branch1 = self.make_branch("branch1") |
| 123 |
tree2 = self.make_branch_and_tree("branch2") |
| 124 |
win = LogWindow(locations=["branch1", "branch2"]) |
| 125 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 126 |
self.assertEqual(set(((None, branch1.base, None), (tree2.basedir, tree2.branch.base, None) )), set(self.branches_to_base(branches))) |
| 127 |
|
| 128 |
def make_branch_in_shared_repo(self, relpath, format=None): |
| 129 |
"""Create a branch on the transport at relpath.""" |
| 130 |
made_control = self.make_controldir(relpath, format=format) |
| 131 |
return made_control.create_branch() |
| 132 |
|
| 133 |
def test_open_locations_shared_repo(self): |
| 134 |
self.make_branch = self.make_branch_in_shared_repo |
| 135 |
repo = self.make_repository("repo", shared=True) |
| 136 |
branch1 = self.make_branch("repo/branch1") |
| 137 |
tree2 = self.make_branch_and_tree("repo/branch2") |
| 138 |
win = LogWindow(locations=["repo"]) |
| 139 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 140 |
self.assertEqual(set(((None, branch1.base, None), (tree2.basedir, tree2.branch.base, None))), set(self.branches_to_base(branches))) |
| 141 |
|
| 142 |
def test_open_locations_in_shared_reporaise_not_a_branch(self): |
| 143 |
repo = self.make_repository("repo", shared=True) |
| 144 |
win = LogWindow(locations=["repo"]) |
| 145 |
self.assertRaises(errors.NotBranchError, win.get_branches_and_file_ids) |
| 146 |
|
| 147 |
def test_open_locations_raise_not_a_branch(self): |
| 148 |
self.vfs_transport_factory = memory.MemoryServer |
| 149 |
win = LogWindow(locations=[self.get_url("non_existant_branch")]) |
| 150 |
self.assertRaises(errors.NotBranchError, win.get_branches_and_file_ids) |
| 151 |
|
| 152 |
def check_open_location_files(self): |
| 153 |
win = LogWindow(locations=["branch/file1", 'branch/dir']) |
| 154 |
branches, primary_bi, file_ids = win.get_branches_and_file_ids() |
| 155 |
self.assertEqual([b'file1-id', b'dir-id'], file_ids) |
| 156 |
|
| 157 |
def test_open_locations_files(self): |
| 158 |
tree = self.make_branch_and_tree_with_files_and_dir() |
| 159 |
self.check_open_location_files() |
| 160 |
|
| 161 |
def test_open_locations_files_without_tree(self): |
| 162 |
tree = self.make_branch_and_tree_with_files_and_dir() |
| 163 |
branch = tree.branch |
| 164 |
tree.controldir.destroy_workingtree() |
| 165 |
self.check_open_location_files() |
| 166 |
|
| 167 |
def test_open_locations_raise_not_versioned(self): |
| 168 |
branch = self.make_branch("branch") |
| 169 |
win = LogWindow(locations=["file-that-does-not-exist"]) |
| 170 |
self.assertRaises(errors.BzrCommandError, win.get_branches_and_file_ids) |
| 171 |
|
| 172 |
def test_branch_label_location(self): |
| 173 |
branch = self.make_branch("branch") |
| 174 |
win = LogWindow() |
| 175 |
self.assertEqual('path', win.branch_label('path', branch)) |
| 176 |
|
| 177 |
def test_branch_label_no_location(self): |
| 178 |
branch = self.make_branch("branch") |
| 179 |
win = LogWindow() |
| 180 |
|
| 181 |
self.assertEqual('branch', win.branch_label(None, branch)) |
| 182 |
|
| 183 |
def test_branch_label_path_location(self): |
| 184 |
branch = self.make_branch("branch") |
| 185 |
win = LogWindow() |
| 186 |
|
| 187 |
self.assertEqual('path-to-branch', win.branch_label('path-to-branch', branch)) |
| 188 |
|
| 189 |
def test_branch_label_alias_directory(self): |
| 190 |
branch = self.make_branch("branch") |
| 191 |
win = LogWindow() |
| 192 |
|
| 193 |
self.assertEqual(':parent (branch)', win.branch_label(':parent', branch)) |
| 194 |
|
| 195 |
def test_branch_label_no_info_locations(self): |
| 196 |
branch = self.make_branch("branch") |
| 197 |
win = LogWindow() |
| 198 |
|
| 199 |
self.assertEqual('. (branch)', win.branch_label('.', branch)) |
| 200 |
self.assertEqual('../ (branch)', win.branch_label('../', branch)) |
| 201 |
|
| 202 |
def test_branch_label_explict_nick(self): |
| 203 |
branch = self.make_branch("branch") |
| 204 |
branch.nick = "nick" |
| 205 |
win = LogWindow() |
| 206 |
self.assertEqual('path (nick)', win.branch_label('path', branch)) |
| 207 |
|
| 208 |
def test_branch_label_repository(self): |
| 209 |
repo = self.make_repository("repo", shared=True) |
| 210 |
branch = self.make_branch("repo/branch") |
| 211 |
win = LogWindow() |
| 212 |
self.assertEqual('./branch', win.branch_label(None, branch, '.', repo)) |