~bzr-pqm/bzr/bzr.dev

2052.3.10 by John Arbash Meinel
[merge] bzr.dev 2079
1
# Copyright (C) 2006 Canonical Ltd
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
16
17
"""Tests for WorkingTree.flush."""
18
19
from bzrlib import errors, inventory
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
20
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
21
22
23
class TestFlush(TestCaseWithWorkingTree):
24
25
    def test_flush_fresh_tree(self):
26
        tree = self.make_branch_and_tree('t1')
27
        tree.lock_write()
28
        try:
29
            tree.flush()
30
        finally:
31
            tree.unlock()
32
33
    def test_flush_when_inventory_is_modified(self):
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
34
        # This takes a write lock on the source tree, then opens a second copy
35
        # and tries to grab a read lock, which is a bit bogus
36
        self.thisFailsStrictLockCheck()
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
37
        # when doing a flush the inventory should be written if needed.
38
        # we test that by changing the inventory (using
39
        # _set_inventory for now until add etc have lazy writes of
40
        # the inventory on unlock).
41
        tree = self.make_branch_and_tree('tree')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
42
        # prepare for a series of changes that will modify the
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
43
        # inventory
44
        tree.lock_write()
45
        try:
46
            old_root = tree.get_root_id()
47
            tree.set_root_id('new-root')
48
            # to detect that the inventory is written by flush, we
49
            # first check that it was not written yet.
50
            reference_tree = tree.bzrdir.open_workingtree()
51
            self.assertEqual(old_root, reference_tree.get_root_id())
52
            # now flush the tree which should write the inventory.
53
            tree.flush()
54
            # and check it was written using another reference tree
55
            reference_tree = tree.bzrdir.open_workingtree()
56
            self.assertEqual('new-root', reference_tree.get_root_id())
57
        finally:
58
            tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
59
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
60
    def test_flush_with_read_lock_fails(self):
61
        """Flush cannot be used during a read lock."""
62
        tree = self.make_branch_and_tree('t1')
63
        tree.lock_read()
64
        try:
65
            self.assertRaises(errors.NotWriteLocked, tree.flush)
66
        finally:
67
            tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
68
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
69
    def test_flush_with_no_lock_fails(self):
70
        tree = self.make_branch_and_tree('t1')
71
        self.assertRaises(errors.NotWriteLocked, tree.flush)