/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/bzrdir_implementations/test_bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 05:53:44 UTC
  • mfrom: (2063 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006055344-e73b97b7c6ca6e72
[merge] bzr.dev 2063

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
 
24
24
import bzrlib.branch
25
 
import bzrlib.bzrdir as bzrdir
 
25
from bzrlib import (
 
26
    bzrdir,
 
27
    errors,
 
28
    lockdir,
 
29
    repository,
 
30
    transactions,
 
31
    transport,
 
32
    ui,
 
33
    workingtree,
 
34
    )
26
35
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
27
36
from bzrlib.check import check
28
 
import bzrlib.errors as errors
29
37
from bzrlib.errors import (FileExists,
30
38
                           NoSuchRevision,
31
39
                           NoSuchFile,
32
40
                           UninitializableFormat,
33
41
                           NotBranchError,
34
42
                           )
35
 
import bzrlib.repository as repository
36
43
import bzrlib.revision
37
44
from bzrlib.tests import (
38
45
                          ChrootedTestCase,
41
48
                          TestSkipped,
42
49
                          )
43
50
from bzrlib.trace import mutter
44
 
import bzrlib.transactions as transactions
45
 
import bzrlib.transport as transport
46
51
from bzrlib.transport import get_transport
47
 
import bzrlib.ui as ui
48
52
from bzrlib.upgrade import upgrade
49
 
import bzrlib.workingtree as workingtree
50
53
 
51
54
 
52
55
class TestCaseWithBzrDir(TestCaseWithTransport):
150
153
        wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
151
154
        self.assertEqual([], wt.get_parent_ids())
152
155
 
 
156
    def test_destroy_workingtree(self):
 
157
        tree = self.make_branch_and_tree('tree')
 
158
        self.build_tree(['tree/file'])
 
159
        tree.add('file')
 
160
        tree.commit('first commit')
 
161
        bzrdir = tree.bzrdir
 
162
        try:
 
163
            bzrdir.destroy_workingtree()
 
164
        except errors.UnsupportedOperation:
 
165
            raise TestSkipped('Format does not support destroying tree')
 
166
        self.failIfExists('tree/file')
 
167
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
168
        bzrdir.create_workingtree()
 
169
        self.failUnlessExists('tree/file')
 
170
        bzrdir.destroy_workingtree_metadata()
 
171
        self.failUnlessExists('tree/file')
 
172
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
173
            
153
174
    def test_clone_bzrdir_empty(self):
154
175
        dir = self.make_bzrdir('source')
155
176
        target = dir.clone(self.get_url('target'))
1317
1338
        unused_repo = thisdir.create_repository()
1318
1339
        master.lock_write()
1319
1340
        unused_repo.lock_write()
1320
 
        # two yes's : branch and repository. If the repo in this
1321
 
        # dir is inappropriately accessed, 3 will be needed, and
1322
 
        # we'll see that because the stream will be fully consumed
1323
 
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1324
 
        master.bzrdir.break_lock()
1325
 
        # only two ys should have been read
1326
 
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1327
 
        # we should be able to lock a newly opened branch now
1328
 
        branch = master.bzrdir.open_branch()
1329
 
        branch.lock_write()
1330
 
        branch.unlock()
1331
 
        # we should not be able to lock the repository in thisdir as its still
1332
 
        # held by the explicit lock we took, and the break lock should not have
1333
 
        # touched it.
1334
 
        repo = thisdir.open_repository()
1335
 
        self.assertRaises(errors.LockContention, repo.lock_write)
1336
 
        unused_repo.unlock()
 
1341
        try:
 
1342
            # two yes's : branch and repository. If the repo in this
 
1343
            # dir is inappropriately accessed, 3 will be needed, and
 
1344
            # we'll see that because the stream will be fully consumed
 
1345
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1346
            master.bzrdir.break_lock()
 
1347
            # only two ys should have been read
 
1348
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1349
            # we should be able to lock a newly opened branch now
 
1350
            branch = master.bzrdir.open_branch()
 
1351
            branch.lock_write()
 
1352
            branch.unlock()
 
1353
            # we should not be able to lock the repository in thisdir as its still
 
1354
            # held by the explicit lock we took, and the break lock should not have
 
1355
            # touched it.
 
1356
            repo = thisdir.open_repository()
 
1357
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
 
1358
            try:
 
1359
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
 
1360
                self.assertRaises(errors.LockContention, repo.lock_write)
 
1361
            finally:
 
1362
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
 
1363
        finally:
 
1364
            unused_repo.unlock()
1337
1365
        self.assertRaises(errors.LockBroken, master.unlock)
1338
1366
 
1339
1367
    def test_break_lock_tree(self):