~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_smart_add.py

Refactored the export code to make it easier to add new export formats.

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, NotVersionedError
 
6
from bzrlib.errors import NotBranchError
 
7
from bzrlib.inventory import InventoryFile
7
8
 
8
9
class TestSmartAdd(TestCaseInTempDir):
9
10
 
15
16
        branch = Branch.initialize(".")
16
17
        smart_add((".",), recurse=True)
17
18
        for path in paths:
18
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
19
            self.assertNotEqual(branch.working_tree().path2id(path), None)
19
20
 
20
21
    def test_add_dot_from_subdir(self):
21
22
        """Test adding . from a subdir of the tree.""" 
26
27
        os.chdir("original")
27
28
        smart_add((".",), recurse=True)
28
29
        for path in paths:
29
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
30
            self.assertNotEqual(branch.working_tree().path2id(path), None)
30
31
 
31
32
    def test_add_tree_from_above_tree(self):
32
33
        """Test adding a tree from above the tree.""" 
38
39
        branch = Branch.initialize("branch")
39
40
        smart_add(("branch",))
40
41
        for path in paths:
41
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
42
            self.assertNotEqual(branch.working_tree().path2id(path), None)
42
43
 
43
44
    def test_add_above_tree_preserves_tree(self):
44
45
        """Test nested trees are not affect by an add above them."""
55
56
        child_branch = Branch.initialize("original/child")
56
57
        smart_add((".",), True, add_reporter_null)
57
58
        for path in paths:
58
 
            self.assertNotEqual((path, branch.inventory.path2id(path)),
 
59
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
59
60
                                (path, None))
60
61
        for path in full_child_paths:
61
 
            self.assertEqual((path, branch.inventory.path2id(path)),
 
62
            self.assertEqual((path, branch.working_tree().path2id(path)),
62
63
                             (path, None))
63
64
        for path in child_paths:
64
 
            self.assertEqual(child_branch.inventory.path2id(path), None)
 
65
            self.assertEqual(child_branch.working_tree().path2id(path), None)
65
66
 
66
67
    def test_add_paths(self):
67
68
        """Test smart-adding a list of paths."""
71
72
        branch = Branch.initialize(".")
72
73
        smart_add(paths)
73
74
        for path in paths:
74
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
75
            self.assertNotEqual(branch.working_tree().path2id(path), None)
75
76
            
76
77
class TestSmartAddBranch(TestCaseInTempDir):
77
78
    """Test smart adds with a specified branch."""
84
85
        branch = Branch.initialize(".")
85
86
        smart_add_branch(branch, (".",))
86
87
        for path in paths:
87
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
88
            self.assertNotEqual(branch.working_tree().path2id(path), None)
88
89
 
89
90
    def test_add_dot_from_subdir(self):
90
91
        """Test adding . from a subdir of the tree.""" 
95
96
        os.chdir("original")
96
97
        smart_add_branch(branch, (".",))
97
98
        for path in paths:
98
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
99
            self.assertNotEqual(branch.working_tree().path2id(path), None)
99
100
 
100
101
    def test_add_tree_from_above_tree(self):
101
102
        """Test adding a tree from above the tree.""" 
107
108
        branch = Branch.initialize("branch")
108
109
        smart_add_branch(branch, ("branch",))
109
110
        for path in paths:
110
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
111
            self.assertNotEqual(branch.working_tree().path2id(path), None)
111
112
 
112
113
    def test_add_above_tree_preserves_tree(self):
113
114
        """Test nested trees are not affect by an add above them."""
122
123
        child_branch = Branch.initialize("original/child")
123
124
        smart_add_branch(branch, (".",))
124
125
        for path in paths:
125
 
            self.assertNotEqual((path, branch.inventory.path2id(path)),
 
126
            self.assertNotEqual((path, branch.working_tree().path2id(path)),
126
127
                                (path, None))
127
128
        for path in full_child_paths:
128
 
            self.assertEqual((path, branch.inventory.path2id(path)),
 
129
            self.assertEqual((path, branch.working_tree().path2id(path)),
129
130
                             (path, None))
130
131
        for path in child_paths:
131
 
            self.assertEqual(child_branch.inventory.path2id(path), None)
 
132
            self.assertEqual(child_branch.working_tree().path2id(path), None)
132
133
 
133
134
    def test_add_paths(self):
134
135
        """Test smart-adding a list of paths."""
138
139
        branch = Branch.initialize(".")
139
140
        smart_add_branch(branch, paths)
140
141
        for path in paths:
141
 
            self.assertNotEqual(branch.inventory.path2id(path), None)
 
142
            self.assertNotEqual(branch.working_tree().path2id(path), None)
142
143
 
143
144
class TestAddCallbacks(TestCaseInTempDir):
144
145
 
145
146
    def setUp(self):
146
 
        from bzrlib.inventory import InventoryEntry
147
147
        super(TestAddCallbacks, self).setUp()
148
 
        self.entry = InventoryEntry("id", "name", "file", None)
 
148
        self.entry = InventoryFile("id", "name", None)
149
149
 
150
150
    def test_null_callback(self):
151
151
        from bzrlib.add import add_reporter_null