bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
601
by Martin Pool
- whitebox tests for branch path handling |
1 |
#! /usr/bin/python
|
2 |
||
|
768
by Martin Pool
- start some tests for directory renames |
3 |
import os |
4 |
import unittest |
|
5 |
||
6 |
from bzrlib.selftest import InTempDir, TestBase |
|
7 |
from bzrlib.branch import ScratchBranch, Branch |
|
|
778
by Martin Pool
- simple revert of text files |
8 |
from bzrlib.errors import NotBranchError, NotVersionedError |
9 |
||
10 |
||
11 |
class Revert(InTempDir): |
|
12 |
"""Test selected-file revert""" |
|
13 |
def runTest(self): |
|
14 |
b = Branch('.', init=True) |
|
15 |
||
16 |
self.build_tree(['hello.txt']) |
|
17 |
file('hello.txt', 'w').write('initial hello') |
|
18 |
||
19 |
self.assertRaises(NotVersionedError, |
|
20 |
b.revert, ['hello.txt']) |
|
21 |
||
22 |
b.add(['hello.txt']) |
|
23 |
b.commit('create initial hello.txt') |
|
24 |
||
25 |
self.check_file_contents('hello.txt', 'initial hello') |
|
26 |
file('hello.txt', 'w').write('new hello') |
|
27 |
self.check_file_contents('hello.txt', 'new hello') |
|
28 |
||
29 |
# revert file modified since last revision
|
|
30 |
b.revert(['hello.txt']) |
|
31 |
self.check_file_contents('hello.txt', 'initial hello') |
|
32 |
||
33 |
# reverting again causes no change
|
|
34 |
b.revert(['hello.txt']) |
|
35 |
self.check_file_contents('hello.txt', 'initial hello') |
|
36 |
||
|
768
by Martin Pool
- start some tests for directory renames |
37 |
|
38 |
||
39 |
class RenameDirs(InTempDir): |
|
40 |
"""Test renaming directories and the files within them.""" |
|
41 |
def runTest(self): |
|
42 |
b = Branch('.', init=True) |
|
43 |
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file']) |
|
44 |
b.add(['dir', 'dir/sub', 'dir/sub/file']) |
|
45 |
||
46 |
b.commit('create initial state') |
|
47 |
||
48 |
# TODO: lift out to a test helper that checks the shape of
|
|
49 |
# an inventory
|
|
50 |
||
51 |
revid = b.revision_history()[0] |
|
52 |
self.log('first revision_id is {%s}' % revid) |
|
53 |
||
54 |
inv = b.get_revision_inventory(revid) |
|
55 |
self.log('contents of inventory: %r' % inv.entries()) |
|
56 |
||
57 |
self.check_inventory_shape(inv, |
|
58 |
['dir', 'dir/sub', 'dir/sub/file']) |
|
59 |
||
|
771
by Martin Pool
- more tests of directory renames |
60 |
b.rename_one('dir', 'newdir') |
61 |
||
62 |
self.check_inventory_shape(b.inventory, |
|
63 |
['newdir', 'newdir/sub', 'newdir/sub/file']) |
|
64 |
||
65 |
b.rename_one('newdir/sub', 'newdir/newsub') |
|
66 |
self.check_inventory_shape(b.inventory, |
|
67 |
['newdir', 'newdir/newsub', |
|
68 |
'newdir/newsub/file']) |
|
69 |
||
|
768
by Martin Pool
- start some tests for directory renames |
70 |
|
71 |
||
72 |
||
73 |
class BranchPathTestCase(TestBase): |
|
|
601
by Martin Pool
- whitebox tests for branch path handling |
74 |
"""test for branch path lookups |
75 |
||
76 |
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
|
|
77 |
job: given a path (either relative to cwd or absolute), work out
|
|
78 |
if it is inside a branch and return the path relative to the base.
|
|
79 |
"""
|
|
|
768
by Martin Pool
- start some tests for directory renames |
80 |
|
|
601
by Martin Pool
- whitebox tests for branch path handling |
81 |
def runTest(self): |
82 |
from bzrlib.branch import _relpath |
|
83 |
import tempfile, shutil |
|
84 |
||
85 |
savedir = os.getcwdu() |
|
86 |
dtmp = tempfile.mkdtemp() |
|
87 |
||
88 |
def rp(p): |
|
89 |
return _relpath(dtmp, p) |
|
90 |
||
91 |
try: |
|
92 |
# check paths inside dtmp while standing outside it
|
|
93 |
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo') |
|
94 |
||
95 |
# root = nothing
|
|
96 |
self.assertEqual(rp(dtmp), '') |
|
97 |
||
98 |
self.assertRaises(NotBranchError, |
|
99 |
rp, |
|
100 |
'/etc') |
|
101 |
||
102 |
# now some near-miss operations -- note that
|
|
103 |
# os.path.commonprefix gets these wrong!
|
|
104 |
self.assertRaises(NotBranchError, |
|
105 |
rp, |
|
106 |
dtmp.rstrip('\\/') + '2') |
|
107 |
||
108 |
self.assertRaises(NotBranchError, |
|
109 |
rp, |
|
110 |
dtmp.rstrip('\\/') + '2/foo') |
|
111 |
||
112 |
# now operations based on relpath of files in current
|
|
113 |
# directory, or nearby
|
|
114 |
os.chdir(dtmp) |
|
115 |
||
116 |
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux') |
|
117 |
||
118 |
self.assertEqual(rp('foo'), 'foo') |
|
119 |
||
120 |
self.assertEqual(rp('./foo'), 'foo') |
|
121 |
||
122 |
self.assertEqual(rp(os.path.abspath('foo')), 'foo') |
|
123 |
||
124 |
self.assertRaises(NotBranchError, |
|
125 |
rp, '../foo') |
|
126 |
||
127 |
finally: |
|
128 |
os.chdir(savedir) |
|
129 |
shutil.rmtree(dtmp) |