~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_smart_add.py

  • Committer: Martin Pool
  • Date: 2005-09-07 23:14:30 UTC
  • mto: (1092.2.12) (974.1.76) (1185.8.2)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: mbp@sourcefrog.net-20050907231430-097abbaee94ad75b
- docstring fix from Magnus Therning

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
from bzrlib.selftest import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import Branch
6
 
from bzrlib.errors import NotBranchError
7
 
from bzrlib.inventory import InventoryFile
8
 
from bzrlib.workingtree import WorkingTree
 
6
from bzrlib.errors import NotBranchError, NotVersionedError
9
7
 
10
8
class TestSmartAdd(TestCaseInTempDir):
11
9
 
14
12
        from bzrlib.add import smart_add
15
13
        paths = ("original/", "original/file1", "original/file2")
16
14
        self.build_tree(paths)
17
 
        branch = Branch.initialize(".")
 
15
        branch = Branch(".", init=True)
18
16
        smart_add((".",), recurse=True)
19
17
        for path in paths:
20
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
18
            self.assertNotEqual(branch.inventory.path2id(path), None)
21
19
 
22
20
    def test_add_dot_from_subdir(self):
23
21
        """Test adding . from a subdir of the tree.""" 
24
22
        from bzrlib.add import smart_add
25
23
        paths = ("original/", "original/file1", "original/file2")
26
24
        self.build_tree(paths)
27
 
        branch = Branch.initialize(".")
 
25
        branch = Branch(".", init=True)
28
26
        os.chdir("original")
29
27
        smart_add((".",), recurse=True)
30
28
        for path in paths:
31
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
29
            self.assertNotEqual(branch.inventory.path2id(path), None)
32
30
 
33
31
    def test_add_tree_from_above_tree(self):
34
32
        """Test adding a tree from above the tree.""" 
37
35
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
38
36
                        "branch/original/file2")
39
37
        self.build_tree(branch_paths)
40
 
        branch = Branch.initialize("branch")
 
38
        branch = Branch("branch", init=True)
41
39
        smart_add(("branch",))
42
40
        for path in paths:
43
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
41
            self.assertNotEqual(branch.inventory.path2id(path), None)
44
42
 
45
43
    def test_add_above_tree_preserves_tree(self):
46
44
        """Test nested trees are not affect by an add above them."""
53
51
                       "original/child/", "original/child/path")
54
52
        
55
53
        self.build_tree(build_paths)
56
 
        branch = Branch.initialize(".")
57
 
        child_branch = Branch.initialize("original/child")
 
54
        branch = Branch(".", init=True)
 
55
        child_branch = Branch("original/child", init=True)
58
56
        smart_add((".",), True, add_reporter_null)
59
57
        for path in paths:
60
 
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
 
58
            self.assertNotEqual((path, branch.inventory.path2id(path)),
61
59
                                (path, None))
62
60
        for path in full_child_paths:
63
 
            self.assertEqual((path, branch.working_tree().path2id(path)),
 
61
            self.assertEqual((path, branch.inventory.path2id(path)),
64
62
                             (path, None))
65
63
        for path in child_paths:
66
 
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
64
            self.assertEqual(child_branch.inventory.path2id(path), None)
67
65
 
68
66
    def test_add_paths(self):
69
67
        """Test smart-adding a list of paths."""
70
68
        from bzrlib.add import smart_add
71
69
        paths = ("file1", "file2")
72
70
        self.build_tree(paths)
73
 
        branch = Branch.initialize(".")
 
71
        branch = Branch(".", init=True)
74
72
        smart_add(paths)
75
73
        for path in paths:
76
 
            self.assertNotEqual(branch.working_tree().path2id(path), None)
 
74
            self.assertNotEqual(branch.inventory.path2id(path), None)
77
75
            
78
76
class TestSmartAddBranch(TestCaseInTempDir):
79
77
    """Test smart adds with a specified branch."""
80
78
 
81
79
    def test_add_dot_from_root(self):
82
80
        """Test adding . from the root of the tree.""" 
83
 
        from bzrlib.add import smart_add_tree
 
81
        from bzrlib.add import smart_add_branch
84
82
        paths = ("original/", "original/file1", "original/file2")
85
83
        self.build_tree(paths)
86
 
        Branch.initialize(".")
87
 
        tree = WorkingTree()
88
 
        smart_add_tree(tree, (".",))
 
84
        branch = Branch(".", init=True)
 
85
        smart_add_branch(branch, (".",))
89
86
        for path in paths:
90
 
            self.assertNotEqual(tree.path2id(path), None)
 
87
            self.assertNotEqual(branch.inventory.path2id(path), None)
91
88
 
92
89
    def test_add_dot_from_subdir(self):
93
90
        """Test adding . from a subdir of the tree.""" 
94
 
        from bzrlib.add import smart_add_tree
 
91
        from bzrlib.add import smart_add_branch
95
92
        paths = ("original/", "original/file1", "original/file2")
96
93
        self.build_tree(paths)
97
 
        Branch.initialize(".")
98
 
        tree = WorkingTree()
 
94
        branch = Branch(".", init=True)
99
95
        os.chdir("original")
100
 
        smart_add_tree(tree, (".",))
 
96
        smart_add_branch(branch, (".",))
101
97
        for path in paths:
102
 
            self.assertNotEqual(tree.path2id(path), None)
 
98
            self.assertNotEqual(branch.inventory.path2id(path), None)
103
99
 
104
100
    def test_add_tree_from_above_tree(self):
105
101
        """Test adding a tree from above the tree.""" 
106
 
        from bzrlib.add import smart_add_tree
 
102
        from bzrlib.add import smart_add_branch
107
103
        paths = ("original/", "original/file1", "original/file2")
108
104
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
109
105
                        "branch/original/file2")
