~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_smart_add.py

Fix http server tests for win32/macos (John)

Show diffs side-by-side

added added

removed removed

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