/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1246 by Martin Pool
- add very simple commit tests
1
# Copyright (C) 2005 by Canonical Ltd
2
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.
7
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.
12
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
16
17
18
import os
19
20
from bzrlib.selftest import TestCaseInTempDir
21
from bzrlib.branch import Branch
22
from bzrlib.commit import Commit
1252 by Martin Pool
- add test for commit of an empty tree
23
from bzrlib.errors import PointlessCommit
1246 by Martin Pool
- add very simple commit tests
24
25
26
class TestCommit(TestCaseInTempDir):
27
    def test_simple_commit(self):
28
        """Commit and check two versions of a single file."""
29
        b = Branch('.', init=True)
30
        file('hello', 'w').write('hello world')
31
        b.add('hello')
32
        b.commit(message='add hello')
33
        file_id = b.working_tree().path2id('hello')
34
35
        file('hello', 'w').write('version 2')
36
        b.commit(message='commit 2')
37
38
        eq = self.assertEquals
39
        eq(b.revno(), 2)
40
        rh = b.revision_history()
41
        rev = b.get_revision(rh[0])
42
        eq(rev.message, 'add hello')
43
44
        tree1 = b.revision_tree(rh[0])
45
        text = tree1.get_file_text(file_id)
46
        eq(text, 'hello world')
47
48
        tree2 = b.revision_tree(rh[1])
49
        eq(tree2.get_file_text(file_id), 'version 2')
50
51
52
    def test_delete_commit(self):
53
        """Test a commit with a deleted file"""
1247 by Martin Pool
- tests for deletion and removal of files in commits
54
        b = Branch('.', init=True)
55
        file('hello', 'w').write('hello world')
56
        b.add(['hello'], ['hello-id'])
57
        b.commit(message='add hello')
58
59
        os.remove('hello')
60
        b.commit('removed hello', rev_id='rev2')
61
62
        tree = b.revision_tree('rev2')
63
        self.assertFalse(tree.has_id('hello-id'))
64
1246 by Martin Pool
- add very simple commit tests
65
1253 by Martin Pool
- test that pointless commits are trapped
66
    def test_pointless_commit(self):
67
        """Commit refuses unless there are changes or it's forced."""
68
        b = Branch('.', init=True)
69
        file('hello', 'w').write('hello')
70
        b.add(['hello'])
71
        b.commit(message='add hello')
72
        self.assertEquals(b.revno(), 1)
73
        self.assertRaises(PointlessCommit,
74
                          b.commit,
75
                          message='fails',
76
                          allow_pointless=False)
77
        self.assertEquals(b.revno(), 1)
78
        
79
80
1252 by Martin Pool
- add test for commit of an empty tree
81
    def test_commit_empty(self):
1253 by Martin Pool
- test that pointless commits are trapped
82
        """Commiting an empty tree works."""
1252 by Martin Pool
- add test for commit of an empty tree
83
        b = Branch('.', init=True)
84
        b.commit(message='empty tree', allow_pointless=True)
1253 by Martin Pool
- test that pointless commits are trapped
85
        self.assertRaises(PointlessCommit,
86
                          b.commit,
87
                          message='empty tree',
88
                          allow_pointless=False)
1252 by Martin Pool
- add test for commit of an empty tree
89
        b.commit(message='empty tree', allow_pointless=True)
90
        self.assertEquals(b.revno(), 2)
91
92
93
    def test_selective_delete(self):
94
        """Selective commit in tree with deletions"""
1254 by Martin Pool
- fix handling of selective commit with deleted files
95
        b = Branch('.', init=True)
96
        file('hello', 'w').write('hello')
97
        file('buongia', 'w').write('buongia')
98
        b.add(['hello', 'buongia'])
99
        b.commit(message='add files')
100
        
101
        os.remove('hello')
102
        file('buongia', 'w').write('new text')
103
        b.commit(message='update text',
104
                 specific_files=['buongia'],
105
                 allow_pointless=False)
106
107
        b.commit(message='remove hello',
108
                 specific_files=['hello'],
109
                 allow_pointless=False)
110
111
        eq = self.assertEquals
112
        eq(b.revno(), 3)
113
        
1252 by Martin Pool
- add test for commit of an empty tree
114
115
1246 by Martin Pool
- add very simple commit tests
116
    def test_removed_commit(self):
117
        """Test a commit with a removed file"""
1247 by Martin Pool
- tests for deletion and removal of files in commits
118
        b = Branch('.', init=True)
119
        file('hello', 'w').write('hello world')
120
        b.add(['hello'], ['hello-id'])
121
        b.commit(message='add hello')
122
123
        b.remove('hello')
124
        b.commit('removed hello', rev_id='rev2')
125
126
        tree = b.revision_tree('rev2')
127
        self.assertFalse(tree.has_id('hello-id'))
1246 by Martin Pool
- add very simple commit tests
128
129
130
if __name__ == '__main__':
131
    import unittest
132
    unittest.main()
133