bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
768
by Martin Pool
 - start some tests for directory renames  | 
1  | 
import os  | 
2  | 
import unittest  | 
|
3  | 
||
| 
1141
by Martin Pool
 - rename FunctionalTest to TestCaseInTempDir  | 
4  | 
from bzrlib.selftest import TestCaseInTempDir, TestCase  | 
| 
768
by Martin Pool
 - start some tests for directory renames  | 
5  | 
from bzrlib.branch import ScratchBranch, Branch  | 
| 
778
by Martin Pool
 - simple revert of text files  | 
6  | 
from bzrlib.errors import NotBranchError, NotVersionedError  | 
7  | 
||
8  | 
||
| 
1141
by Martin Pool
 - rename FunctionalTest to TestCaseInTempDir  | 
9  | 
class TestBranch(TestCaseInTempDir):  | 
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
10  | 
|
11  | 
def test_unknowns(self):  | 
|
| 
1185.11.5
by John Arbash Meinel
 Merged up-to-date against mainline, still broken.  | 
12  | 
b = Branch.initialize('.')  | 
| 
781
by Martin Pool
 - start of simple test for unknown-file reporting  | 
13  | 
|
14  | 
self.build_tree(['hello.txt',  | 
|
15  | 
'hello.txt~'])  | 
|
16  | 
||
17  | 
self.assertEquals(list(b.unknowns()),  | 
|
18  | 
['hello.txt'])  | 
|
19  | 
||
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
20  | 
def test_no_changes(self):  | 
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
21  | 
from bzrlib.errors import PointlessCommit  | 
| 
882
by Martin Pool
 - Optionally raise EmptyCommit if there are no changes. Test for this.  | 
22  | 
|
| 
1185.11.5
by John Arbash Meinel
 Merged up-to-date against mainline, still broken.  | 
23  | 
b = Branch.initialize('.')  | 
| 
882
by Martin Pool
 - Optionally raise EmptyCommit if there are no changes. Test for this.  | 
24  | 
|
25  | 
self.build_tree(['hello.txt'])  | 
|
26  | 
||
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
27  | 
self.assertRaises(PointlessCommit,  | 
| 
882
by Martin Pool
 - Optionally raise EmptyCommit if there are no changes. Test for this.  | 
28  | 
b.commit,  | 
29  | 
'commit without adding',  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
30  | 
allow_pointless=False)  | 
| 
882
by Martin Pool
 - Optionally raise EmptyCommit if there are no changes. Test for this.  | 
31  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
32  | 
b.commit('commit pointless tree',  | 
33  | 
allow_pointless=True)  | 
|
| 
883
by Martin Pool
 - more tests for detecting empty commits  | 
34  | 
|
35  | 
b.add('hello.txt')  | 
|
36  | 
||
37  | 
b.commit('commit first added file',  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
38  | 
allow_pointless=False)  | 
| 
883
by Martin Pool
 - more tests for detecting empty commits  | 
39  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
40  | 
self.assertRaises(PointlessCommit,  | 
| 
883
by Martin Pool
 - more tests for detecting empty commits  | 
41  | 
b.commit,  | 
42  | 
'commit after adding file',  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
43  | 
allow_pointless=False)  | 
| 
883
by Martin Pool
 - more tests for detecting empty commits  | 
44  | 
|
45  | 
b.commit('commit pointless revision with one file',  | 
|
| 
885
by Martin Pool
 - commit command refuses unless something is changed or --unchanged is given  | 
46  | 
allow_pointless=True)  | 
| 
883
by Martin Pool
 - more tests for detecting empty commits  | 
47  | 
|
| 
811
by Martin Pool
 - Test case for validate_revision_id  | 
48  | 
|
| 
1278
by Martin Pool
 - remove test that tried to commit absent parents  | 
49  | 
class MoreTests(TestCaseInTempDir):  | 
| 
1390
by Robert Collins
 pair programming worx... merge integration and weave  | 
50  | 
|
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
51  | 
def test_revert(self):  | 
52  | 
"""Test selected-file revert"""  | 
|
| 
1185.11.5
by John Arbash Meinel
 Merged up-to-date against mainline, still broken.  | 
53  | 
b = Branch.initialize('.')  | 
| 
778
by Martin Pool
 - simple revert of text files  | 
54  | 
|
55  | 
self.build_tree(['hello.txt'])  | 
|
56  | 
file('hello.txt', 'w').write('initial hello')  | 
|
57  | 
||
58  | 
self.assertRaises(NotVersionedError,  | 
|
59  | 
b.revert, ['hello.txt'])  | 
|
60  | 
||
61  | 
b.add(['hello.txt'])  | 
|
62  | 
b.commit('create initial hello.txt')  | 
|
63  | 
||
64  | 
self.check_file_contents('hello.txt', 'initial hello')  | 
|
65  | 
file('hello.txt', 'w').write('new hello')  | 
|
66  | 
self.check_file_contents('hello.txt', 'new hello')  | 
|
67  | 
||
68  | 
        # revert file modified since last revision
 | 
|
69  | 
b.revert(['hello.txt'])  | 
|
70  | 
self.check_file_contents('hello.txt', 'initial hello')  | 
|
| 
782
by Martin Pool
 - Branch.revert copies files to backups before reverting them  | 
71  | 
self.check_file_contents('hello.txt~', 'new hello')  | 
| 
778
by Martin Pool
 - simple revert of text files  | 
72  | 
|
| 
782
by Martin Pool
 - Branch.revert copies files to backups before reverting them  | 
73  | 
        # reverting again clobbers the backup
 | 
| 
778
by Martin Pool
 - simple revert of text files  | 
74  | 
b.revert(['hello.txt'])  | 
75  | 
self.check_file_contents('hello.txt', 'initial hello')  | 
|
| 
782
by Martin Pool
 - Branch.revert copies files to backups before reverting them  | 
