/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
1
import os
2
import unittest
3
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
4
from bzrlib.tests import TestCaseInTempDir, TestCase
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
5
from bzrlib.branch import Branch
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
6
from bzrlib.errors import NotBranchError
1399.1.10 by Robert Collins
remove kind from the InventoryEntry constructor - only child classes should be created now
7
from bzrlib.inventory import InventoryFile
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
8
from bzrlib.workingtree import WorkingTree
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
9
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
10
class TestSmartAdd(TestCaseInTempDir):
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
11
12
    def test_add_dot_from_root(self):
13
        """Test adding . from the root of the tree.""" 
14
        from bzrlib.add import smart_add
15
        paths = ("original/", "original/file1", "original/file2")
16
        self.build_tree(paths)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
17
        branch = Branch.initialize(".")
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
18
        smart_add((".",), recurse=True)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
19
        for path in paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
20
            self.assertNotEqual(branch.working_tree().path2id(path), None)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
21
22
    def test_add_dot_from_subdir(self):
23
        """Test adding . from a subdir of the tree.""" 
24
        from bzrlib.add import smart_add
25
        paths = ("original/", "original/file1", "original/file2")
26
        self.build_tree(paths)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
27
        branch = Branch.initialize(".")
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
28
        os.chdir("original")
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
29
        smart_add((".",), recurse=True)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
30
        for path in paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
31
            self.assertNotEqual(branch.working_tree().path2id(path), None)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
32
33
    def test_add_tree_from_above_tree(self):
34
        """Test adding a tree from above the tree.""" 
35
        from bzrlib.add import smart_add
36
        paths = ("original/", "original/file1", "original/file2")
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
37
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
38
                        "branch/original/file2")
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
39
        self.build_tree(branch_paths)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
40
        branch = Branch.initialize("branch")
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
41
        smart_add(("branch",))
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
42
        for path in paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
43
            self.assertNotEqual(branch.working_tree().path2id(path), None)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
44
45
    def test_add_above_tree_preserves_tree(self):
46
        """Test nested trees are not affect by an add above them."""
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
47
        from bzrlib.add import smart_add, add_reporter_null
48
        
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
49
        paths = ("original/", "original/file1", "original/file2")
1143 by Martin Pool
- remove dead code and remove some small errors (pychecker)
50
        child_paths = ("path",)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
51
        full_child_paths = ("original/child", "original/child/path")
52
        build_paths = ("original/", "original/file1", "original/file2", 
53
                       "original/child/", "original/child/path")
1143 by Martin Pool
- remove dead code and remove some small errors (pychecker)
54
        
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
55
        self.build_tree(build_paths)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
56
        branch = Branch.initialize(".")
57
        child_branch = Branch.initialize("original/child")
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
58
        smart_add((".",), True, add_reporter_null)
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
59
        for path in paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
60
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
61
                                (path, None))
62
        for path in full_child_paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
63
            self.assertEqual((path, branch.working_tree().path2id(path)),
1092.1.27 by Robert Collins
two bugfixes to smart_add - do not add paths from nested trees to the parent tree, and do not mutate the user supplied file list
64
                             (path, None))
65
        for path in child_paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
66
            self.assertEqual(child_branch.working_tree().path2id(path), None)
1092.1.28 by Robert Collins
test adding lists of paths
67
68
    def test_add_paths(self):
69
        """Test smart-adding a list of paths."""
70
        from bzrlib.add import smart_add
71
        paths = ("file1", "file2")
72
        self.build_tree(paths)
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
73
        branch = Branch.initialize(".")
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
74
        smart_add(paths)
1092.1.28 by Robert Collins
test adding lists of paths
75
        for path in paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
76
            self.assertNotEqual(branch.working_tree().path2id(path), None)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
77
            
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
78
class TestSmartAddBranch(TestCaseInTempDir):
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
79
    """Test smart adds with a specified branch."""
80
81
    def test_add_dot_from_root(self):
82
        """Test adding . from the root of the tree.""" 
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
83
        from bzrlib.add import smart_add_tree
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
84
        paths = ("original/", "original/file1", "original/file2")
85
        self.build_tree(paths)
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
86
        Branch.initialize(".")
87
        tree = WorkingTree()
88
        smart_add_tree(tree, (".",))
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
89
        for path in paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
