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 |
|
23 |
||
24 |
||
25 |
class TestCommit(TestCaseInTempDir): |
|
26 |
def test_simple_commit(self): |
|
27 |
"""Commit and check two versions of a single file.""" |
|
28 |
b = Branch('.', init=True) |
|
29 |
file('hello', 'w').write('hello world') |
|
30 |
b.add('hello') |
|
31 |
b.commit(message='add hello') |
|
32 |
file_id = b.working_tree().path2id('hello') |
|
33 |
||
34 |
file('hello', 'w').write('version 2') |
|
35 |
b.commit(message='commit 2') |
|
36 |
||
37 |
eq = self.assertEquals |
|
38 |
eq(b.revno(), 2) |
|
39 |
rh = b.revision_history() |
|
40 |
rev = b.get_revision(rh[0]) |
|
41 |
eq(rev.message, 'add hello') |
|
42 |
||
43 |
tree1 = b.revision_tree(rh[0]) |
|
44 |
text = tree1.get_file_text(file_id) |
|
45 |
eq(text, 'hello world') |
|
46 |
||
47 |
tree2 = b.revision_tree(rh[1]) |
|
48 |
eq(tree2.get_file_text(file_id), 'version 2') |
|
49 |
||
50 |
||
51 |
def test_delete_commit(self): |
|
52 |
"""Test a commit with a deleted file""" |
|
1247
by Martin Pool
- tests for deletion and removal of files in commits |
53 |
b = Branch('.', init=True) |
54 |
file('hello', 'w').write('hello world') |
|
55 |
b.add(['hello'], ['hello-id']) |
|
56 |
b.commit(message='add hello') |
|
57 |
||
58 |
os.remove('hello') |
|
59 |
b.commit('removed hello', rev_id='rev2') |
|
60 |
||
61 |
tree = b.revision_tree('rev2') |
|
62 |
self.assertFalse(tree.has_id('hello-id')) |
|
63 |
||
1246
by Martin Pool
- add very simple commit tests |
64 |
|
65 |
def test_removed_commit(self): |
|
66 |
"""Test a commit with a removed file""" |
|
1247
by Martin Pool
- tests for deletion and removal of files in commits |
67 |
b = Branch('.', init=True) |
68 |
file('hello', 'w').write('hello world') |
|
69 |
b.add(['hello'], ['hello-id']) |
|
70 |
b.commit(message='add hello') |
|
71 |
||
72 |
b.remove('hello') |
|
73 |
b.commit('removed hello', rev_id='rev2') |
|
74 |
||
75 |
tree = b.revision_tree('rev2') |
|
76 |
self.assertFalse(tree.has_id('hello-id')) |
|
1246
by Martin Pool
- add very simple commit tests |
77 |
|
78 |
||
79 |
if __name__ == '__main__': |
|
80 |
import unittest |
|
81 |
unittest.main() |
|
82 |