/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2012, 2016 Canonical Ltd
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
17
from breezy import (
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
18
    errors,
7122.4.1 by Jelmer Vernooij
Some refactoring; check for required functionality rather than specific implementation (InventoryTree).
19
    tests,
20
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.tests.per_tree import TestCaseWithTree
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
22
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
23
7122.4.1 by Jelmer Vernooij
Some refactoring; check for required functionality rather than specific implementation (InventoryTree).
24
class Path2IdTests(TestCaseWithTree):
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
25
26
    def setUp(self):
7122.4.1 by Jelmer Vernooij
Some refactoring; check for required functionality rather than specific implementation (InventoryTree).
27
        super(Path2IdTests, self).setUp()
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
28
        work_a = self.make_branch_and_tree('wta')
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
29
        if not work_a.supports_setting_file_ids():
6821.2.2 by Jelmer Vernooij
More foreign fixes.
30
            self.skipTest("working tree does not support setting file ids")
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
31
        self.build_tree(['wta/bla', 'wta/dir/', 'wta/dir/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
32
        work_a.add(['bla', 'dir', 'dir/file'], [b'bla-id', b'dir-id', b'file-id'])
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
33
        work_a.commit('add files')
34
        self.tree_a = self.workingtree_to_test_tree(work_a)
35
36
    def test_path2id(self):
6855.4.1 by Jelmer Vernooij
Yet more bees.
37
        self.assertEqual(b'bla-id', self.tree_a.path2id('bla'))
38
        self.assertEqual(b'dir-id', self.tree_a.path2id('dir'))
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
39
        self.assertIs(None, self.tree_a.path2id('idontexist'))
40
41
    def test_path2id_list(self):
6855.4.1 by Jelmer Vernooij
Yet more bees.
42
        self.assertEqual(b'bla-id', self.tree_a.path2id(['bla']))
43
        self.assertEqual(b'dir-id', self.tree_a.path2id(['dir']))
44
        self.assertEqual(b'file-id', self.tree_a.path2id(['dir', 'file']))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
45
        self.assertEqual(self.tree_a.get_root_id(),
46
                         self.tree_a.path2id([]))
6478.2.1 by Jelmer Vernooij
Accept path element list as argument to Tree.path2id.
47
        self.assertIs(None, self.tree_a.path2id(['idontexist']))
48
        self.assertIs(None, self.tree_a.path2id(['dir', 'idontexist']))
49
50
    def test_id2path(self):
51
        self.addCleanup(self.tree_a.lock_read().unlock)
6855.4.1 by Jelmer Vernooij
Yet more bees.
52
        self.assertEqual('bla', self.tree_a.id2path(b'bla-id'))
53
        self.assertEqual('dir', self.tree_a.id2path(b'dir-id'))
54
        self.assertEqual('dir/file', self.tree_a.id2path(b'file-id'))
55
        self.assertRaises(errors.NoSuchId, self.tree_a.id2path, b'nonexistant')
7122.4.1 by Jelmer Vernooij
Some refactoring; check for required functionality rather than specific implementation (InventoryTree).
56
57
class Path2IdsTests(TestCaseWithTree):
58
59
    def test_paths2ids_recursive(self):
60
        work_tree = self.make_branch_and_tree('tree')
61
        self.build_tree(['tree/dir/', 'tree/dir/file'])
62
        work_tree.add(['dir', 'dir/file'])
63
        if not work_tree.supports_setting_file_ids():
64
            raise tests.TestNotApplicable(
65
                "test not applicable on non-inventory tests")
66
        tree = self._convert_tree(work_tree)
67
        tree.lock_read()
68
        self.addCleanup(tree.unlock)
69
        self.assertEqual({tree.path2id('dir'), tree.path2id('dir/file')},
70
                         tree.paths2ids(['dir']))
71
72
    def test_paths2ids_forget_old(self):
73
        work_tree = self.make_branch_and_tree('tree')
74
        self.build_tree(['tree/file'])
75
        work_tree.add('file')
76
        work_tree.commit('commit old state')
77
        work_tree.remove('file')
78
        if not work_tree.supports_setting_file_ids():
79
            raise tests.TestNotApplicable(
80
                "test not applicable on non-inventory tests")
81
        tree = self._convert_tree(work_tree)
82
        tree.lock_read()
83
        self.addCleanup(tree.unlock)
84
        self.assertEqual(set([]), tree.paths2ids(['file'],
85
                         require_versioned=False))