~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2008-11-12 17:09:36 UTC
  • Revision ID: aaron@aaronbentley.com-20081112170936-3dybsv7il8gxhchz
Use bzrlib's getchar

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 (
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")
 
8
from bzrlib.tests import TestCaseWithTransport, HardlinkFeature
26
9
 
27
10
 
28
11
class TestBzrTools(TestCaseWithTransport):
29
 
 
30
 
    def setUp(self):
31
 
        TestCaseWithTransport.setUp(self)
32
 
        command._testing = True
33
 
        self.addCleanup(command._stop_testing)
34
 
 
35
12
    @staticmethod
36
13
    def touch(filename):
37
14
        file(filename, 'wb').write('')
38
15
 
 
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
 
39
45
    def test_shelve(self):
40
46
        self.run_bzr('init')
41
47
        self.run_bzr('commit -m uc --unchanged')
49
55
        self.run_bzr('init')
50
56
        self.run_bzr('fetch-ghosts .')
51
57
 
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
58
    def test_patch(self):
58
59
        self.run_bzr('init')
59
60
        file('myfile', 'wb').write('hello')
104
105
        checkout.add('file')
105
106
        self.run_bzr_error(('This checkout has uncommitted changes',),
106
107
                           'zap checkout')
107
 
        self.assertPathExists('checkout')
 
108
        self.failUnlessExists('checkout')
108
109
        self.run_bzr('zap checkout --force')
109
 
        self.assertPathDoesNotExist('checkout')
110
 
        self.assertPathExists('source')
 
110
        self.failIfExists('checkout')
 
111
        self.failUnlessExists('source')
111
112
 
112
113
    def test_zap_branch(self):
113
114
        self.run_bzr('init source')
121
122
        self.assertIs(False, os.path.exists('checkout2'))
122
123
        self.assertIs(False, os.path.exists('source2'))
123
124
 
124
 
    def test_list_branches(self):
 
125
    def test_branches(self):
125
126
        self.run_bzr('init source')
126
127
        self.run_bzr('init source/subsource')
127
128
        self.run_bzr('checkout --lightweight source checkout')
128
129
        self.run_bzr('init checkout/subcheckout')
129
130
        self.run_bzr('init checkout/.bzr/subcheckout')
130
 
        out = self.run_bzr('list-branches')[0]
 
131
        out = self.run_bzr('branches')[0]
131
132
        lines = out.split('\n')
132
133
        self.assertIs(True, 'source' in lines)
133
134
        self.assertIs(True, 'source/subsource' in lines)
149
150
        self.run_bzr('init ../import')
150
151
        os.chdir('../import')
151
152
        self.run_bzr('import ../source-0.1.tar.gz')
152
 
        self.assertPathExists('src/myfile')
 
153
        self.failUnlessExists('src/myfile')
153
154
        result = self.run_bzr('import ../source-0.1.tar.gz', retcode=3)[1]
154
155
        self.assertContainsRe(result, 'Working tree has uncommitted changes')
155
156
        self.run_bzr('commit -m commit')
157
158
        os.chdir('..')
158
159
        self.run_bzr('init import2')
159
160
        self.run_bzr('import source-0.1.tar.gz import2')
160
 
        self.assertPathExists('import2/src/myfile')
 
161
        self.failUnlessExists('import2/src/myfile')
161
162
        self.run_bzr('import source-0.1.tar.gz import3')
162
 
        self.assertPathExists('import3/src/myfile')
 
163
        self.failUnlessExists('import3/src/myfile')
163
164
        self.run_bzr('import source-0.1.tar.bz2 import4')
164
 
        self.assertPathExists('import4/src/myfile')
 
165
        self.failUnlessExists('import4/src/myfile')
165
166
        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')
 
167
        self.failUnlessExists('import5/src/myfile')
185
168
 
186
169
    def test_cbranch(self):
187
170
        source = self.make_branch_and_tree('source')
198
181
 
199
182
    def test_cbranch_hardlink(self):
200
183
        self.requireFeature(HardlinkFeature)
201
 
        # Later formats don't support hardlinks.  Boo!
202
 
        source = self.make_branch_and_tree('source', format='1.9')
 
184
        source = self.make_branch_and_tree('source')
203
185
        self.build_tree(['source/file'])
204
186
        source.add('file')
205
187
        source.commit('added file')
216
198
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
217
199
                         os.lstat(source.abspath('file')).st_ino)
218
200
 
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
201
 
228
202
def test_suite():
229
203
    return makeSuite(TestBzrTools)