/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: Aaron Bentley
  • Date: 2006-11-17 04:06:03 UTC
  • mfrom: (2139 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2162.
  • Revision ID: aaron.bentley@utoronto.ca-20061117040603-pgebxndswvwk26tt
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import errno
20
21
import os
21
22
from stat import S_ISDIR
22
23
import sys
23
24
 
24
25
import bzrlib.branch
25
 
import bzrlib.bzrdir as bzrdir
 
26
from bzrlib import (
 
27
    bzrdir,
 
28
    errors,
 
29
    lockdir,
 
30
    repository,
 
31
    transactions,
 
32
    transport,
 
33
    ui,
 
34
    workingtree,
 
35
    )
26
36
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
27
37
from bzrlib.check import check
28
 
import bzrlib.errors as errors
29
38
from bzrlib.errors import (FileExists,
30
39
                           NoSuchRevision,
31
40
                           NoSuchFile,
32
41
                           UninitializableFormat,
33
42
                           NotBranchError,
34
43
                           )
35
 
import bzrlib.repository as repository
36
44
import bzrlib.revision
37
45
from bzrlib.tests import (
38
46
                          ChrootedTestCase,
41
49
                          TestSkipped,
42
50
                          )
43
51
from bzrlib.trace import mutter
44
 
import bzrlib.transactions as transactions
45
 
import bzrlib.transport as transport
46
52
from bzrlib.transport import get_transport
47
 
import bzrlib.ui as ui
48
53
from bzrlib.upgrade import upgrade
49
 
import bzrlib.workingtree as workingtree
50
54
 
51
55
 
52
56
class TestCaseWithBzrDir(TestCaseWithTransport):
150
154
        wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
151
155
        self.assertEqual([], wt.get_parent_ids())
152
156
 
 
157
    def test_destroy_workingtree(self):
 
158
        tree = self.make_branch_and_tree('tree')
 
159
        self.build_tree(['tree/file'])
 
160
        tree.add('file')
 
161
        tree.commit('first commit')
 
162
        bzrdir = tree.bzrdir
 
163
        try:
 
164
            bzrdir.destroy_workingtree()
 
165
        except errors.UnsupportedOperation:
 
166
            raise TestSkipped('Format does not support destroying tree')
 
167
        self.failIfExists('tree/file')
 
168
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
169
        bzrdir.create_workingtree()
 
170
        self.failUnlessExists('tree/file')
 
171
        bzrdir.destroy_workingtree_metadata()
 
172
        self.failUnlessExists('tree/file')
 
173
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
 
174
            
153
175
    def test_clone_bzrdir_empty(self):
154
176
        dir = self.make_bzrdir('source')
155
177
        target = dir.clone(self.get_url('target'))
515
537
        repo = dir.create_repository()
516
538
        repo.fetch(tree.branch.repository)
517
539
        self.assertTrue(repo.has_revision('1'))
 
540
        try:
 
541
            self.assertIs(dir.open_branch().last_revision(), None)
 
542
        except errors.NotBranchError:
 
543
            pass
518
544
        target = self.sproutOrSkip(dir, self.get_url('target'))
519
545
        self.assertNotEqual(dir.transport.base, target.transport.base)
 
546
        # testing inventory isn't reasonable for repositories
520
547
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
521
548
                                    ['./.bzr/repository/inventory.knit',
 
549
                                     './.bzr/inventory'
522
550
                                     ])
 
551
        try:
 
552
            # If we happen to have a tree, we'll guarantee everything
 
553
            # except for the tree root is the same.
 
554
            inventory_f = file(dir.transport.base+'inventory', 'rb')
 
555
            self.assertContainsRe(inventory_f.read(), 
 
556
                                  '<inventory file_id="TREE_ROOT[^"]*"'
 
557
                                  ' format="5">\n</inventory>\n')
 
558
            inventory_f.close()
 
559
        except IOError, e:
 
560
            if e.errno != errno.ENOENT:
 
561
                raise
523
562
 
524
563
    def test_sprout_bzrdir_with_repository_to_shared(self):
525
564
        tree = self.make_branch_and_tree('commit_tree')
1317
1356
        unused_repo = thisdir.create_repository()
1318
1357
        master.lock_write()
1319
1358
        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()
 
1359
        try:
 
1360
            # two yes's : branch and repository. If the repo in this
 
1361
            # dir is inappropriately accessed, 3 will be needed, and
 
1362
            # we'll see that because the stream will be fully consumed
 
1363
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
 
1364
            master.bzrdir.break_lock()
 
1365
            # only two ys should have been read
 
1366
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
 
1367
            # we should be able to lock a newly opened branch now
 
1368
            branch = master.bzrdir.open_branch()
 
1369
            branch.lock_write()
 
1370
            branch.unlock()
 
1371
            # we should not be able to lock the repository in thisdir as its still
 
1372
            # held by the explicit lock we took, and the break lock should not have
 
1373
            # touched it.
 
1374
            repo = thisdir.open_repository()
 
1375
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
 
1376
            try:
 
1377
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
 
1378
                self.assertRaises(errors.LockContention, repo.lock_write)
 
1379
            finally:
 
1380
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
 
1381
        finally:
 
1382
            unused_repo.unlock()
1337
1383
        self.assertRaises(errors.LockBroken, master.unlock)
1338
1384
 
1339
1385
    def test_break_lock_tree(self):