Rev 2708: blackbox.test_b* user internals as appropriate (Daniel Watkins) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Aug 15 23:52:41 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2708
revision-id: pqm at pqm.ubuntu.com-20070815225233-w4gpchswmwvqi12r
parent: pqm at pqm.ubuntu.com-20070815213042-m6nonfyi3cqcq5qc
parent: d.m.watkins at warwick.ac.uk-20070803125914-ovio9p3j35kxa10k
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-08-15 23:52:33 +0100
message:
  blackbox.test_b* user internals as appropriate (Daniel Watkins)
modified:
  bzrlib/tests/blackbox/test_bound_branches.py test_bound_branches.py-20051109215527-2373188ad566c205
  bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
    ------------------------------------------------------------
    revno: 2664.8.2
    merged: d.m.watkins at warwick.ac.uk-20070803125914-ovio9p3j35kxa10k
    parent: d.m.watkins at warwick.ac.uk-20070803125048-h35i1he6g4n2fszf
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: fix-blackbox-tests
    timestamp: Fri 2007-08-03 13:59:14 +0100
    message:
      tests.blackbox.test_branch now uses internals where appropriate.
    ------------------------------------------------------------
    revno: 2664.8.1
    merged: d.m.watkins at warwick.ac.uk-20070803125048-h35i1he6g4n2fszf
    parent: pqm at pqm.ubuntu.com-20070731122244-f1jemfecukeevugw
    committer: Daniel Watkins <D.M.Watkins at warwick.ac.uk>
    branch nick: fix-blackbox-tests
    timestamp: Fri 2007-08-03 13:50:48 +0100
    message:
      tests.blackbox.test_bound_branches now uses internals where appropriate.
=== modified file 'bzrlib/tests/blackbox/test_bound_branches.py'
--- a/bzrlib/tests/blackbox/test_bound_branches.py	2007-06-28 12:26:11 +0000
+++ b/bzrlib/tests/blackbox/test_bound_branches.py	2007-08-03 12:50:48 +0000
@@ -22,6 +22,7 @@
 
 from bzrlib import (
     bzrdir,
+    errors
     )
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import (BzrDir, BzrDirFormat, BzrDirMetaFormat1)
@@ -36,8 +37,9 @@
     def setUp(self):
         super(TestLegacyFormats, self).setUp()
         self.build_tree(['master/', 'child/'])
-        self.run_bzr('init master')
-        self.run_bzr('init --format=weave child')
+        self.make_branch_and_tree('master')
+        self.make_branch_and_tree('child',
+                        format=bzrdir.format_registry.make_bzrdir('weave'))
         os.chdir('child')
     
     def test_bind_format_6_bzrdir(self):
@@ -62,22 +64,23 @@
 class TestBoundBranches(TestCaseWithTransport):
 
     def create_branches(self):
-        bzr = self.run_bzr
         self.build_tree(['base/', 'base/a', 'base/b'])
 
         branch = self.init_meta_branch('base')
-        tree = branch.bzrdir.open_workingtree()
-        tree.lock_write()
-        tree.add(['a', 'b'])
-        tree.commit('init')
-        tree.unlock()
+        base_tree = branch.bzrdir.open_workingtree()
+        base_tree.lock_write()
+        base_tree.add(['a', 'b'])
+        base_tree.commit('init')
+        base_tree.unlock()
 
-        self.run_bzr('checkout base child')
+        child_tree = branch.create_checkout('child')
 
         self.check_revno(1, 'child')
         d = BzrDir.open('child')
         self.assertNotEqual(None, d.open_branch().get_master_branch())
 
+        return base_tree, child_tree
+
     def check_revno(self, val, loc='.'):
         self.assertEqual(
             val, len(BzrDir.open(loc).open_branch().revision_history()))
@@ -85,11 +88,12 @@
     def test_simple_binding(self):
         self.build_tree(['base/', 'base/a', 'base/b'])
 
-        self.init_meta_branch('base')
-        self.run_bzr('add base')
-        self.run_bzr('commit -m init base')
+        branch = self.init_meta_branch('base')
+        tree = branch.bzrdir.open_workingtree()
+        tree.add('a', 'b')
+        tree.commit(message='init')
 
