/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_treebuilder.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
 
 
18
 
"""Tests for the TreeBuilder helper class."""
19
 
 
20
 
from breezy import tests
21
 
from breezy.memorytree import MemoryTree
22
 
from breezy.tests import TestCaseWithTransport
23
 
from breezy.treebuilder import (
24
 
    AlreadyBuilding,
25
 
    NotBuilding,
26
 
    TreeBuilder,
27
 
    )
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
 
 
36
 
    def lock_tree_write(self):
37
 
        self._calls.append("lock_tree_write")
38
 
 
39
 
    def unlock(self):
40
 
        self._calls.append("unlock")
41
 
 
42
 
 
43
 
class TestFakeTree(TestCaseWithTransport):
44
 
 
45
 
    def testFakeTree(self):
46
 
        """Check that FakeTree works as required for the TreeBuilder tests."""
47
 
        tree = FakeTree()
48
 
        self.assertEqual([], tree._calls)
49
 
        tree.lock_tree_write()
50
 
        self.assertEqual(["lock_tree_write"], tree._calls)
51
 
        tree.unlock()
52
 
        self.assertEqual(["lock_tree_write", "unlock"], tree._calls)
53
 
 
54
 
 
55
 
class TestTreeBuilderMemoryTree(tests.TestCaseWithMemoryTransport):
56
 
 
57
 
    def test_create(self):
58
 
        TreeBuilder()
59
 
 
60
 
    def test_start_tree_locks_write(self):
61
 
        builder = TreeBuilder()
62
 
        tree = FakeTree()
63
 
        builder.start_tree(tree)
64
 
        self.assertEqual(["lock_tree_write"], tree._calls)
65
 
 
66
 
    def test_start_tree_when_started_fails(self):
67
 
        builder = TreeBuilder()
68
 
        tree = FakeTree()
69
 
        builder.start_tree(tree)
70
 
        self.assertRaises(AlreadyBuilding, builder.start_tree, tree)
71
 
 
72
 
    def test_finish_tree_not_started_errors(self):
73
 
        builder = TreeBuilder()
74
 
        self.assertRaises(NotBuilding, builder.finish_tree)
75
 
 
76
 
    def test_finish_tree_unlocks(self):
77
 
        builder = TreeBuilder()
78
 
        tree = FakeTree()
79
 
        builder.start_tree(tree)
80
 
        builder.finish_tree()
81
 
        self.assertEqual(["lock_tree_write", "unlock"], tree._calls)
82
 
 
83
 
    def test_build_tree_not_started_errors(self):
84
 
        builder = TreeBuilder()
85
 
        self.assertRaises(NotBuilding, builder.build, "foo")
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"])
94
 
        self.assertEqual(
95
 
            b'contents of foo\n',
96
 
            tree.get_file('foo').read())
97
 
        self.assertEqual(
98
 
            b'contents of bar/file\n',
99
 
            tree.get_file('bar/file').read())
100
 
        builder.finish_tree()