~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2011-04-12 04:51:37 UTC
  • Revision ID: aaron@aaronbentley.com-20110412045137-ni3eart33v4wnlst
Allow zap --branch --store if no uncommitted changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import os.path
3
3
from unittest import makeSuite
4
4
 
5
 
from bzrlib import branch
6
 
from bzrlib.tests import TestCaseWithTransport
 
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 TestCaseWithTransport, HardlinkFeature
 
9
from bzrlib.plugins.bzrtools import command
7
10
 
8
11
 
9
12
class TestBzrTools(TestCaseWithTransport):
 
13
 
 
14
    def setUp(self):
 
15
        TestCaseWithTransport.setUp(self)
 
16
        command._testing = True
 
17
        self.addCleanup(command._stop_testing)
 
18
 
10
19
    @staticmethod
11
20
    def touch(filename):
12
21
        file(filename, 'wb').write('')
13
22
 
14
 
    def test_clean_tree(self):
15
 
        self.run_bzr('init')
16
 
        self.run_bzr('ignore *~')
17
 
        self.run_bzr('ignore *.pyc')
18
 
        self.touch('name')
19
 
        self.touch('name~')
20
 
        assert os.path.lexists('name~')
21
 
        self.touch('name.pyc')
22
 
        self.run_bzr('clean-tree')
23
 
        assert os.path.lexists('name~')
24
 
        assert not os.path.lexists('name')
25
 
        self.touch('name')
26
 
        self.run_bzr('clean-tree --detritus')
27
 
        assert os.path.lexists('name')
28
 
        assert not os.path.lexists('name~')
29
 
        assert os.path.lexists('name.pyc')
30
 
        self.run_bzr('clean-tree --ignored')
31
 
        assert os.path.lexists('name')
32
 
        assert not os.path.lexists('name.pyc')
33
 
        self.run_bzr('clean-tree --unknown')
34
 
        assert not os.path.lexists('name')
35
 
        self.touch('name')
36
 
        self.touch('name~')
37
 
        self.touch('name.pyc')
38
 
        self.run_bzr('clean-tree --unknown --ignored')
39
 
        assert not os.path.lexists('name')
40
 
        assert not os.path.lexists('name~')
41
 
        assert not os.path.lexists('name.pyc')
42
 
 
43
23
    def test_shelve(self):
44
24
        self.run_bzr('init')
45
25
        self.run_bzr('commit -m uc --unchanged')
46
 
        self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
 
26
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
47
27
        file('foo', 'wb').write('foo')
48
28
        self.run_bzr('add foo')
49
29
        self.run_bzr('commit -m foo')
50
 
        self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
 
30
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
51
31
 
52
32
    def test_fetch_ghosts(self):
53
33
        self.run_bzr('init')
54
34
        self.run_bzr('fetch-ghosts .')
55
35
 
 
36
    def test_fetch_ghosts_with_saved(self):
 
37
        wt = self.make_branch_and_tree('.')
 
38
        wt.branch.set_parent('.')
 
39
        self.run_bzr('fetch-ghosts')
 
40
 
56
41
    def test_patch(self):
57
42
        self.run_bzr('init')
58
43
        file('myfile', 'wb').write('hello')
164
149
        self.run_bzr('import source-0.1 import5')
165
150
        self.failUnlessExists('import5/src/myfile')
166
151
 
 
152
    def test_cbranch(self):
 
153
        source = self.make_branch_and_tree('source')
 
154
        config = LocationConfig(osutils.abspath('target'))
 
155
        config.set_user_option('cbranch_target', 'target_branch')
 
156
        self.run_bzr('cbranch source target')
 
157
        checkout = workingtree.WorkingTree.open('target')
 
158
        self.assertEqual(checkout.branch.base,
 
159
                         get_transport('target').base)
 
160
        self.assertEqual(checkout.branch.get_master_branch().base,
 
161
                         get_transport('target_branch').base)
 
162
        self.assertEqual(checkout.branch.get_master_branch().get_parent(),
 
163
                         get_transport('source').base)
 
164
 
 
165
    def test_cbranch_hardlink(self):
 
166
        self.requireFeature(HardlinkFeature)
 
167
        # Later formats don't support hardlinks.  Boo!
 
168
        source = self.make_branch_and_tree('source', format='1.9')
 
169
        self.build_tree(['source/file'])
 
170
        source.add('file')
 
171
        source.commit('added file')
 
172
        config = LocationConfig(osutils.abspath('target'))
 
173
        config.set_user_option('cbranch_target', 'target_branch')
 
174
        self.run_bzr('cbranch source target --lightweight')
 
175
        checkout = workingtree.WorkingTree.open('target')
 
176
        self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
 
177
                            os.lstat(source.abspath('file')).st_ino)
 
178
        config = LocationConfig(osutils.abspath('target2'))
 
179
        config.set_user_option('cbranch_target', 'target_branch2')
 
180
        self.run_bzr('cbranch source target2 --lightweight --hardlink')
 
181
        checkout2 = workingtree.WorkingTree.open('target2')
 
182
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
 
183
                         os.lstat(source.abspath('file')).st_ino)
 
184
 
 
185
    def test_create_mirror(self):
 
186
        source = self.make_branch_and_tree('source')
 
187
        source.commit('message')
 
188
        self.run_bzr('create-mirror source target')
 
189
        target = branch.Branch.open('target')
 
190
        self.assertEqual(source.last_revision(), target.last_revision())
 
191
        self.assertEqual(source.branch.base, target.get_public_branch())
 
192
 
 
193
 
167
194
def test_suite():
168
195
    return makeSuite(TestBzrTools)