-        self.run_bzr('branch base child')
+        tree.bzrdir.sprout('child')
 
         os.chdir('child')
         self.run_bzr('bind ../base')
@@ -132,141 +136,134 @@
         return BzrDir.create_branch_convenience(path, format=format)
 
     def test_bound_commit(self):
-        bzr = self.run_bzr
-        self.create_branches()
-
-        os.chdir('child')
-        open('a', 'wb').write('new contents\n')
-        bzr('commit -m child')
-
-        self.check_revno(2)
+        child_tree = self.create_branches()[1]
+
+        self.build_tree_contents([('child/a', 'new contents')])
+        child_tree.commit(message='child')
+
+        self.check_revno(2, 'child')
 
         # Make sure it committed on the parent
-        self.check_revno(2, '../base')
+        self.check_revno(2, 'base')
 
     def test_bound_fail(self):
         # Make sure commit fails if out of date.
-        bzr = self.run_bzr
-        self.create_branches()
-
-        os.chdir('base')
-        open('a', 'wb').write('new base contents\n')
-        bzr('commit -m base')
-        self.check_revno(2)
-
-        os.chdir('../child')
-        self.check_revno(1)
-        open('b', 'wb').write('new b child contents\n')
-        bzr('commit -m child', retcode=3)
-        self.check_revno(1)
-
-        bzr('update')
-        self.check_revno(2)
-
-        bzr('commit -m child')
-        self.check_revno(3)
-        self.check_revno(3, '../base')
+        base_tree, child_tree = self.create_branches()
+
+        self.build_tree_contents([
+            ('base/a',  'new base contents\n'   ),
+            ('child/b', 'new b child contents\n')])
+        base_tree.commit(message='base')
+        self.check_revno(2, 'base')
+
+        self.check_revno(1, 'child')
+        self.assertRaises(errors.BoundBranchOutOfDate, child_tree.commit,
+                                                            message='child')
+        self.check_revno(1, 'child')
+
+        child_tree.update()
+        self.check_revno(2, 'child')
+
+        child_tree.commit(message='child')
+        self.check_revno(3, 'child')
+        self.check_revno(3, 'base')
 
     def test_double_binding(self):
-        bzr = self.run_bzr
-        self.create_branches()
-
-        bzr('branch child child2')
+        child_tree = self.create_branches()[1]
+
+        child2_tree = child_tree.bzrdir.sprout('child2').open_workingtree()
+
         os.chdir('child2')
-
         # Double binding succeeds, but committing to child2 should fail
-        bzr('bind ../child')
+        self.run_bzr('bind ../child')
 
-        bzr('commit -m child2 --unchanged', retcode=3)
+        self.assertRaises(errors.CommitToDoubleBoundBranch,
+                child2_tree.commit, message='child2', allow_pointless=True)
 
     def test_unbinding(self):
-        bzr = self.run_bzr
-        self.create_branches()
-
-        os.chdir('base')
-        open('a', 'wb').write('new base contents\n')
-        bzr('commit -m base')
-        self.check_revno(2)
-
-        os.chdir('../child')
-        open('b', 'wb').write('new b child contents\n')
-        self.check_revno(1)
-        bzr('commit -m child', retcode=3)
-        self.check_revno(1)
-        bzr('unbind')
-        bzr('commit -m child')
-        self.check_revno(2)
-
-        bzr('bind', retcode=3)
+        base_tree, child_tree = self.create_branches()
+
+        self.build_tree_contents([
+            ('base/a',  'new base contents\n'   ),
+            ('child/b', 'new b child contents\n')])
+
+        base_tree.commit(message='base')
+        self.check_revno(2, 'base')
+
+        self.check_revno(1, 'child')
+        os.chdir('child')
+        self.run_bzr("commit -m child", retcode=3)
+        self.check_revno(1)
+        self.run_bzr('unbind')
+        child_tree.commit(message='child')
+        self.check_revno(2)
+
+        self.run_bzr('bind', retcode=3)
 
     def test_commit_remote_bound(self):
         # It is not possible to commit to a branch
         # which is bound to a branch which is bound
