/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import errors
21
from breezy.tests import TestSkipped
22
from breezy.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')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
29
        with tree.lock_write():
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
30
            tree.flush()
31
32
    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.
33
        if sys.platform == "win32":
34
            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.
35
        # 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.
36
        # and tries to grab a read lock. This works on Unix and is a reasonable
37
        # way to detect when the file is actually written to, but it won't work
38
        # (as a test) on Windows. It might be nice to instead stub out the
39
        # functions used to write and that way do both less work and also be
40
        # able to execute on Windows.
4523.4.17 by John Arbash Meinel
Now we got to the per-workingtree tests, etc.
41
        self.thisFailsStrictLockCheck()
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
42
        # when doing a flush the inventory should be written if needed.
43
        # we test that by changing the inventory (using
44
        # _set_inventory for now until add etc have lazy writes of
45
        # the inventory on unlock).
46
        tree = self.make_branch_and_tree('tree')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
47
        # 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
48
        # inventory
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
49
        with tree.lock_write():
50
            old_root = tree.path2id('')
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
51
            tree.add('')
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
52
            # to detect that the inventory is written by flush, we
53
            # first check that it was not written yet.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
54
            reference_tree = tree.controldir.open_workingtree()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
55
            self.assertEqual(old_root, reference_tree.path2id(''))
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
56
            # now flush the tree which should write the inventory.
57
            tree.flush()
58
            # and check it was written using another reference tree
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
59
            reference_tree = tree.controldir.open_workingtree()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
60
            self.assertIsNot(None, reference_tree.path2id(''))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
61
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
62
    def test_flush_with_read_lock_fails(self):
63
        """Flush cannot be used during a read lock."""
64
        tree = self.make_branch_and_tree('t1')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
65
        with tree.lock_read():
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
66
            self.assertRaises(errors.NotWriteLocked, tree.flush)
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_no_lock_fails(self):
69
        tree = self.make_branch_and_tree('t1')
70
        self.assertRaises(errors.NotWriteLocked, tree.flush)