~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/blackbox.py

  • Committer: Aaron Bentley
  • Date: 2009-04-10 21:11:45 UTC
  • Revision ID: aaron@aaronbentley.com-20090410211145-ibc2ispf7uw2rwg9
Tags: release-1.14.0
Update NEWS for release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from bzrlib.tests.blackbox import ExternalBase
 
1
import os
 
2
import os.path
2
3
from unittest import makeSuite
3
 
import os.path
4
 
class TestBzrTools(ExternalBase):
 
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 TestCaseWithTransport, HardlinkFeature
 
9
 
 
10
 
 
11
class TestBzrTools(TestCaseWithTransport):
5
12
    @staticmethod
6
13
    def touch(filename):
7
14
        file(filename, 'wb').write('')
8
15
 
9
 
    def test_clean_tree(self):
10
 
        self.run_bzr('init')
11
 
        self.run_bzr('ignore *~')
12
 
        self.run_bzr('ignore *.pyc')
13
 
        self.touch('name')
14
 
        self.touch('name~')
15
 
        assert os.path.lexists('name~')
16
 
        self.touch('name.pyc')
17
 
        self.run_bzr('clean-tree')
18
 
        assert os.path.lexists('name~')
19
 
        assert not os.path.lexists('name')
20
 
        self.touch('name')
21
 
        self.run_bzr('clean-tree --detritus')
22
 
        assert os.path.lexists('name')
23
 
        assert not os.path.lexists('name~')
24
 
        assert os.path.lexists('name.pyc')
25
 
        self.run_bzr('clean-tree --ignored')
26
 
        assert os.path.lexists('name')
27
 
        assert not os.path.lexists('name.pyc')
28
 
        self.run_bzr('clean-tree --unknown')
29
 
        assert not os.path.lexists('name')
30
 
        self.touch('name')
31
 
        self.touch('name~')
32
 
        self.touch('name.pyc')
33
 
        self.run_bzr('clean-tree --unknown --ignored')
34
 
        assert not os.path.lexists('name')
35
 
        assert not os.path.lexists('name~')
36
 
        assert not os.path.lexists('name.pyc')
37
 
 
38
16
    def test_shelve(self):
39
17
        self.run_bzr('init')
40
18
        self.run_bzr('commit -m uc --unchanged')
41
 
        self.run_bzr('shelve -r 1 -m foo --all', retcode=3)
 
19
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=3)
42
20
        file('foo', 'wb').write('foo')
43
21
        self.run_bzr('add foo')
44
22
        self.run_bzr('commit -m foo')
45
 
        self.run_bzr('shelve -r 1 -m foo --all', retcode=0)
 
23
        self.run_bzr('shelve1 -r 1 -m foo --all', retcode=0)
46
24
 
47
25
    def test_fetch_ghosts(self):
48
26
        self.run_bzr('init')
91
69
        self.assertIs(False, os.path.exists('checkout'))
92
70
        self.assertIs(True, os.path.exists('source'))
93
71
 
 
72
    def test_zap_modified(self):
 
73
        tree = self.make_branch_and_tree('source')
 
74
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
75
        self.build_tree(['checkout/file'])
 
76
        checkout.add('file')
 
77
        self.run_bzr_error(('This checkout has uncommitted changes',),
 
78
                           'zap checkout')
 
79
        self.failUnlessExists('checkout')
 
80
        self.run_bzr('zap checkout --force')
 
81
        self.failIfExists('checkout')
 
82
        self.failUnlessExists('source')
 
83
 
94
84
    def test_zap_branch(self):
95
85
        self.run_bzr('init source')
96
86
        self.run_bzr('checkout --lightweight source checkout')
115
105
        self.assertIs(True, 'source/subsource' in lines)
116
106
        self.assertIs(True, 'checkout/subcheckout' in lines)
117
107
        self.assertIs(True, 'checkout' not in lines)
118
 
        self.assertIs(True, 'checkout/.bzr/subcheckout' not in lines)
119
108
 
120
109
    def test_import_upstream(self):
121
110
        self.run_bzr('init source')
148
137
        self.run_bzr('import source-0.1 import5')
149
138
        self.failUnlessExists('import5/src/myfile')
150
139
 
 
140
    def test_cbranch(self):
 
141
        source = self.make_branch_and_tree('source')
 
142
        config = LocationConfig(osutils.abspath('target'))
 
143
        config.set_user_option('cbranch_target', 'target_branch')
 
144
        self.run_bzr('cbranch source target')
 
145
        checkout = workingtree.WorkingTree.open('target')
 
146
        self.assertEqual(checkout.branch.base,
 
147
                         get_transport('target').base)
 
148
        self.assertEqual(checkout.branch.get_master_branch().base,
 
149
                         get_transport('target_branch').base)
 
150
        self.assertEqual(checkout.branch.get_master_branch().get_parent(),
 
151
                         get_transport('source').base)
 
152
 
 
153
    def test_cbranch_hardlink(self):
 
154
        self.requireFeature(HardlinkFeature)
 
155
        source = self.make_branch_and_tree('source')
 
156
        self.build_tree(['source/file'])
 
157
        source.add('file')
 
158
        source.commit('added file')
 
159
        config = LocationConfig(osutils.abspath('target'))
 
160
        config.set_user_option('cbranch_target', 'target_branch')
 
161
        self.run_bzr('cbranch source target --lightweight')
 
162
        checkout = workingtree.WorkingTree.open('target')
 
163
        self.assertNotEqual(os.lstat(checkout.abspath('file')).st_ino,
 
164
                            os.lstat(source.abspath('file')).st_ino)
 
165
        config = LocationConfig(osutils.abspath('target2'))
 
166
        config.set_user_option('cbranch_target', 'target_branch2')
 
167
        self.run_bzr('cbranch source target2 --lightweight --hardlink')
 
168
        checkout2 = workingtree.WorkingTree.open('target2')
 
169
        self.assertEqual(os.lstat(checkout2.abspath('file')).st_ino,
 
170
                         os.lstat(source.abspath('file')).st_ino)
 
171
 
 
172
 
151
173
def test_suite():
152
174
    return makeSuite(TestBzrTools)