-        bzr = self.run_bzr
-        self.create_branches()
-        bzr('branch base newbase')
+        base_tree, child_tree = self.create_branches()
+        base_tree.bzrdir.sprout('newbase')
+
         os.chdir('base')
-        
         # There is no way to know that B has already
         # been bound by someone else, otherwise it
         # might be nice if this would fail
-        bzr('bind ../newbase')
+        self.run_bzr('bind ../newbase')
 
         os.chdir('../child')
-        bzr('commit -m failure --unchanged', retcode=3)
+        self.run_bzr('commit -m failure --unchanged', retcode=3)
 
     def test_pull_updates_both(self):
-        bzr = self.run_bzr
-        self.create_branches()
-        bzr('branch base newchild')
-        os.chdir('newchild')
-        open('b', 'wb').write('newchild b contents\n')
-        bzr('commit -m newchild')
-        self.check_revno(2)
+        base_tree = self.create_branches()[0]
+        newchild_tree = base_tree.bzrdir.sprout('newchild').open_workingtree()
+        self.build_tree_contents([('newchild/b', 'newchild b contents\n')])
+        newchild_tree.commit(message='newchild')
+        self.check_revno(2, 'newchild')
 
-        os.chdir('../child')
+        os.chdir('child')
         # The pull should succeed, and update
         # the bound parent branch
-        bzr('pull ../newchild')
+        self.run_bzr('pull ../newchild')
         self.check_revno(2)
 
         self.check_revno(2, '../base')
 
     def test_bind_diverged(self):
-        bzr = self.run_bzr
-        self.create_branches()
-
-        os.chdir('child')
-        bzr('unbind')
-
-        bzr('commit -m child --unchanged')
-        self.check_revno(2)
-
-        os.chdir('../base')
-        self.check_revno(1)
-        bzr('commit -m base --unchanged')
-        self.check_revno(2)
-
-        os.chdir('../child')
+        base_tree, child_tree = self.create_branches()
+        base_branch = base_tree.branch
+        child_branch = child_tree.branch
+
+        os.chdir('child')
+        self.run_bzr('unbind')
+
+        child_tree.commit(message='child', allow_pointless=True)
+        self.check_revno(2)
+
+        os.chdir('..')
+        self.check_revno(1, 'base')
+        base_tree.commit(message='base', allow_pointless=True)
+        self.check_revno(2, 'base')
+
+        os.chdir('child')
         # These branches have diverged
-        bzr('bind ../base', retcode=3)
+        self.run_bzr('bind ../base', retcode=3)
 
         # TODO: In the future, this might require actual changes
         # to have occurred, rather than just a new revision entry
-        bzr('merge ../base')
-        bzr('commit -m merged')
+        child_tree.merge_from_branch(base_branch)
+        child_tree.commit(message='merged')
         self.check_revno(3)
 
         # After binding, the revision history should be unaltered
-        base_branch = Branch.open('../base')
-        child_branch = Branch.open('.')
         # take a copy before
         base_history = base_branch.revision_history()
         child_history = child_branch.revision_history()
 
         # After a merge, trying to bind again should succeed
         # keeping the new change as a local commit.
-        bzr('bind ../base')
+        self.run_bzr('bind ../base')
         self.check_revno(3)
         self.check_revno(2, '../base')
 
@@ -275,131 +272,119 @@
         self.assertEqual(child_history, child_branch.revision_history())
 
     def test_bind_parent_ahead(self):
-        bzr = self.run_bzr
-        self.create_branches()
+        base_tree = self.create_branches()[0]
 
         os.chdir('child')
-        bzr('unbind')
-
-        os.chdir('../base')
-        bzr('commit -m base --unchanged')
-
-        os.chdir('../child')
+        self.run_bzr('unbind')
+
+        base_tree.commit(message='base', allow_pointless=True)
+
         self.check_revno(1)
