/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
1
# Copyright (C) 2006 Canonical Ltd
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
17
18
"""Tests for the TreeBuilder helper class."""
19
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
20
from breezy import tests
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.memorytree import MemoryTree
22
from breezy.tests import TestCaseWithTransport
6734.1.6 by Jelmer Vernooij
Move AlreadyBuilding/NotBuilding errors.
23
from breezy.treebuilder import (
24
    AlreadyBuilding,
25
    NotBuilding,
26
    TreeBuilder,
27
    )
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
28
29
30
class FakeTree(object):
31
    """A pretend tree to test the calls made by TreeBuilder."""
32
33
    def __init__(self):
34
        self._calls = []
35
1986.1.9 by Robert Collins
Update to the TreeBuilder tests.
36
    def lock_tree_write(self):
37
        self._calls.append("lock_tree_write")
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
38
39
    def unlock(self):
40
        self._calls.append("unlock")
41
42
43
class TestFakeTree(TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
44
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
45
    def testFakeTree(self):
46
        """Check that FakeTree works as required for the TreeBuilder tests."""
47
        tree = FakeTree()
48
        self.assertEqual([], tree._calls)
1986.1.9 by Robert Collins
Update to the TreeBuilder tests.
49
        tree.lock_tree_write()
50
        self.assertEqual(["lock_tree_write"], tree._calls)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
51
        tree.unlock()
1986.1.9 by Robert Collins
Update to the TreeBuilder tests.
52
        self.assertEqual(["lock_tree_write", "unlock"], tree._calls)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
53
54
2466.7.1 by Robert Collins
Tree builder tests do not need a working dir.
55
class TestTreeBuilderMemoryTree(tests.TestCaseWithMemoryTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
56
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
57
    def test_create(self):
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
58
        TreeBuilder()
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
59
60
    def test_start_tree_locks_write(self):
61
        builder = TreeBuilder()
62
        tree = FakeTree()
63
        builder.start_tree(tree)
1986.1.9 by Robert Collins
Update to the TreeBuilder tests.
64
        self.assertEqual(["lock_tree_write"], tree._calls)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
65
66
    def test_start_tree_when_started_fails(self):
67
        builder = TreeBuilder()
68
        tree = FakeTree()
69
        builder.start_tree(tree)
6734.1.6 by Jelmer Vernooij
Move AlreadyBuilding/NotBuilding errors.
70
        self.assertRaises(AlreadyBuilding, builder.start_tree, tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
71
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
72
    def test_finish_tree_not_started_errors(self):
73
        builder = TreeBuilder()
6734.1.6 by Jelmer Vernooij
Move AlreadyBuilding/NotBuilding errors.
74
        self.assertRaises(NotBuilding, builder.finish_tree)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
75
76
    def test_finish_tree_unlocks(self):
77
        builder = TreeBuilder()
78
        tree = FakeTree()
79
        builder.start_tree(tree)
80
        builder.finish_tree()
1986.1.9 by Robert Collins
Update to the TreeBuilder tests.
81
        self.assertEqual(["lock_tree_write", "unlock"], tree._calls)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
82
83
    def test_build_tree_not_started_errors(self):
84
        builder = TreeBuilder()
6734.1.6 by Jelmer Vernooij
Move AlreadyBuilding/NotBuilding errors.
85
        self.assertRaises(NotBuilding, builder.build, "foo")
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
86
87
    def test_build_tree(self):
88
        """Test building works using a MemoryTree."""
89
        branch = self.make_branch('branch')
90
        tree = MemoryTree.create_on_branch(branch)
91
        builder = TreeBuilder()
92
        builder.start_tree(tree)
93
        builder.build(['foo', "bar/", "bar/file"])
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
94
        self.assertEqual(
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
95
            b'contents of foo\n',
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
96
            tree.get_file('foo').read())
97
        self.assertEqual(
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
98
            b'contents of bar/file\n',
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
99
            tree.get_file('bar/file').read())
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
100
        builder.finish_tree()