110
106
        self.build_tree(branch_paths)
111
 
        Branch.initialize("branch")
112
 
        tree = WorkingTree("branch")
113
 
        smart_add_tree(tree, ("branch",))
 
107
        branch = Branch("branch", init=True)
 
108
        smart_add_branch(branch, ("branch",))
114
109
        for path in paths:
115
 
            self.assertNotEqual(tree.path2id(path), None)
 
110
            self.assertNotEqual(branch.inventory.path2id(path), None)
116
111
 
117
112
    def test_add_above_tree_preserves_tree(self):
118
113
        """Test nested trees are not affect by an add above them."""
119
 
        from bzrlib.add import smart_add_tree
 
114
        from bzrlib.add import smart_add_branch
120
115
        paths = ("original/", "original/file1", "original/file2")
121
116
        child_paths = ("path")
122
117
        full_child_paths = ("original/child", "original/child/path")
123
118
        build_paths = ("original/", "original/file1", "original/file2", 
124
119
                       "original/child/", "original/child/path")
125
120
        self.build_tree(build_paths)
126
 
        Branch.initialize(".")
127
 
        tree = WorkingTree()
128
 
        child_branch = Branch.initialize("original/child")
129
 
        smart_add_tree(tree, (".",))
 
121
        branch = Branch(".", init=True)
 
122
        child_branch = Branch("original/child", init=True)
 
123
        smart_add_branch(branch, (".",))
130
124
        for path in paths:
131
 
            self.assertNotEqual((path, tree.path2id(path)),
 
125
            self.assertNotEqual((path, branch.inventory.path2id(path)),
132
126
                                (path, None))
133
127
        for path in full_child_paths:
134
 
            self.assertEqual((path, tree.path2id(path)),
 
128
            self.assertEqual((path, branch.inventory.path2id(path)),
135
129
                             (path, None))
136
130
        for path in child_paths:
137
 
            self.assertEqual(child_branch.working_tree().path2id(path), None)
 
131
            self.assertEqual(child_branch.inventory.path2id(path), None)
138
132
 
139
133
    def test_add_paths(self):
140
134
        """Test smart-adding a list of paths."""
141
 
        from bzrlib.add import smart_add_tree
 
135
        from bzrlib.add import smart_add_branch
142
136
        paths = ("file1", "file2")
143
137
        self.build_tree(paths)
144
 
        Branch.initialize(".")
145
 
        tree = WorkingTree()
146
 
        smart_add_tree(tree, paths)
 
138
        branch = Branch(".", init=True)
 
139
        smart_add_branch(branch, paths)
147
140
        for path in paths:
148
 
            self.assertNotEqual(tree.path2id(path), None)
 
141
            self.assertNotEqual(branch.inventory.path2id(path), None)
149
142
 
150
143
class TestAddCallbacks(TestCaseInTempDir):
151
144
 
152
145
    def setUp(self):
 
146
        from bzrlib.inventory import InventoryEntry
153
147
        super(TestAddCallbacks, self).setUp()
154
 
        self.entry = InventoryFile("id", "name", None)
 
148
        self.entry = InventoryEntry("id", "name", "file", None)
155
149
 
156
150
    def test_null_callback(self):
157
151
        from bzrlib.add import add_reporter_null