-        bzr('bind ../base')
+        self.run_bzr('bind ../base')
 
         # binding does not pull data:
         self.check_revno(1)
-        bzr('unbind')
+        self.run_bzr('unbind')
 
         # Check and make sure it also works if parent is ahead multiple
-        os.chdir('../base')
-        bzr(['commit', '-m', 'base 3', '--unchanged'])
-        bzr(['commit', '-m', 'base 4', '--unchanged'])
-        bzr(['commit', '-m', 'base 5', '--unchanged'])
-        self.check_revno(5)
+        base_tree.commit(message='base 3', allow_pointless=True)
+        base_tree.commit(message='base 4', allow_pointless=True)
+        base_tree.commit(message='base 5', allow_pointless=True)
+        self.check_revno(5, '../base')
 
-        os.chdir('../child')
         self.check_revno(1)
-        bzr('bind ../base')
+        self.run_bzr('bind ../base')
         self.check_revno(1)
 
     def test_bind_child_ahead(self):
         # test binding when the master branches history is a prefix of the 
         # childs - it should bind ok but the revision histories should not
         # be altered
-        bzr = self.run_bzr
-        self.create_branches()
+        child_tree = self.create_branches()[1]
 
         os.chdir('child')
-        bzr('unbind')
-        bzr('commit -m child --unchanged')
+        self.run_bzr('unbind')
+        child_tree.commit(message='child', allow_pointless=True)
         self.check_revno(2)
         self.check_revno(1, '../base')
 
-        bzr('bind ../base')
+        self.run_bzr('bind ../base')
         self.check_revno(1, '../base')
 
         # Check and make sure it also works if child is ahead multiple
-        bzr('unbind')
-        bzr(['commit', '-m', 'child 3', '--unchanged'])
-        bzr(['commit', '-m', 'child 4', '--unchanged'])
-        bzr(['commit', '-m', 'child 5', '--unchanged'])
+        self.run_bzr('unbind')
+        child_tree.commit(message='child 3', allow_pointless=True)
+        child_tree.commit(message='child 4', allow_pointless=True)
+        child_tree.commit(message='child 5', allow_pointless=True)
         self.check_revno(5)
 
         self.check_revno(1, '../base')
-        bzr('bind ../base')
+        self.run_bzr('bind ../base')
         self.check_revno(1, '../base')
 
     def test_commit_after_merge(self):
-        bzr = self.run_bzr
-        self.create_branches()
+        base_tree, child_tree = self.create_branches()
 
         # We want merge to be able to be a local only
         # operation, because it can be without violating
         # the binding invariants.
         # But we can't fail afterwards
-
-        bzr('branch child other')
-
-        os.chdir('other')
-        open('c', 'wb').write('file c\n')
-        bzr('add c')
-        bzr(['commit', '-m', 'adding c'])
-        new_rev_id = bzr('revision-history')[0].strip().split('\n')[-1]
-
-        os.chdir('../child')
-        bzr('merge ../other')
-
-        self.failUnlessExists('c')
-        tree = WorkingTree.open('.') # opens child
-        self.assertEqual([new_rev_id], tree.get_parent_ids()[1:])
+        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
+        other_branch = other_tree.branch
+
+        self.build_tree_contents([('other/c', 'file c\n')])
+        other_tree.add('c')
+        other_tree.commit(message='adding c')
+        new_rev_id = other_branch.revision_history()[-1]
+
+        child_tree.merge_from_branch(other_branch)
+
+        self.failUnlessExists('child/c')
+        self.assertEqual([new_rev_id], child_tree.get_parent_ids()[1:])
 
         # Make sure the local branch has the installed revision
-        bzr(['cat-revision', new_rev_id])
-        
+        self.assertTrue(child_tree.branch.repository.has_revision(new_rev_id))
+
         # And make sure that the base tree does not
-        os.chdir('../base')
-        bzr(['cat-revision', new_rev_id], retcode=3)
+        self.assertFalse(base_tree.branch.repository.has_revision(new_rev_id))
 
         # Commit should succeed, and cause merged revisions to
         # be pulled into base
