~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2012-03-20 02:40:57 UTC
  • Revision ID: aaron@aaronbentley.com-20120320024057-mqltf93xxs09r0ry
Compatibility fixes for bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import os.path
 
3
from unittest import makeSuite
 
4
 
 
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 (
 
9
    TestCaseWithTransport,
 
10
    )
 
11
from bzrlib.plugins.bzrtools import command
 
12
 
 
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
 
 
24
 
 
25
LzmaFeature = ModuleAvailableFeature("lzma")
 
26
 
 
27
 
 
28
class TestBzrTools(TestCaseWithTransport):
 
29
 
 
30
    def setUp(self):
 
31
        TestCaseWithTransport.setUp(self)
 
32
        command._testing = True
 
33
        self.addCleanup(command._stop_testing)
 
34
 
 
35
    @staticmethod
 
36
    def touch(filename):
 
37
        file(filename, 'wb').write('')
 
38
 
 
39
    def test_shelve(self):
 
40
        self.run_bzr('init')
 
41
        self.run_bzr('commit -m uc --unchanged')
 
42
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
 
43
        file('foo', 'wb').write('foo')
 
44
        self.run_bzr('add foo')
 
45
        self.run_bzr('commit -m foo')
 
46
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
 
47
 
 
48
    def test_fetch_ghosts(self):
 
49
        self.run_bzr('init')
 
50
        self.run_bzr('fetch-ghosts .')
 
51
 
 
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
 
 
57
    def test_patch(self):
 
58
        self.run_bzr('init')
 
59
        file('myfile', 'wb').write('hello')
 
60
        self.run_bzr('add')
 
61
        self.run_bzr('commit -m hello')
 
62
        file('myfile', 'wb').write('goodbye')
 
63
        file('mypatch', 'wb').write(self.run_bzr('diff', retcode=1)[0])
 
64
        self.run_bzr('revert')
 
65
        assert file('myfile', 'rb').read() == 'hello'
 
66
        self.run_bzr('patch --silent mypatch')
 
67
        assert file('myfile', 'rb').read() == 'goodbye'
 
68
 
 
69
    def test_branch_history(self):
 
70
        self.run_bzr('init')
 
71
        file('myfile', 'wb').write('hello')
 
72
        self.run_bzr('add')
 
73
        self.run_bzr('commit -m hello')
 
74
        self.run_bzr('branch-history')
 
75
 
 
76
    def test_branch_history(self):
 
77
        self.run_bzr('init')
 
78
        file('myfile', 'wb').write('hello')
 
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')
 
84
 
 
85
    def test_fetch_ghosts(self):
 
86
        self.run_bzr('init')
 
87
        file('myfile', 'wb').write('hello')
 
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')
 
92
 
 
93
    def test_zap(self):
 
94
        self.run_bzr('init source')
 
95
        self.run_bzr('checkout --lightweight source checkout')
 
96
        self.run_bzr('zap checkout')
 
97
        self.assertIs(False, os.path.exists('checkout'))
 
98
        self.assertIs(True, os.path.exists('source'))
 
99
 
 
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')
 
107
        self.assertPathExists('checkout')
 
108
        self.run_bzr('zap checkout --force')
 
109
        self.assertPathDoesNotExist('checkout')
 
110
        self.assertPathExists('source')
 
111
 
 
112
    def test_zap_branch(self):
 
113
        self.run_bzr('init source')
 
114
        self.run_bzr('checkout --lightweight source checkout')
 
115
        self.run_bzr('zap --branch checkout', retcode=3)
 
116
        self.assertIs(True, os.path.exists('checkout'))
 
117
        self.assertIs(True, os.path.exists('source'))
 
118
        self.run_bzr('branch source source2')
 
119
        self.run_bzr('checkout --lightweight source2 checkout2')
 
120
        self.run_bzr('zap --branch checkout2')
 
121
        self.assertIs(False, os.path.exists('checkout2'))
 
122
        self.assertIs(False, os.path.exists('source2'))
 
123
 
 
124
    def test_list_branches(self):
 
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')
 
130
        out = self.run_bzr('list-branches')[0]
 
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)
 
136
 
 
137
    def test_import_upstream(self):
 
138
        self.run_bzr('init source')
 
139
        os.mkdir('source/src')
 
140
        f = file('source/src/myfile', 'wb')
 
141
        f.write('hello?')
 
142
        f.close()
 
143
        os.chdir('source')
 
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')
 
150
        os.chdir('../import')
 
151
        self.run_bzr('import ../source-0.1.tar.gz')
 
152
        self.assertPathExists('src/myfile')
 
153
        result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
 
154
        self.assertContainsRe(result, 'Working tree has uncommitted changes')
 
155
        self.run_bzr('commit -m commit')
 
156
        self.run_bzr('import ../source-0.1.tar.gz')
 
157
        os.chdir('..')
 
158
        self.run_bzr('init import2')
 
159
        self.run_bzr('import source-0.1.tar.gz import2')
 
160
        self.assertPathExists('import2/src/myfile')
 
161
        self.run_bzr('import source-0.1.tar.gz import3')
 
162
        self.assertPathExists('import3/src/myfile')
 
163
        self.run_bzr('import source-0.1.tar.bz2 import4')
 
164
        self.assertPathExists('import4/src/myfile')
 
165
        self.run_bzr('import source-0.1 import5')
 
166
        self.assertPathExists('import5/src/myfile')
 
167
 
 
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
 
 
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)
 
201
        # Later formats don't support hardlinks.  Boo!
 
202
        source = self.make_branch_and_tree('source', format='1.9')
 
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
 
 
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
 
 
227
 
 
228
def test_suite():
 
229
    return makeSuite(TestBzrTools)