~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_extract.py

  • Committer: Aaron Bentley
  • Date: 2012-07-23 16:47:33 UTC
  • mto: This revision was merged to the branch mainline in revision 6540.
  • Revision ID: aaron@aaronbentley.com-20120723164733-gg80rc88eh07szod
Tweak docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006, 2007, 2009, 2011 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
from bzrlib import (
 
18
    branch,
 
19
    errors,
 
20
    )
 
21
from bzrlib.tests import TestCaseWithTransport
 
22
 
 
23
 
 
24
class TestExtract(TestCaseWithTransport):
 
25
 
 
26
    def test_extract(self):
 
27
        self.build_tree(['a/', 'a/b/', 'a/b/c', 'a/d'])
 
28
        wt = self.make_branch_and_tree('a', format='rich-root-pack')
 
29
        wt.add(['b', 'b/c', 'd'], ['b-id', 'c-id', 'd-id'])
 
30
        wt.commit('added files')
 
31
        b_wt = wt.extract('b-id')
 
32
        self.assertEqual('b-id', b_wt.get_root_id())
 
33
        self.assertEqual('c-id', b_wt.path2id('c'))
 
34
        self.assertEqual('c', b_wt.id2path('c-id'))
 
35
        self.assertRaises(errors.BzrError, wt.id2path, 'b-id')
 
36
        self.assertEqual(b_wt.basedir, wt.abspath('b'))
 
37
        self.assertEqual(wt.get_parent_ids(), b_wt.get_parent_ids())
 
38
        self.assertEqual(wt.branch.last_revision(),
 
39
                         b_wt.branch.last_revision())
 
40
 
 
41
    def extract_in_checkout(self, a_branch):
 
42
        self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d'])
 
43
        wt = a_branch.create_checkout('a', lightweight=True)
 
44
        wt.add(['b', 'b/c', 'b/c/d'], ['b-id', 'c-id', 'd-id'])
 
45
        wt.commit('added files')
 
46
        return wt.extract('b-id')
 
47
 
 
48
    def test_extract_in_checkout(self):
 
49
        a_branch = self.make_branch('branch', format='rich-root-pack')
 
50
        self.extract_in_checkout(a_branch)
 
51
        b_branch = branch.Branch.open('branch/b')
 
52
        b_branch_ref = branch.Branch.open('a/b')
 
53
        self.assertEqual(b_branch.base, b_branch_ref.base)
 
54
 
 
55
    def test_extract_in_deep_checkout(self):
 
56
        a_branch = self.make_branch('branch', format='rich-root-pack')
 
57
        self.build_tree(['a/', 'a/b/', 'a/b/c/', 'a/b/c/d/', 'a/b/c/d/e'])
 
58
        wt = a_branch.create_checkout('a', lightweight=True)
 
59
        wt.add(['b', 'b/c', 'b/c/d', 'b/c/d/e/'], ['b-id', 'c-id', 'd-id',
 
60
                'e-id'])
 
61
        wt.commit('added files')
 
62
        b_wt = wt.extract('d-id')
 
63
        b_branch = branch.Branch.open('branch/b/c/d')
 
64
        b_branch_ref = branch.Branch.open('a/b/c/d')
 
65
        self.assertEqual(b_branch.base, b_branch_ref.base)
 
66
 
 
67
    def test_bad_repo_format(self):
 
68
        repo = self.make_repository('branch', shared=True,
 
69
                                    format='knit')
 
70
        a_branch = repo.bzrdir.create_branch()
 
71
        self.assertRaises(errors.RootNotRich, self.extract_in_checkout,
 
72
                          a_branch)
 
73
 
 
74
    def test_good_repo_format(self):
 
75
        repo = self.make_repository('branch', shared=True,
 
76
            format='dirstate-with-subtree')
 
77
        a_branch = repo.bzrdir.create_branch()
 
78
        wt_b = self.extract_in_checkout(a_branch)
 
79
        self.assertEqual(wt_b.branch.repository.bzrdir.transport.base,
 
80
        repo.bzrdir.transport.base)