76  | 
self.check_file_contents('hello.txt~', 'initial hello')  | 
| 
778
by Martin Pool
 - simple revert of text files  | 
77  | 
|
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
78  | 
def test_rename_dirs(self):  | 
79  | 
"""Test renaming directories and the files within them."""  | 
|
| 
1185.11.5
by John Arbash Meinel
 Merged up-to-date against mainline, still broken.  | 
80  | 
b = Branch.initialize('.')  | 
| 
768
by Martin Pool
 - start some tests for directory renames  | 
81  | 
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])  | 
82  | 
b.add(['dir', 'dir/sub', 'dir/sub/file'])  | 
|
83  | 
||
84  | 
b.commit('create initial state')  | 
|
85  | 
||
86  | 
        # TODO: lift out to a test helper that checks the shape of
 | 
|
87  | 
        # an inventory
 | 
|
88  | 
||
89  | 
revid = b.revision_history()[0]  | 
|
90  | 
self.log('first revision_id is {%s}' % revid)  | 
|
91  | 
||
92  | 
inv = b.get_revision_inventory(revid)  | 
|
93  | 
self.log('contents of inventory: %r' % inv.entries())  | 
|
94  | 
||
95  | 
self.check_inventory_shape(inv,  | 
|
96  | 
['dir', 'dir/sub', 'dir/sub/file'])  | 
|
97  | 
||
| 
771
by Martin Pool
 - more tests of directory renames  | 
98  | 
b.rename_one('dir', 'newdir')  | 
99  | 
||
100  | 
self.check_inventory_shape(b.inventory,  | 
|
101  | 
['newdir', 'newdir/sub', 'newdir/sub/file'])  | 
|
102  | 
||
103  | 
b.rename_one('newdir/sub', 'newdir/newsub')  | 
|
104  | 
self.check_inventory_shape(b.inventory,  | 
|
105  | 
['newdir', 'newdir/newsub',  | 
|
106  | 
'newdir/newsub/file'])  | 
|
107  | 
||
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
108  | 
def test_relpath(self):  | 
109  | 
"""test for branch path lookups  | 
|
110  | 
    
 | 
|
| 
1457.1.2
by Robert Collins
 move branch._relpath into osutils as relpath  | 
111  | 
        bzrlib.osutils._relpath do a simple but subtle
 | 
| 
1102
by Martin Pool
 - merge test refactoring from robertc  | 
112  | 
        job: given a path (either relative to cwd or absolute), work out
 | 
113  | 
        if it is inside a branch and return the path relative to the base.
 | 
|
114  | 
        """
 | 
|
| 
1457.1.2
by Robert Collins
 move branch._relpath into osutils as relpath  | 
115  | 
from bzrlib.osutils import relpath  | 
| 
601
by Martin Pool
 - whitebox tests for branch path handling  | 
116  | 
import tempfile, shutil  | 
117  | 
||
118  | 
savedir = os.getcwdu()  | 
|
119  | 
dtmp = tempfile.mkdtemp()  | 
|
| 
907.1.7
by John Arbash Meinel
 Fixed test failure on Mac OSX.  | 
120  | 
        # On Mac OSX, /tmp actually expands to /private/tmp
 | 
121  | 
dtmp = os.path.realpath(dtmp)  | 
|
| 
601
by Martin Pool
 - whitebox tests for branch path handling  | 
122  | 
|
123  | 
def rp(p):  | 
|
| 
1457.1.2
by Robert Collins
 move branch._relpath into osutils as relpath  | 
124  | 
return relpath(dtmp, p)  | 
| 
601
by Martin Pool
 - whitebox tests for branch path handling  | 
125  | 
|
126  | 
try:  | 
|
127  | 
            # check paths inside dtmp while standing outside it
 | 
|
128  | 
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')  | 
|
129  | 
||
130  | 
            # root = nothing
 | 
|
131  | 
self.assertEqual(rp(dtmp), '')  | 
|
132  | 
||
133  | 
self.assertRaises(NotBranchError,  | 
|
134  | 
rp,  | 
|
135  | 
'/etc')  | 
|
136  | 
||
137  | 
            # now some near-miss operations -- note that
 | 
|
138  | 
            # os.path.commonprefix gets these wrong!
 | 
|
139  | 
self.assertRaises(NotBranchError,  | 
|
140  | 
rp,  | 
|
141  | 
dtmp.rstrip('\\/') + '2')  | 
|
142  | 
||
143  | 
self.assertRaises(NotBranchError,  | 
|
144  | 
rp,  | 
|
145  | 
dtmp.rstrip('\\/') + '2/foo')  | 
|
146  | 
||
147  | 
            # now operations based on relpath of files in current
 | 
|
148  | 
            # directory, or nearby
 | 
|
149  | 
os.chdir(dtmp)  | 
|
150  | 
||
| 
1185.1.40
by Robert Collins
 Merge what applied of Alexander Belchenko's win32 patch.  | 
151  | 
FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')  | 
152  | 
self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)  | 
|
| 
601
by Martin Pool
 - whitebox tests for branch path handling  | 
153  | 
|
154  | 
self.assertEqual(rp('foo'), 'foo')  | 
|
155  | 
||
156  | 
self.assertEqual(rp('./foo'), 'foo')  | 
|
157  | 
||
158  | 
self.assertEqual(rp(os.path.abspath('foo')), 'foo')  | 
|
159  | 
||
160  | 
self.assertRaises(NotBranchError,  | 
|
161  | 
rp, '../foo')  | 
|
162  | 
||
163  | 
finally:  | 
|
164  | 
os.chdir(savedir)  | 
|
165  | 
shutil.rmtree(dtmp)  |