/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
1
# Copyright (C) 2007 Canonical Ltd
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for repository write groups."""
18
19
from bzrlib import errors
20
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
21
22
23
class TestWriteGroup(TestCaseWithRepository):
24
25
    def test_start_write_group_unlocked_needs_write_lock(self):
26
        repo = self.make_repository('.')
27
        self.assertRaises(errors.NotWriteLocked, repo.start_write_group)
28
29
    def test_start_write_group_read_locked_needs_write_lock(self):
30
        repo = self.make_repository('.')
31
        repo.lock_read()
32
        try:
33
            self.assertRaises(errors.NotWriteLocked, repo.start_write_group)
34
        finally:
35
            repo.unlock()
36
37
    def test_start_write_group_write_locked_gets_None(self):
38
        repo = self.make_repository('.')
39
        repo.lock_write()
40
        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.
41
        repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
42
        repo.unlock()
43
44
    def test_start_write_group_twice_errors(self):
45
        repo = self.make_repository('.')
46
        repo.lock_write()
47
        repo.start_write_group()
48
        try:
49
            # don't need a specific exception for now - this is 
50
            # really to be sure it's used right, not for signalling
51
            # semantic information.
52
            self.assertRaises(errors.BzrError, repo.start_write_group)
53
        finally:
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
54
            repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
55
            repo.unlock()
56
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
57
    def test_commit_write_group_gets_None(self):
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
58
        repo = self.make_repository('.')
59
        repo.lock_write()
60
        repo.start_write_group()
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
61
        self.assertEqual(None, repo.commit_write_group())
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
62
        repo.unlock()
63
64
    def test_unlock_after_start_errors(self):
65
        repo = self.make_repository('.')
66
        repo.lock_write()
67
        repo.start_write_group()
68
        # don't need a specific exception for now - this is 
69
        # really to be sure it's used right, not for signalling
70
        # semantic information.
71
        self.assertRaises(errors.BzrError, repo.unlock)
72
        self.assertTrue(repo.is_locked())
2617.6.2 by Robert Collins
Add abort_write_group and wire write_groups into fetch and commit.
73
        repo.commit_write_group()
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
74
        repo.unlock()
75
76
    def test_is_in_write_group(self):
77
        repo = self.make_repository('.')
78
        self.assertFalse(repo.is_in_write_group())
79
        repo.lock_write()
80
        repo.start_write_group()
81
        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.
82
        repo.commit_write_group()
83
        self.assertFalse(repo.is_in_write_group())
84
        # abort also removes the in_write_group status.
85
        repo.start_write_group()
86
        self.assertTrue(repo.is_in_write_group())
87
        repo.abort_write_group()
88
        self.assertFalse(repo.is_in_write_group())
89
        repo.unlock()
90
91
    def test_abort_write_group_gets_None(self):
92
        repo = self.make_repository('.')
93
        repo.lock_write()
94
        repo.start_write_group()
95
        self.assertEqual(None, repo.abort_write_group())
2617.6.1 by Robert Collins
* New method on Repository - ``start_write_group``, ``end_write_group``
96
        repo.unlock()