~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: John Arbash Meinel
  • Date: 2005-12-01 19:27:48 UTC
  • mto: (1185.50.19 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1532.
  • Revision ID: john@arbash-meinel.com-20051201192748-369238cd06ecf7e8
Added osutils.mkdtemp()

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