/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_write_group.py

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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())
 
41
        repo.commit_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:
 
54
            repo.commit_write_group()
 
55
            repo.unlock()
 
56
 
 
57
    def test_commit_write_group_gets_None(self):
 
58
        repo = self.make_repository('.')
 
59
        repo.lock_write()
 
60
        repo.start_write_group()
 
61
        self.assertEqual(None, repo.commit_write_group())
 
62
        repo.unlock()
 
63
 
 
64
    def test_unlock_in_write_group(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
        # after this error occurs, the repository is unlocked, and the write
 
73
        # group is gone.  you've had your chance, and you blew it. ;-)
 
74
        self.assertFalse(repo.is_locked())
 
75
        self.assertRaises(errors.BzrError, repo.commit_write_group)
 
76
        self.assertRaises(errors.BzrError, repo.unlock)
 
77
 
 
78
    def test_is_in_write_group(self):
 
79
        repo = self.make_repository('.')
 
80
        self.assertFalse(repo.is_in_write_group())
 
81
        repo.lock_write()
 
82
        repo.start_write_group()
 
83
        self.assertTrue(repo.is_in_write_group())
 
84
        repo.commit_write_group()
 
85
        self.assertFalse(repo.is_in_write_group())
 
86
        # abort also removes the in_write_group status.
 
87
        repo.start_write_group()
 
88
        self.assertTrue(repo.is_in_write_group())
 
89
        repo.abort_write_group()
 
90
        self.assertFalse(repo.is_in_write_group())
 
91
        repo.unlock()
 
92
 
 
93
    def test_abort_write_group_gets_None(self):
 
94
        repo = self.make_repository('.')
 
95
        repo.lock_write()
 
96
        repo.start_write_group()
 
97
        self.assertEqual(None, repo.abort_write_group())
 
98
        repo.unlock()