1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
17
"""Tests for repository write groups."""
19
from bzrlib import errors
20
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
23
class TestWriteGroup(TestCaseWithRepository):
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)
29
def test_start_write_group_read_locked_needs_write_lock(self):
30
repo = self.make_repository('.')
33
self.assertRaises(errors.NotWriteLocked, repo.start_write_group)
37
def test_start_write_group_write_locked_gets_None(self):
38
repo = self.make_repository('.')
40
self.assertEqual(None, repo.start_write_group())
41
repo.commit_write_group()
44
def test_start_write_group_twice_errors(self):
45
repo = self.make_repository('.')
47
repo.start_write_group()
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)
54
repo.commit_write_group()
57
def test_commit_write_group_gets_None(self):
58
repo = self.make_repository('.')
60
repo.start_write_group()
61
self.assertEqual(None, repo.commit_write_group())
64
def test_unlock_in_write_group(self):
65
repo = self.make_repository('.')
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)
78
def test_is_in_write_group(self):
79
repo = self.make_repository('.')
80
self.assertFalse(repo.is_in_write_group())
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())
93
def test_abort_write_group_gets_None(self):
94
repo = self.make_repository('.')
96
repo.start_write_group()
97
self.assertEqual(None, repo.abort_write_group())