~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
770.1.1 by Jelmer Vernooij
Add support for importing .tar.xz and .tar.lzma files.
8
from bzrlib.tests import (
9
    HardlinkFeature,
10
    ModuleAvailableFeature,
11
    TestCaseWithTransport,
12
    )
730.1.5 by Aaron Bentley
Disable version check for commands run in the test suite.
13
from bzrlib.plugins.bzrtools import command
577.1.1 by Aaron Bentley
bzr switch works when the source branch is renamed
14
15
770.1.1 by Jelmer Vernooij
Add support for importing .tar.xz and .tar.lzma files.
16
LzmaFeature = ModuleAvailableFeature("lzma")
17
18
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
19
class TestBzrTools(TestCaseWithTransport):
730.1.5 by Aaron Bentley
Disable version check for commands run in the test suite.
20
21
    def setUp(self):
22
        TestCaseWithTransport.setUp(self)
23
        command._testing = True
24
        self.addCleanup(command._stop_testing)
25
241 by Aaron Bentley
Added blackbox tests for bzrtools
26
    @staticmethod
27
    def touch(filename):
28
        file(filename, 'wb').write('')
29
30
    def test_shelve(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
31
        self.run_bzr('init')
32
        self.run_bzr('commit -m uc --unchanged')
680 by Aaron Bentley
More shelf test fixes
33
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
338 by Aaron Bentley
Fixed shelf test case
34
        file('foo', 'wb').write('foo')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
35
        self.run_bzr('add foo')
36
        self.run_bzr('commit -m foo')
680 by Aaron Bentley
More shelf test fixes
37
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
241 by Aaron Bentley
Added blackbox tests for bzrtools
38
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
39
    def test_fetch_ghosts(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
40
        self.run_bzr('init')
41
        self.run_bzr('fetch-ghosts .')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
42
730.1.2 by Aaron Bentley
Add tests for fetch-ghosts fix.
43
    def test_fetch_ghosts_with_saved(self):
44
        wt = self.make_branch_and_tree('.')
45
        wt.branch.set_parent('.')
46
        self.run_bzr('fetch-ghosts')
47
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
48
    def test_patch(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
49
        self.run_bzr('init')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
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')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
53
        file('myfile', 'wb').write('goodbye')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
54
        file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
55
        self.run_bzr('revert')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
56
        assert file('myfile', 'rb').read() == 'hello'
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
57
        self.run_bzr('patch --silent mypatch')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
58
        assert file('myfile', 'rb').read() == 'goodbye'
59
308 by Aaron Bentley
got branch-history under test
60
    def test_branch_history(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
61
        self.run_bzr('init')
308 by Aaron Bentley
got branch-history under test
62
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
63
        self.run_bzr('add')
64
        self.run_bzr('commit -m hello')
65
        self.run_bzr('branch-history')
308 by Aaron Bentley
got branch-history under test
66
309 by Aaron Bentley
Fixed graph-ancestry
67
    def test_branch_history(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
68
        self.run_bzr('init')
309 by Aaron Bentley
Fixed graph-ancestry
69
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
70
        self.run_bzr('add')
71
        self.run_bzr('commit -m hello')
72
        self.run_bzr('graph-ancestry . graph.dot')
73
        self.run_bzr('branch . my_branch')
74
        self.run_bzr('graph-ancestry . graph.dot --merge-branch my_branch')
242 by Aaron Bentley
Added tests for patch and fetch-ghosts
75
310 by Aaron Bentley
Fixed fetch-ghosts
76
    def test_fetch_ghosts(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
77
        self.run_bzr('init')
310 by Aaron Bentley
Fixed fetch-ghosts
78
        file('myfile', 'wb').write('hello')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
79
        self.run_bzr('add')
80
        self.run_bzr('commit -m hello')
81
        self.run_bzr('branch . my_branch')
82
        self.run_bzr('fetch-ghosts my_branch')
310 by Aaron Bentley
Fixed fetch-ghosts
83
345 by Aaron Bentley
Added zap command
84
    def test_zap(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 checkout')
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
88
        self.assertIs(False, os.path.exists('checkout'))
89
        self.assertIs(True, os.path.exists('source'))
90
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
91
    def test_zap_modified(self):
92
        tree = self.make_branch_and_tree('source')
93
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
94
        self.build_tree(['checkout/file'])
95
        checkout.add('file')
96
        self.run_bzr_error(('This checkout has uncommitted changes',),
97
                           'zap checkout')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
98
        self.assertPathExists('checkout')
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
99
        self.run_bzr('zap checkout --force')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
100
        self.assertPathDoesNotExist('checkout')
101
        self.assertPathExists('source')
573.1.3 by Aaron Bentley
Allow zap --force to delete modified checkouts
102
355.1.1 by Aaron Bentley
Provided --branch option to for zapping branches
103
    def test_zap_branch(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
104
        self.run_bzr('init source')
105
        self.run_bzr('checkout --lightweight source checkout')
106
        self.run_bzr('zap --branch checkout', retcode=3)
407 by Aaron Bentley
Fix zap for checkouts of branches with no parents
107
        self.assertIs(True, os.path.exists('checkout'))
108
        self.assertIs(True, os.path.exists('source'))
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
109
        self.run_bzr('branch source source2')
110
        self.run_bzr('checkout --lightweight source2 checkout2')
111
        self.run_bzr('zap --branch checkout2')
407 by Aaron Bentley
Fix zap for checkouts of branches with no parents
112
        self.assertIs(False, os.path.exists('checkout2'))
113
        self.assertIs(False, os.path.exists('source2'))
345 by Aaron Bentley
Added zap command
114
352 by Aaron Bentley
Added branches subcommand
115
    def test_branches(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
116
        self.run_bzr('init source')
117
        self.run_bzr('init source/subsource')
118
        self.run_bzr('checkout --lightweight source checkout')
119
        self.run_bzr('init checkout/subcheckout')
120
        self.run_bzr('init checkout/.bzr/subcheckout')
121
        out = self.run_bzr('branches')[0]
352 by Aaron Bentley
Added branches subcommand
122
        lines = out.split('\n')
123
        self.assertIs(True, 'source' in lines)
124
        self.assertIs(True, 'source/subsource' in lines)
125
        self.assertIs(True, 'checkout/subcheckout' in lines)
126
        self.assertIs(True, 'checkout' not in lines)
345 by Aaron Bentley
Added zap command
127
377 by Aaron Bentley
Got import command working
128
    def test_import_upstream(self):
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
129
        self.run_bzr('init source')
377 by Aaron Bentley
Got import command working
130
        os.mkdir('source/src')
131
        f = file('source/src/myfile', 'wb')
132
        f.write('hello?')
133
        f.close()
134
        os.chdir('source')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
135
        self.run_bzr('add')
136
        self.run_bzr('commit -m hello')
137
        self.run_bzr('export ../source-0.1.tar.gz')
138
        self.run_bzr('export ../source-0.1.tar.bz2')
139
        self.run_bzr('export ../source-0.1')
140
        self.run_bzr('init ../import')
377 by Aaron Bentley
Got import command working
141
        os.chdir('../import')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
142
        self.run_bzr('import ../source-0.1.tar.gz')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
143
        self.assertPathExists('src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
144
        result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
378 by Aaron Bentley
Check for modified files
145
        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).
146
        self.run_bzr('commit -m commit')
147
        self.run_bzr('import ../source-0.1.tar.gz')
380 by Aaron Bentley
Got import working decently
148
        os.chdir('..')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
149
        self.run_bzr('init import2')
150
        self.run_bzr('import source-0.1.tar.gz import2')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
151
        self.assertPathExists('import2/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
152
        self.run_bzr('import source-0.1.tar.gz import3')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
153
        self.assertPathExists('import3/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
154
        self.run_bzr('import source-0.1.tar.bz2 import4')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
155
        self.assertPathExists('import4/src/myfile')
548.1.1 by Vincent Ladeuil
Cleanup blackbox test following recent Martin's patch (bzr.dev@2555).
156
        self.run_bzr('import source-0.1 import5')
762 by Aaron Bentley
Eschew failIfExists/failUnlessExists.
157
        self.assertPathExists('import5/src/myfile')
377 by Aaron Bentley
Got import command working
158
770.1.1 by Jelmer Vernooij
Add support for importing .tar.xz and .tar.lzma files.
159
    def test_import_upstream_lzma(self):
160
        self.requireFeature(LzmaFeature)
161
        self.run_bzr('init source')
162
        os.mkdir('source/src')
163
        f = file('source/src/myfile', 'wb')
164
        f.write('hello?')
165
        f.close()
166
        os.chdir('source')
167
        self.run_bzr('add')
168
        self.run_bzr('commit -m hello')
169
        self.run_bzr('export ../source-0.1.tar.lzma')
170
        self.run_bzr('export ../source-0.1.tar.xz')
171
        os.chdir('..')
172
        self.run_bzr('import source-0.1.tar.lzma import1')
173
        self.assertPathExists('import1/src/myfile')
174
        self.run_bzr('import source-0.1.tar.xz import2')
175
        self.assertPathExists('import2/src/myfile')
176
619 by Aaron Bentley
Add support for hard-link in cbranch
177
    def test_cbranch(self):
178
        source = self.make_branch_and_tree('source')
179
        config = LocationConfig(osutils.abspath('target'))
180
        config.set_user_option('cbranch_target', 'target_branch')
181
        self.run_bzr('cbranch source target')
182
        checkout = workingtree.WorkingTree.open('target')
183
        self.assertEqual(checkout.branch.base,
184
                         get_transport('target').base)
185
        self.assertEqual(checkout.branch.get_master_branch().base,
186
                         get_transport('target_branch').base)
187
        self.assertEqual(checkout.branch.get_master_branch().get_parent(),
188
                         get_transport('source').base)
189
190
    def test_cbranch_hardlink(self):
191
        self.requireFeature(HardlinkFeature)
721 by Aaron Bentley
Fix test that fails with 2a format.
192
        # Later formats don't support hardlinks.  Boo!
193
        source = self.make_branch_and_tree('source', format='1.9')
619 by Aaron Bentley
Add support for hard-link in cbranch
194
        self.build_tree(['source/file'])
195
        source.add('file')
196
        source.commit('added file')
197
        config = LocationConfig(osutils.abspath('target'))
198
        config.set_user_option('cbranch_target', 'target_branch')
199
        self.run_bzr('cbranch source target --lightweight')
200
        checkout = workingtree.WorkingTree.open('target')
201
        self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
202
                            os.lstat(source.abspath('file')).st_ino)
203
        config = LocationConfig(osutils.abspath('target2'))
204
        config.set_user_option('cbranch_target', 'target_branch2')
205
        self.run_bzr('cbranch source target2 --lightweight --hardlink')
206
        checkout2 = workingtree.WorkingTree.open('target2')
207
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
208
                         os.lstat(source.abspath('file')).st_ino)
209
711 by Aaron Bentley
Implement create-mirror command
210
    def test_create_mirror(self):
211
        source = self.make_branch_and_tree('source')
212
        source.commit('message')
213
        self.run_bzr('create-mirror source target')
214
        target = branch.Branch.open('target')
215
        self.assertEqual(source.last_revision(), target.last_revision())
216
        self.assertEqual(source.branch.base, target.get_public_branch())
217
626 by Aaron Bentley
cbranch creates parent directories as needed
218
241 by Aaron Bentley
Added blackbox tests for bzrtools
219
def test_suite():
220
    return makeSuite(TestBzrTools)