~bzr-pqm/bzr/bzr.dev

1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
1
# Copyright (C) 2005 by Canonical Ltd
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
#
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.
8
#
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.
13
#
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
17
18
"""Tests for the behaviour of the Transaction concept in bzr."""
19
20
# import system imports here
21
import os
22
import sys
23
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
28
29
30
class TestReadOnlyTransaction(TestCase):
31
32
    def test_symbols(self):
33
        from bzrlib.transactions import ReadOnlyTransaction
34
35
    def test_construct(self):
36
        transactions.ReadOnlyTransaction()
37
38
    def test_register_clean(self):
39
        transaction = transactions.ReadOnlyTransaction()
40
        transaction.register_clean("anobject")
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
41
42
    def test_register_dirty_raises(self):
43
        transaction = transactions.ReadOnlyTransaction()
44
        self.assertRaises(errors.ReadOnlyError, 
45
                          transaction.register_dirty,"anobject")
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
46
    
47
    def test_commit_raises(self):
48
        transaction = transactions.ReadOnlyTransaction()
49
        self.assertRaises(errors.CommitNotPossible, transaction.commit)
50
51
    def test_map(self):
52
        transaction = transactions.ReadOnlyTransaction()
53
        self.assertNotEqual(None, getattr(transaction, "map", None))
54
    
55
    def test_add_and_get(self):
56
        transaction = transactions.ReadOnlyTransaction()
57
        weave = "a weave"
58
        transaction.map.add_weave("id", weave)
59
        self.assertEqual(weave, transaction.map.find_weave("id"))
60
61
    def test_rollback_returns(self):
62
        transaction = transactions.ReadOnlyTransaction()
63
        transaction.rollback()
64
65
    def test_finish_returns(self):
66
        transaction = transactions.ReadOnlyTransaction()
67
        transaction.finish()
68
69
        
70
class TestPassThroughTransaction(TestCase):
71
72
    def test_symbols(self):
73
        from bzrlib.transactions import PassThroughTransaction
74
75
    def test_construct(self):
76
        transactions.PassThroughTransaction()
77
78
    def test_register_clean(self):
79
        transaction = transactions.PassThroughTransaction()
80
        transaction.register_clean("anobject")
81
    
1417.1.8 by Robert Collins
use transactions in the weave store interface, which enables caching for log
82
    def test_register_dirty(self):
83
        transaction = transactions.PassThroughTransaction()
84
        transaction.register_dirty("anobject")
85
    
1417.1.6 by Robert Collins
introduce transactions for grouping actions done to and with branches
86
    def test_commit_nothing_returns(self):
87
        transaction = transactions.PassThroughTransaction()
88
        transaction.commit()
89
90
    def test_map(self):
91
        transaction = transactions.PassThroughTransaction()
92
        self.assertNotEqual(None, getattr(transaction, "map", None))
93
    
94
    def test_add_and_get(self):
95
        transaction = transactions.PassThroughTransaction()
96
        weave = "a weave"
97
        transaction.map.add_weave("id", weave)
98
        self.assertEqual(None, transaction.map.find_weave("id"))
99
        
100
    def test_rollback_asserts(self):
101
        transaction = transactions.PassThroughTransaction()
102
        self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
103
104
    def test_finish_returns(self):
105
        transaction = transactions.PassThroughTransaction()
106
        transaction.finish()