~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2011-09-25 01:18:55 UTC
  • mfrom: (776.2.1 unused-imports)
  • Revision ID: aaron@aaronbentley.com-20110925011855-3dil4ijgluvzq7q5
Remove unused imports, fix the importing of two error classes. (jelmer)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
from bzrlib import branch, osutils, workingtree
6
6
from bzrlib.config import LocationConfig
7
7
from bzrlib.transport import get_transport
8
 
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
 
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")
9
26
 
10
27
 
11
28
class TestBzrTools(TestCaseWithTransport):
 
29
 
 
30
    def setUp(self):
 
31
        TestCaseWithTransport.setUp(self)
 
32
        command._testing = True
 
33
        self.addCleanup(command._stop_testing)
 
34
 
12
35
    @staticmethod
13
36
    def touch(filename):
14
37
        file(filename, 'wb').write('')
15
38
 
16
 
    def test_clean_tree(self):
17
 
        self.run_bzr('init')
18
 
        self.run_bzr('ignore *~')
19
 
        self.run_bzr('ignore *.pyc')
20
 
        self.touch('name')
21
 
        self.touch('name~')
22
 
        assert os.path.lexists('name~')
23
 
        self.touch('name.pyc')
24
 
        self.run_bzr('clean-tree --force')
25
 
        assert os.path.lexists('name~')
26
 
        assert not os.path.lexists('name')
27
 
        self.touch('name')
28
 
        self.run_bzr('clean-tree --detritus --force')
29
 
        assert os.path.lexists('name')
30
 
        assert not os.path.lexists('name~')
31
 
        assert os.path.lexists('name.pyc')
32
 
        self.run_bzr('clean-tree --ignored --force')
33
 
        assert os.path.lexists('name')
34
 
        assert not os.path.lexists('name.pyc')
35
 
        self.run_bzr('clean-tree --unknown --force')
36
 
        assert not os.path.lexists('name')
37
 
        self.touch('name')
38
 
        self.touch('name~')
39
 
        self.touch('name.pyc')
40
 
        self.run_bzr('clean-tree --unknown --ignored --force')
41
 
        assert not os.path.lexists('name')
42
 
        assert not os.path.lexists('name~')
43
 
        assert not os.path.lexists('name.pyc')
44
 
 
45
39
    def test_shelve(self):
46
40
        self.run_bzr('init')
47
41
        self.run_bzr('commit -m uc --unchanged')
55
49
        self.run_bzr('init')
56
50
        self.run_bzr('fetch-ghosts .')
57
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
 
58
57
    def test_patch(self):
59
58
        self.run_bzr('init')
60
59
        file('myfile', 'wb').write('hello')
105
104
        checkout.add('file')
106
105
        self.run_bzr_error(('This checkout has uncommitted changes',),
107
106
                           'zap checkout')
108
 
        self.failUnlessExists('checkout')
 
107
        self.assertPathExists('checkout')
109
108
        self.run_bzr('zap checkout --force')
110
 
        self.failIfExists('checkout')
111
 
        self.failUnlessExists('source')
 
109
        self.assertPathDoesNotExist('checkout')
 
110
        self.assertPathExists('source')
112
111
 
113
112
    def test_zap_branch(self):
114
113
        self.run_bzr('init source')
150
149
        self.run_bzr('init ../import')
151
150
        os.chdir('../import')
152
151
        self.run_bzr('import ../source-0.1.tar.gz')
153
 
        self.failUnlessExists('src/myfile')
 
152
        self.assertPathExists('src/myfile')
154
153
        result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
155
154
        self.assertContainsRe(result, 'Working tree has uncommitted changes')
156
155
        self.run_bzr('commit -m commit')
158
157
        os.chdir('..')
159
158
        self.run_bzr('init import2')
160
159
        self.run_bzr('import source-0.1.tar.gz import2')
161
 
        self.failUnlessExists('import2/src/myfile')
 
160
        self.assertPathExists('import2/src/myfile')
162
161
        self.run_bzr('import source-0.1.tar.gz import3')
163
 
        self.failUnlessExists('import3/src/myfile')
 
162
        self.assertPathExists('import3/src/myfile')
164
163
        self.run_bzr('import source-0.1.tar.bz2 import4')
165
 
        self.failUnlessExists('import4/src/myfile')
 
164
        self.assertPathExists('import4/src/myfile')
166
165
        self.run_bzr('import source-0.1 import5')
167
 
        self.failUnlessExists('import5/src/myfile')
 
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')
168
185
 
169
186
    def test_cbranch(self):
170
187
        source = self.make_branch_and_tree('source')
181
198
 
182
199
    def test_cbranch_hardlink(self):
183
200
        self.requireFeature(HardlinkFeature)
184
 
        source = self.make_branch_and_tree('source')
 
201
        # Later formats don't support hardlinks.  Boo!
 
202
        source = self.make_branch_and_tree('source', format='1.9')
185
203
        self.build_tree(['source/file'])
186
204
        source.add('file')
187
205
        source.commit('added file')
198
216
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
199
217
                         os.lstat(source.abspath('file')).st_ino)
200
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
 
201
227
 
202
228
def test_suite():
203
229
    return makeSuite(TestBzrTools)