~abentley/bzrtools/bzrtools.dev

577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
1
import os
2
import os.path
3
from unittest import makeSuite
4
619 by Aaron Bentley
Add support for hard-link in cbranch
5
from bzrlib import branch, osutils, workingtree
6
from bzrlib.config import LocationConfig
7
from bzrlib.transport import get_transport
8
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
9
10
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
11
class TestBzrTools(TestCaseWithTransport):
241 by Aaron Bentley
Added blackbox tests for bzrtools
12
    @staticmethod
13
    def touch(filename):
14
        file(filename, 'wb').write('')
15
16
    def test_shelve(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
17
        self.run_bzr('init')
18
        self.run_bzr('commit -m uc --unchanged')
680 by Aaron Bentley
More shelf test fixes
19
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
338 by Aaron Bentley
Fixed shelf test case
20
        file('foo', 'wb').write('foo')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
21
        self.run_bzr('add foo')
22
        self.run_bzr('commit -m foo')
680 by Aaron Bentley
More shelf test fixes
23
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
241 by Aaron Bentley
Added blackbox tests for bzrtools
24
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
25
    def test_fetch_ghosts(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
26
        self.run_bzr('init')
27
        self.run_bzr('fetch-ghosts .')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
28
29
    def test_patch(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
30
        self.run_bzr('init')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
31
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
32
        self.run_bzr('add')
33
        self.run_bzr('commit -m hello')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
34
        file('myfile', 'wb').write('goodbye')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
35
        file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
36
        self.run_bzr('revert')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
37
        assert file('myfile', 'rb').read() == 'hello'
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
38
        self.run_bzr('patch --silent mypatch')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
39
        assert file('myfile', 'rb').read() == 'goodbye'
40
308 by Aaron Bentley
got branch-history under test
41
    def test_branch_history(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
42
        self.run_bzr('init')
308 by Aaron Bentley
got branch-history under test
43
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
44
        self.run_bzr('add')
45
        self.run_bzr('commit -m hello')
46
        self.run_bzr('branch-history')
308 by Aaron Bentley
got branch-history under test
47
309 by Aaron Bentley
Fixed graph-ancestry
48
    def test_branch_history(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
49
        self.run_bzr('init')
309 by Aaron Bentley
Fixed graph-ancestry
50
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
51
        self.run_bzr('add')
52
        self.run_bzr('commit -m hello')
53
        self.run_bzr('graph-ancestry . graph.dot')
54
        self.run_bzr('branch . my_branch')
55
        self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
56
310 by Aaron Bentley
Fixed fetch-ghosts
57
    def test_fetch_ghosts(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
58
        self.run_bzr('init')
310 by Aaron Bentley
Fixed fetch-ghosts
59
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
60
        self.run_bzr('add')
61
        self.run_bzr('commit -m hello')
62
        self.run_bzr('branch . my_branch')
63
        self.run_bzr('fetch-ghosts my_branch')
310 by Aaron Bentley
Fixed fetch-ghosts
64
345 by Aaron Bentley
Added zap command
65
    def test_zap(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
66
        self.run_bzr('init source')
67
        self.run_bzr('checkout --lightweight source checkout')
68
        self.run_bzr('zap checkout')
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
69
        self.assertIs(False, os.path.exists('checkout'))
70
        self.assertIs(True, os.path.exists('source'))
71
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
72
    def test_zap_modified(self):
73
        tree = self.make_branch_and_tree('source')
74
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
75
        self.build_tree(['checkout/file'])
76
        checkout.add('file')
77
        self.run_bzr_error(('This checkout has uncommitted changes',),
78
                           'zap checkout')
79
        self.failUnlessExists('checkout')
80
        self.run_bzr('zap checkout --force')
81
        self.failIfExists('checkout')
82
        self.failUnlessExists('source')
83
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
84
    def test_zap_branch(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
85
        self.run_bzr('init source')
86
        self.run_bzr('checkout --lightweight source checkout')
87
        self.run_bzr('zap --branch checkout', retcode=3)
407 by Aaron Bentley
Fix zap for checkouts of branches with no parents
88
        self.assertIs(True, os.path.exists('checkout'))
89
        self.assertIs(True, os.path.exists('source'))
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
90
        self.run_bzr('branch source source2')
91
        self.run_bzr('checkout --lightweight source2 checkout2')
92
        self.run_bzr('zap --branch checkout2')
407 by Aaron Bentley
Fix zap for checkouts of branches with no parents
93
        self.assertIs(False, os.path.exists('checkout2'))
94
        self.assertIs(False, os.path.exists('source2'))
345 by Aaron Bentley
Added zap command
95
352 by Aaron Bentley
Added branches subcommand
96
    def test_branches(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
97
        self.run_bzr('init source')
98
        self.run_bzr('init source/subsource')
99
        self.run_bzr('checkout --lightweight source checkout')
100
        self.run_bzr('init checkout/subcheckout')
101
        self.run_bzr('init checkout/.bzr/subcheckout')
102
        out = self.run_bzr('branches')[0]
352 by Aaron Bentley
Added branches subcommand
103
        lines = out.split('\n')
104
        self.assertIs(True, 'source' in lines)
105
        self.assertIs(True, 'source/subsource' in lines)
106
        self.assertIs(True, 'checkout/subcheckout' in lines)
107
        self.assertIs(True, 'checkout' not in lines)
345 by Aaron Bentley
Added zap command
108
377 by Aaron Bentley
Got import command working
109
    def test_import_upstream(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
110
        self.run_bzr('init source')
377 by Aaron Bentley
Got import command working
111
        os.mkdir('source/src')
112
        f = file('source/src/myfile', 'wb')
113
        f.write('hello?')
114
        f.close()
115
        os.chdir('source')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
116
        self.run_bzr('add')
117
        self.run_bzr('commit -m hello')
118
        self.run_bzr('export ../source-0.1.tar.gz')
119
        self.run_bzr('export ../source-0.1.tar.bz2')
120
        self.run_bzr('export ../source-0.1')
121
        self.run_bzr('init ../import')
377 by Aaron Bentley
Got import command working
122
        os.chdir('../import')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
123
        self.run_bzr('import ../source-0.1.tar.gz')
380 by Aaron Bentley
Got import working decently
124
        self.failUnlessExists('src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
125
        result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
378 by Aaron Bentley
Check for modified files
126
        self.assertContainsRe(result, 'Working tree has uncommitted changes')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
127
        self.run_bzr('commit -m commit')
128
        self.run_bzr('import ../source-0.1.tar.gz')
380 by Aaron Bentley
Got import working decently
129
        os.chdir('..')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
130
        self.run_bzr('init import2')
131
        self.run_bzr('import source-0.1.tar.gz import2')
380 by Aaron Bentley
Got import working decently
132
        self.failUnlessExists('import2/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
133
        self.run_bzr('import source-0.1.tar.gz import3')
380 by Aaron Bentley
Got import working decently
134
        self.failUnlessExists('import3/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
135
        self.run_bzr('import source-0.1.tar.bz2 import4')
384 by Aaron Bentley
Implement bzip support
136
        self.failUnlessExists('import4/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
137
        self.run_bzr('import source-0.1 import5')
489 by Aaron Bentley
import now imports directories
138
        self.failUnlessExists('import5/src/myfile')
377 by Aaron Bentley
Got import command working
139
619 by Aaron Bentley
Add support for hard-link in cbranch
140
    def test_cbranch(self):
141
        source = self.make_branch_and_tree('source')
142
        config = LocationConfig(osutils.abspath('target'))
143
        config.set_user_option('cbranch_target', 'target_branch')
144
        self.run_bzr('cbranch source target')
145
        checkout = workingtree.WorkingTree.open('target')
146
        self.assertEqual(checkout.branch.base,
147
                         get_transport('target').base)
148
        self.assertEqual(checkout.branch.get_master_branch().base,
149
                         get_transport('target_branch').base)
150
        self.assertEqual(checkout.branch.get_master_branch().get_parent(),
151
                         get_transport('source').base)
152
153
    def test_cbranch_hardlink(self):
154
        self.requireFeature(HardlinkFeature)
155
        source = self.make_branch_and_tree('source')
156
        self.build_tree(['source/file'])
157
        source.add('file')
158
        source.commit('added file')
159
        config = LocationConfig(osutils.abspath('target'))
160
        config.set_user_option('cbranch_target', 'target_branch')
161
        self.run_bzr('cbranch source target --lightweight')
162
        checkout = workingtree.WorkingTree.open('target')
163
        self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
164
                            os.lstat(source.abspath('file')).st_ino)
165
        config = LocationConfig(osutils.abspath('target2'))
166
        config.set_user_option('cbranch_target', 'target_branch2')
167
        self.run_bzr('cbranch source target2 --lightweight --hardlink')
168
        checkout2 = workingtree.WorkingTree.open('target2')
169
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
170
                         os.lstat(source.abspath('file')).st_ino)
171
626 by Aaron Bentley
cbranch creates parent directories as needed
172
241 by Aaron Bentley
Added blackbox tests for bzrtools
173
def test_suite():
174
    return makeSuite(TestBzrTools)