~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/test_smart_add.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-09-04 02:59:56 UTC
  • mfrom: (1172)
  • mto: (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: aaron.bentley@utoronto.ca-20050904025956-776ba4f07de97700
Merged mpool's latest changes (~0.0.7)

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 FunctionalTestCase, TestCase
 
4
from bzrlib.selftest import TestCaseInTempDir, TestCase
5
5
from bzrlib.branch import Branch
6
6
from bzrlib.errors import NotBranchError, NotVersionedError
7
7
 
8
 
class TestSmartAdd(FunctionalTestCase):
 
8
class TestSmartAdd(TestCaseInTempDir):
9
9
 
10
10
    def test_add_dot_from_root(self):
11
11
        """Test adding . from the root of the tree.""" 
13
13
        paths = ("original/", "original/file1", "original/file2")
14
14
        self.build_tree(paths)
15
15
        branch = Branch(".", init=True)
16
 
        smart_add((".",), False, True)
 
16
        smart_add((".",), recurse=True)
17
17
        for path in paths:
18
18
            self.assertNotEqual(branch.inventory.path2id(path), None)
19
19
 
24
24
        self.build_tree(paths)
25
25
        branch = Branch(".", init=True)
26
26
        os.chdir("original")
27
 
        smart_add((".",), False, True)
 
27
        smart_add((".",), recurse=True)
28
28
        for path in paths:
29
29
            self.assertNotEqual(branch.inventory.path2id(path), None)
30
30
 
36
36
                        "branch/original/file2")
37
37
        self.build_tree(branch_paths)
38
38
        branch = Branch("branch", init=True)
39
 
        smart_add(("branch",), False, True)
 
39
        smart_add(("branch",))
40
40
        for path in paths:
41
41
            self.assertNotEqual(branch.inventory.path2id(path), None)
42
42
 
43
43
    def test_add_above_tree_preserves_tree(self):
44
44
        """Test nested trees are not affect by an add above them."""
45
 
        from bzrlib.add import smart_add
 
45
        from bzrlib.add import smart_add, add_reporter_null
 
46
        
46
47
        paths = ("original/", "original/file1", "original/file2")
47
 
        child_paths = ("path")
 
48
        child_paths = ("path",)
48
49
        full_child_paths = ("original/child", "original/child/path")
49
50
        build_paths = ("original/", "original/file1", "original/file2", 
50
51
                       "original/child/", "original/child/path")
 
52
        
51
53
        self.build_tree(build_paths)
52
54
        branch = Branch(".", init=True)
53
55
        child_branch = Branch("original/child", init=True)
54
 
        smart_add((".",), False, True)
 
56
        smart_add((".",), True, add_reporter_null)
55
57
        for path in paths:
56
58
            self.assertNotEqual((path, branch.inventory.path2id(path)),
57
59
                                (path, None))
67
69
        paths = ("file1", "file2")
68
70
        self.build_tree(paths)
69
71
        branch = Branch(".", init=True)
70
 
        smart_add(paths, False, True)
 
72
        smart_add(paths)
71
73
        for path in paths:
72
74
            self.assertNotEqual(branch.inventory.path2id(path), None)
73
75
            
74
 
class TestSmartAddBranch(FunctionalTestCase):
 
76
class TestSmartAddBranch(TestCaseInTempDir):
75
77
    """Test smart adds with a specified branch."""
76
78
 
77
79
    def test_add_dot_from_root(self):
80
82
        paths = ("original/", "original/file1", "original/file2")
81
83
        self.build_tree(paths)
82
84
        branch = Branch(".", init=True)
83
 
        smart_add_branch(branch, (".",), False, True)
 
85
        smart_add_branch(branch, (".",))
84
86
        for path in paths:
85
87
            self.assertNotEqual(branch.inventory.path2id(path), None)
86
88
 
91
93
        self.build_tree(paths)
92
94
        branch = Branch(".", init=True)
93
95
        os.chdir("original")
94
 
        smart_add_branch(branch, (".",), False, True)
 
96
        smart_add_branch(branch, (".",))
95
97
        for path in paths:
96
98
            self.assertNotEqual(branch.inventory.path2id(path), None)
97
99
 
103
105
                        "branch/original/file2")
104
106
        self.build_tree(branch_paths)
105
107
        branch = Branch("branch", init=True)
106
 
        smart_add_branch(branch, ("branch",), False, True)
 
108
        smart_add_branch(branch, ("branch",))
107
109
        for path in paths:
108
110
            self.assertNotEqual(branch.inventory.path2id(path), None)
109
111
 
118
120
        self.build_tree(build_paths)
119
121
        branch = Branch(".", init=True)
120
122
        child_branch = Branch("original/child", init=True)
121
 
        smart_add_branch(branch, (".",), False, True)
 
123
        smart_add_branch(branch, (".",))
122
124
        for path in paths:
123
125
            self.assertNotEqual((path, branch.inventory.path2id(path)),
124
126
                                (path, None))
134
136
        paths = ("file1", "file2")
135
137
        self.build_tree(paths)
136
138
        branch = Branch(".", init=True)
137
 
        smart_add_branch(branch, paths, False, True)
 
139
        smart_add_branch(branch, paths)
138
140
        for path in paths:
139
141
            self.assertNotEqual(branch.inventory.path2id(path), None)
140
142
 
141
 
class TestAddCallbacks(TestCase):
 
143
class TestAddCallbacks(TestCaseInTempDir):
142
144
 
143
145
    def setUp(self):
144
146
        from bzrlib.inventory import InventoryEntry
146
148
        self.entry = InventoryEntry("id", "name", "file", None)
147
149
 
148
150
    def test_null_callback(self):
149
 
        from bzrlib.add import _NullAddCallback
150
 
        _NullAddCallback(self.entry)
 
151
        from bzrlib.add import add_reporter_null
 
152
        add_reporter_null('path', 'file', self.entry)
151
153
 
152
154
    def test_print_callback(self):
153
 
        from bzrlib.add import _PrintAddCallback
 
155
        from bzrlib.add import add_reporter_print
154
156
        from StringIO import StringIO
155
157
        stdout = StringIO()
156
 
        self.apply_redirected(None, stdout, None, _PrintAddCallback,
157
 
                              self.entry)
158
 
        self.assertEqual(stdout.getvalue(), "added name\n")
 
158
        self.apply_redirected(None, stdout, None, add_reporter_print,
 
159
                              'path', 'file', self.entry)
 
160
        self.assertEqual(stdout.getvalue(), "added path\n")