~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (C) 2005 by Canonical Ltd
#   Authors: Robert Collins <robert.collins@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""Tests for the behaviour of the Transaction concept in bzr."""

# import system imports here
import os
import sys

#import bzrlib specific imports here
import bzrlib.errors as errors
from bzrlib.selftest import TestCase, TestCaseInTempDir
import bzrlib.transactions as transactions


class TestReadOnlyTransaction(TestCase):

    def test_symbols(self):
        from bzrlib.transactions import ReadOnlyTransaction

    def test_construct(self):
        transactions.ReadOnlyTransaction()

    def test_register_clean(self):
        transaction = transactions.ReadOnlyTransaction()
        transaction.register_clean("anobject")

    def test_register_dirty_raises(self):
        transaction = transactions.ReadOnlyTransaction()
        self.assertRaises(errors.ReadOnlyError, 
                          transaction.register_dirty,"anobject")
    
    def test_commit_raises(self):
        transaction = transactions.ReadOnlyTransaction()
        self.assertRaises(errors.CommitNotPossible, transaction.commit)

    def test_map(self):
        transaction = transactions.ReadOnlyTransaction()
        self.assertNotEqual(None, getattr(transaction, "map", None))
    
    def test_add_and_get(self):
        transaction = transactions.ReadOnlyTransaction()
        weave = "a weave"
        transaction.map.add_weave("id", weave)
        self.assertEqual(weave, transaction.map.find_weave("id"))

    def test_rollback_returns(self):
        transaction = transactions.ReadOnlyTransaction()
        transaction.rollback()

    def test_finish_returns(self):
        transaction = transactions.ReadOnlyTransaction()
        transaction.finish()

        
class TestPassThroughTransaction(TestCase):

    def test_symbols(self):
        from bzrlib.transactions import PassThroughTransaction

    def test_construct(self):
        transactions.PassThroughTransaction()

    def test_register_clean(self):
        transaction = transactions.PassThroughTransaction()
        transaction.register_clean("anobject")
    
    def test_register_dirty(self):
        transaction = transactions.PassThroughTransaction()
        transaction.register_dirty("anobject")
    
    def test_commit_nothing_returns(self):
        transaction = transactions.PassThroughTransaction()
        transaction.commit()

    def test_map(self):
        transaction = transactions.PassThroughTransaction()
        self.assertNotEqual(None, getattr(transaction, "map", None))
    
    def test_add_and_get(self):
        transaction = transactions.PassThroughTransaction()
        weave = "a weave"
        transaction.map.add_weave("id", weave)
        self.assertEqual(None, transaction.map.find_weave("id"))
        
    def test_rollback_asserts(self):
        transaction = transactions.PassThroughTransaction()
        self.assertRaises(errors.AlreadyCommitted, transaction.rollback)

    def test_finish_returns(self):
        transaction = transactions.PassThroughTransaction()
        transaction.finish()