/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')
1255 by Martin Pool
- more tests for selective commit of deletion
98
        b.add(['hello', 'buongia'],
99
              ['hello-id', 'buongia-id'])
100
        b.commit(message='add files',
101
                 rev_id='test@rev-1')
1254 by Martin Pool
- fix handling of selective commit with deleted files
102
        
103
        os.remove('hello')
104
        file('buongia', 'w').write('new text')
105
        b.commit(message='update text',
106
                 specific_files=['buongia'],
1255 by Martin Pool
- more tests for selective commit of deletion
107
                 allow_pointless=False,
108
                 rev_id='test@rev-2')
1254 by Martin Pool
- fix handling of selective commit with deleted files
109
110
        b.commit(message='remove hello',
111
                 specific_files=['hello'],
1255 by Martin Pool
- more tests for selective commit of deletion
112
                 allow_pointless=False,
113
                 rev_id='test@rev-3')
1254 by Martin Pool
- fix handling of selective commit with deleted files
114
115
        eq = self.assertEquals
116
        eq(b.revno(), 3)
1255 by Martin Pool
- more tests for selective commit of deletion
117
118
        tree2 = b.revision_tree('test@rev-2')
119
        self.assertTrue(tree2.has_filename('hello'))
120
        self.assertEquals(tree2.get_file_text('hello-id'), 'hello')
121
        self.assertEquals(tree2.get_file_text('buongia-id'), 'new text')
122
        
123
        tree3 = b.revision_tree('test@rev-3')
124
        self.assertFalse(tree3.has_filename('hello'))
125
        self.assertEquals(tree3.get_file_text('buongia-id'), 'new text')
1254 by Martin Pool
- fix handling of selective commit with deleted files
126
        
1252 by Martin Pool
- add test for commit of an empty tree
127
128
1246 by Martin Pool
- add very simple commit tests
129
    def test_removed_commit(self):
130
        """Test a commit with a removed file"""
1247 by Martin Pool
- tests for deletion and removal of files in commits
131
        b = Branch('.', init=True)
132
        file('hello', 'w').write('hello world')
133
        b.add(['hello'], ['hello-id'])
134
        b.commit(message='add hello')
135
136
        b.remove('hello')
137
        b.commit('removed hello', rev_id='rev2')
138
139
        tree = b.revision_tree('rev2')
140
        self.assertFalse(tree.has_id('hello-id'))
1246 by Martin Pool
- add very simple commit tests
141
142
143
if __name__ == '__main__':
144
    import unittest
145
    unittest.main()
146