/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
1252 by Martin Pool
- add test for commit of an empty tree
66
    def test_commit_empty(self):
67
        b = Branch('.', init=True)
68
        b.commit(message='empty tree', allow_pointless=True)
69
        ##self.assertRaises(PointlessCommit,
70
        ##                  b.commit,
71
        ##                  message='empty tree')
72
        b.commit(message='empty tree', allow_pointless=True)
73
        self.assertEquals(b.revno(), 2)
74
75
76
    def test_selective_delete(self):
77
        """Selective commit in tree with deletions"""
78
79
1246 by Martin Pool
- add very simple commit tests
80
    def test_removed_commit(self):
81
        """Test a commit with a removed file"""
1247 by Martin Pool
- tests for deletion and removal of files in commits
82
        b = Branch('.', init=True)
83
        file('hello', 'w').write('hello world')
84
        b.add(['hello'], ['hello-id'])
85
        b.commit(message='add hello')
86
87
        b.remove('hello')
88
        b.commit('removed hello', rev_id='rev2')
89
90
        tree = b.revision_tree('rev2')
91
        self.assertFalse(tree.has_id('hello-id'))
1246 by Martin Pool
- add very simple commit tests
92
93
94
if __name__ == '__main__':
95
    import unittest
96
    unittest.main()
97