1
# Copyright (C) 2005 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
"""Tests for the behaviour of the Transaction concept in bzr."""
20
# import system imports here
24
#import bzrlib specific imports here
25
import bzrlib.errors as errors
26
from bzrlib.selftest import TestCase, TestCaseInTempDir
27
import bzrlib.transactions as transactions
30
class TestReadOnlyTransaction(TestCase):
32
def test_symbols(self):
33
from bzrlib.transactions import ReadOnlyTransaction
35
def test_construct(self):
36
transactions.ReadOnlyTransaction()
38
def test_register_clean(self):
39
transaction = transactions.ReadOnlyTransaction()
40
transaction.register_clean("anobject")
42
def test_commit_raises(self):
43
transaction = transactions.ReadOnlyTransaction()
44
self.assertRaises(errors.CommitNotPossible, transaction.commit)
47
transaction = transactions.ReadOnlyTransaction()
48
self.assertNotEqual(None, getattr(transaction, "map", None))
50
def test_add_and_get(self):
51
transaction = transactions.ReadOnlyTransaction()
53
transaction.map.add_weave("id", weave)
54
self.assertEqual(weave, transaction.map.find_weave("id"))
56
def test_rollback_returns(self):
57
transaction = transactions.ReadOnlyTransaction()
58
transaction.rollback()
60
def test_finish_returns(self):
61
transaction = transactions.ReadOnlyTransaction()
65
class TestPassThroughTransaction(TestCase):
67
def test_symbols(self):
68
from bzrlib.transactions import PassThroughTransaction
70
def test_construct(self):
71
transactions.PassThroughTransaction()
73
def test_register_clean(self):
74
transaction = transactions.PassThroughTransaction()
75
transaction.register_clean("anobject")
77
def test_commit_nothing_returns(self):
78
transaction = transactions.PassThroughTransaction()
82
transaction = transactions.PassThroughTransaction()
83
self.assertNotEqual(None, getattr(transaction, "map", None))
85
def test_add_and_get(self):
86
transaction = transactions.PassThroughTransaction()
88
transaction.map.add_weave("id", weave)
89
self.assertEqual(None, transaction.map.find_weave("id"))
91
def test_rollback_asserts(self):
92
transaction = transactions.PassThroughTransaction()
93
self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
95
def test_finish_returns(self):
96
transaction = transactions.PassThroughTransaction()