~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
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
19
import sys
5807.2.1 by Jelmer Vernooij
Remove unused imports.
20
from bzrlib import errors
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
21
from bzrlib.tests import TestSkipped
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
22
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
23
24
25
class TestFlush(TestCaseWithWorkingTree):
26
27
    def test_flush_fresh_tree(self):
28
        tree = self.make_branch_and_tree('t1')
29
        tree.lock_write()
30
        try:
31
            tree.flush()
32
        finally:
33
            tree.unlock()
34
35
    def test_flush_when_inventory_is_modified(self):
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
36
        if sys.platform == "win32":
37
            raise TestSkipped("don't use oslocks on win32 in unix manner")
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
38
        # This takes a write lock on the source tree, then opens a second copy
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
39
        # and tries to grab a read lock. This works on Unix and is a reasonable
40
        # way to detect when the file is actually written to, but it won't work
41
        # (as a test) on Windows. It might be nice to instead stub out the
42
        # functions used to write and that way do both less work and also be
43
        # able to execute on Windows.
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
44
        self.thisFailsStrictLockCheck()
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
45
        # when doing a flush the inventory should be written if needed.
46
        # we test that by changing the inventory (using
47
        # _set_inventory for now until add etc have lazy writes of
48
        # the inventory on unlock).
49
        tree = self.make_branch_and_tree('tree')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
50
        # 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
51
        # inventory
52
        tree.lock_write()
53
        try:
54
            old_root = tree.get_root_id()
55
            tree.set_root_id('new-root')
56
            # to detect that the inventory is written by flush, we
57
            # first check that it was not written yet.
58
            reference_tree = tree.bzrdir.open_workingtree()
59
            self.assertEqual(old_root, reference_tree.get_root_id())
60
            # now flush the tree which should write the inventory.
61
            tree.flush()
62
            # and check it was written using another reference tree
63
            reference_tree = tree.bzrdir.open_workingtree()
64
            self.assertEqual('new-root', reference_tree.get_root_id())
65
        finally:
66
            tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
67
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
68
    def test_flush_with_read_lock_fails(self):
69
        """Flush cannot be used during a read lock."""
70
        tree = self.make_branch_and_tree('t1')
71
        tree.lock_read()
72
        try:
73
            self.assertRaises(errors.NotWriteLocked, tree.flush)
74
        finally:
75
            tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
76
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
77
    def test_flush_with_no_lock_fails(self):
78
        tree = self.make_branch_and_tree('t1')
79
        self.assertRaises(errors.NotWriteLocked, tree.flush)