90
            self.assertNotEqual(tree.path2id(path), None)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
91
92
    def test_add_dot_from_subdir(self):
93
        """Test adding . from a subdir of the tree.""" 
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
94
        from bzrlib.add import smart_add_tree
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
95
        paths = ("original/", "original/file1", "original/file2")
96
        self.build_tree(paths)
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
97
        Branch.initialize(".")
98
        tree = WorkingTree()
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
99
        os.chdir("original")
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
100
        smart_add_tree(tree, (".",))
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
101
        for path in paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
102
            self.assertNotEqual(tree.path2id(path), None)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
103
104
    def test_add_tree_from_above_tree(self):
105
        """Test adding a tree from above the tree.""" 
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
106
        from bzrlib.add import smart_add_tree
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
107
        paths = ("original/", "original/file1", "original/file2")
108
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
109
                        "branch/original/file2")
110
        self.build_tree(branch_paths)
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
111
        Branch.initialize("branch")
112
        tree = WorkingTree("branch")
113
        smart_add_tree(tree, ("branch",))
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
114
        for path in paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
115
            self.assertNotEqual(tree.path2id(path), None)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
116
117
    def test_add_above_tree_preserves_tree(self):
118
        """Test nested trees are not affect by an add above them."""
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
119
        from bzrlib.add import smart_add_tree
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
120
        paths = ("original/", "original/file1", "original/file2")
121
        child_paths = ("path")
122
        full_child_paths = ("original/child", "original/child/path")
123
        build_paths = ("original/", "original/file1", "original/file2", 
124
                       "original/child/", "original/child/path")
125
        self.build_tree(build_paths)
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
126
        Branch.initialize(".")
127
        tree = WorkingTree()
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
128
        child_branch = Branch.initialize("original/child")
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
129
        smart_add_tree(tree, (".",))
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
130
        for path in paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
131
            self.assertNotEqual((path, tree.path2id(path)),
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
132
                                (path, None))
133
        for path in full_child_paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
134
            self.assertEqual((path, tree.path2id(path)),
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
135
                             (path, None))
136
        for path in child_paths:
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
137
            self.assertEqual(child_branch.working_tree().path2id(path), None)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
138
139
    def test_add_paths(self):
140
        """Test smart-adding a list of paths."""
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
141
        from bzrlib.add import smart_add_tree
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
142
        paths = ("file1", "file2")
143
        self.build_tree(paths)
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
144
        Branch.initialize(".")
145
        tree = WorkingTree()
146
        smart_add_tree(tree, paths)
1092.1.29 by Robert Collins
break smart_add into smart_add and smart_add_branch which will accept a branch parameter
147
        for path in paths:
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
148
            self.assertNotEqual(tree.path2id(path), None)
1092.1.30 by Robert Collins
change smart_add reporting of added files to callback with the entry, and change the inventory.add signature to return the added entry
149
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
150
class TestAddCallbacks(TestCaseInTempDir):
1092.1.30 by Robert Collins
change smart_add reporting of added files to callback with the entry, and change the inventory.add signature to return the added entry
151
152
    def setUp(self):
153
        super(TestAddCallbacks, self).setUp()
1399.1.10 by Robert Collins
remove kind from the InventoryEntry constructor - only child classes should be created now
154
        self.entry = InventoryFile("id", "name", None)
1092.1.30 by Robert Collins
change smart_add reporting of added files to callback with the entry, and change the inventory.add signature to return the added entry
155
156
    def test_null_callback(self):
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
157
        from bzrlib.add import add_reporter_null
158
        add_reporter_null('path', 'file', self.entry)
1092.1.30 by Robert Collins
change smart_add reporting of added files to callback with the entry, and change the inventory.add signature to return the added entry
159
160
    def test_print_callback(self):
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
161
        from bzrlib.add import add_reporter_print
1092.1.30 by Robert Collins
change smart_add reporting of added files to callback with the entry, and change the inventory.add signature to return the added entry
162
        from StringIO import StringIO
163
        stdout = StringIO()
1159 by Martin Pool
- clean up parameters to smart_add and smart_add_branch
164
        self.apply_redirected(None, stdout, None, add_reporter_print,
1139 by Martin Pool
- merge in merge improvements and additional tests
165
                              'path', 'file', self.entry)
166
        self.assertEqual(stdout.getvalue(), "added path\n")