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