~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testtransactions.py

  • Committer: Robert Collins
  • Date: 2005-10-07 04:10:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1420.
  • Revision ID: robertc@robertcollins.net-20051007041046-10b07ae31ecde799
introduce transactions for grouping actions done to and with branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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")
 
41
    
 
42
    def test_commit_raises(self):
 
43
        transaction = transactions.ReadOnlyTransaction()
 
44
        self.assertRaises(errors.CommitNotPossible, transaction.commit)
 
45
 
 
46
    def test_map(self):
 
47
        transaction = transactions.ReadOnlyTransaction()
 
48
        self.assertNotEqual(None, getattr(transaction, "map", None))
 
49
    
 
50
    def test_add_and_get(self):
 
51
        transaction = transactions.ReadOnlyTransaction()
 
52
        weave = "a weave"
 
53
        transaction.map.add_weave("id", weave)
 
54
        self.assertEqual(weave, transaction.map.find_weave("id"))
 
55
 
 
56
    def test_rollback_returns(self):
 
57
        transaction = transactions.ReadOnlyTransaction()
 
58
        transaction.rollback()
 
59
 
 
60
    def test_finish_returns(self):
 
61
        transaction = transactions.ReadOnlyTransaction()
 
62
        transaction.finish()
 
63
 
 
64
        
 
65
class TestPassThroughTransaction(TestCase):
 
66
 
 
67
    def test_symbols(self):
 
68
        from bzrlib.transactions import PassThroughTransaction
 
69
 
 
70
    def test_construct(self):
 
71
        transactions.PassThroughTransaction()
 
72
 
 
73
    def test_register_clean(self):
 
74
        transaction = transactions.PassThroughTransaction()
 
75
        transaction.register_clean("anobject")
 
76
    
 
77
    def test_commit_nothing_returns(self):
 
78
        transaction = transactions.PassThroughTransaction()
 
79
        transaction.commit()
 
80
 
 
81
    def test_map(self):
 
82
        transaction = transactions.PassThroughTransaction()
 
83
        self.assertNotEqual(None, getattr(transaction, "map", None))
 
84
    
 
85
    def test_add_and_get(self):
 
86
        transaction = transactions.PassThroughTransaction()
 
87
        weave = "a weave"
 
88
        transaction.map.add_weave("id", weave)
 
89
        self.assertEqual(None, transaction.map.find_weave("id"))
 
90
        
 
91
    def test_rollback_asserts(self):
 
92
        transaction = transactions.PassThroughTransaction()
 
93
        self.assertRaises(errors.AlreadyCommitted, transaction.rollback)
 
94
 
 
95
    def test_finish_returns(self):
 
96
        transaction = transactions.PassThroughTransaction()
 
97
        transaction.finish()