-        os.chdir('../child')
-        bzr(['commit', '-m', 'merge other'])
-
-        self.check_revno(2)
-
-        os.chdir('../base')
-        self.check_revno(2)
-
-        bzr(['cat-revision', new_rev_id])
+        os.chdir('child')
+        self.run_bzr(['commit', '-m', 'merge other'])
+
+        self.check_revno(2)
+
+        self.check_revno(2, '../base')
+
+        self.assertTrue(base_tree.branch.repository.has_revision(new_rev_id))
 
     def test_pull_overwrite(self):
         # XXX: This test should be moved to branch-implemenations/test_pull
-        bzr = self.run_bzr
-        self.create_branches()
-
-        bzr('branch child other')
-        
-        os.chdir('other')
-        open('a', 'wb').write('new contents\n')
-        bzr(['commit', '-m', 'changed a'])
-        self.check_revno(2)
-        open('a', 'ab').write('and then some\n')
-        bzr(['commit', '-m', 'another a'])
-        self.check_revno(3)
-        open('a', 'ab').write('and some more\n')
-        bzr(['commit', '-m', 'yet another a'])
-        self.check_revno(4)
-
-        os.chdir('../child')
-        open('a', 'wb').write('also changed a\n')
-        bzr(['commit', '-m', 'child modified a'])
-
-        self.check_revno(2)
-        self.check_revno(2, '../base')
-
-        bzr('pull --overwrite ../other')
+        child_tree = self.create_branches()[1]
+
+        other_tree = child_tree.bzrdir.sprout('other').open_workingtree()
+
+        self.build_tree_contents([('other/a', 'new contents\n')])
+        other_tree.commit(message='changed a')
+        self.check_revno(2, 'other')
+        self.build_tree_contents([
+            ('other/a', 'new contents\nand then some\n')])
+        other_tree.commit(message='another a')
+        self.check_revno(3, 'other')
+        self.build_tree_contents([
+            ('other/a', 'new contents\nand then some\nand some more\n')])
+        other_tree.commit('yet another a')
+        self.check_revno(4, 'other')
+
+        self.build_tree_contents([('child/a', 'also changed a\n')])
+        child_tree.commit(message='child modified a')
+
+        self.check_revno(2, 'child')
+        self.check_revno(2, 'base')
+
+        os.chdir('child')
+        self.run_bzr('pull --overwrite ../other')
 
         # both the local and master should have been updated.
         self.check_revno(4)

=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py	2007-07-22 17:18:05 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py	2007-08-03 12:59:14 +0000
@@ -28,28 +28,23 @@
 
 class TestBranch(ExternalBase):
 
-    def example_branch(test):
-        test.run_bzr('init')
-        file('hello', 'wt').write('foo')
-        test.run_bzr('add hello')
-        test.run_bzr('commit -m setup hello')
-        file('goodbye', 'wt').write('baz')
-        test.run_bzr('add goodbye')
-        test.run_bzr('commit -m setup goodbye')
+    def example_branch(self, path='.'):
+        tree = self.make_branch_and_tree(path)
+        self.build_tree_contents([(path + '/hello', 'foo')])
+        tree.add('hello')
+        tree.commit(message='setup')
+        self.build_tree_contents([(path + '/goodbye', 'baz')])
+        tree.add('goodbye')
+        tree.commit(message='setup')
 
     def test_branch(self):
         """Branch from one branch to another."""
-        os.mkdir('a')
-        os.chdir('a')
-        self.example_branch()
-        os.chdir('..')
+        self.example_branch('a')
         self.run_bzr('branch a b')
         b = branch.Branch.open('b')
         self.assertEqual('b\n', b.control_files.get_utf8('branch-name').read())
         self.run_bzr('branch a c -r 1')
-        os.chdir('b')
-        self.run_bzr('commit -m foo --unchanged')
-        os.chdir('..')
+        b.bzrdir.open_workingtree().commit(message='foo', allow_pointless=True)
 
     def test_branch_only_copies_history(self):
         # Knit branches should only push the history for the current revision.




More information about the bazaar-commits mailing list