/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.10 by John Arbash Meinel
Add StreamSink.insert_stream_without_locking
1
# Copyright (C) 2007-2011 Canonical Ltd
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
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
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
16
17
"""Tests for repository write groups."""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
4343.3.2 by John Arbash Meinel
All stacking tests seem to be passing for dev6 repos
20
    errors,
21
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy.tests import (
5017.3.43 by Vincent Ladeuil
-s bt.per_repository.test_write_group passing
23
    per_repository,
24
    test_server,
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.transport import memory
5010.2.7 by Vincent Ladeuil
Fix per_repository/test_write_group.py imports.
27
28
29
class TestWriteGroup(per_repository.TestCaseWithRepository):
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
30
31
    def test_start_write_group_unlocked_needs_write_lock(self):
32
        repo = self.make_repository('.')
33
        self.assertRaises(errors.NotWriteLocked, repo.start_write_group)
34
35
    def test_start_write_group_read_locked_needs_write_lock(self):
36
        repo = self.make_repository('.')
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
37
        with repo.lock_read():
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
38
            self.assertRaises(errors.NotWriteLocked, repo.start_write_group)
39
40
    def test_start_write_group_write_locked_gets_None(self):
41
        repo = self.make_repository('.')
42
        repo.lock_write()
43
        self.assertEqual(None, repo.start_write_group())
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
44
        repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
45
        repo.unlock()
46
47
    def test_start_write_group_twice_errors(self):
48
        repo = self.make_repository('.')
49
        repo.lock_write()
50
        repo.start_write_group()
51
        try:
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
52
            # don't need a specific exception for now - this is
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
53
            # really to be sure it's used right, not for signalling
54
            # semantic information.
55
            self.assertRaises(errors.BzrError, repo.start_write_group)
56
        finally:
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
57
            repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
58
            repo.unlock()
59
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
60
    def test_commit_write_group_does_not_error(self):
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
61
        repo = self.make_repository('.')
62
        repo.lock_write()
63
        repo.start_write_group()
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
64
        # commit_write_group can either return None (for repositories without
65
        # isolated transactions) or a hint for pack(). So we only check it
66
        # works in this interface test, because all repositories are exercised.
67
        repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
68
        repo.unlock()
69
2592.3.242 by Martin Pool
New method TestCase.call_catch_warnings
70
    def test_unlock_in_write_group(self):
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
71
        repo = self.make_repository('.')
72
        repo.lock_write()
73
        repo.start_write_group()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
74
        # don't need a specific exception for now - this is
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
75
        # really to be sure it's used right, not for signalling
76
        # semantic information.
4634.85.10 by Andrew Bennetts
Change test_unlock_in_write_group to expect a log_exception_quietly rather than a raise.
77
        self.assertLogsError(errors.BzrError, repo.unlock)
2592.3.244 by Martin Pool
unlock while in a write group now aborts the write group, unlocks, and errors.
78
        # after this error occurs, the repository is unlocked, and the write
79
        # group is gone.  you've had your chance, and you blew it. ;-)
80
        self.assertFalse(repo.is_locked())
81
        self.assertRaises(errors.BzrError, repo.commit_write_group)
82
        self.assertRaises(errors.BzrError, repo.unlock)
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
83
84
    def test_is_in_write_group(self):
85
        repo = self.make_repository('.')
86
        self.assertFalse(repo.is_in_write_group())
87
        repo.lock_write()
88
        repo.start_write_group()
89
        self.assertTrue(repo.is_in_write_group())
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
90
        repo.commit_write_group()
91
        self.assertFalse(repo.is_in_write_group())
92
        # abort also removes the in_write_group status.
93
        repo.start_write_group()
94
        self.assertTrue(repo.is_in_write_group())
95
        repo.abort_write_group()
96
        self.assertFalse(repo.is_in_write_group())
97
        repo.unlock()
98
99
    def test_abort_write_group_gets_None(self):
100
        repo = self.make_repository('.')
101
        repo.lock_write()
102
        repo.start_write_group()
103
        self.assertEqual(None, repo.abort_write_group())
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
104
        repo.unlock()
3825.4.1 by Andrew Bennetts
Add suppress_errors to abort_write_group.
105
106
    def test_abort_write_group_does_not_raise_when_suppressed(self):
5017.3.43 by Vincent Ladeuil
-s bt.per_repository.test_write_group passing
107
        if self.transport_server is test_server.LocalURLServer:
3825.4.3 by Andrew Bennetts
Conditionally replace LocalURLServer in the test rather than changing the default_transport behaviour of per_repository tests.
108
            self.transport_server = None
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
109
        self.vfs_transport_factory = memory.MemoryServer
3825.4.1 by Andrew Bennetts
Add suppress_errors to abort_write_group.
110
        repo = self.make_repository('repo')
111
        token = repo.lock_write()
112
        self.addCleanup(repo.unlock)
113
        repo.start_write_group()
114
        # Damage the repository on the filesystem
4327.1.9 by Vincent Ladeuil
Fix 4 more lock-related test failures.
115
        t = self.get_transport('')
116
        t.rename('repo', 'foo')
117
        self.addCleanup(t.rename, 'foo', 'repo')
3825.4.1 by Andrew Bennetts
Add suppress_errors to abort_write_group.
118
        # abort_write_group will not raise an error, because either an
119
        # exception was not generated, or the exception was caught and
120
        # suppressed.  See also test_pack_repository's test of the same name.
121
        self.assertEqual(None, repo.abort_write_group(suppress_errors=True))