~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_add.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-11 20:39:06 UTC
  • mfrom: (1830.3.17 mac)
  • Revision ID: pqm@pqm.ubuntu.com-20060711203906-910d9b22b82b219c
(jam) support mac-normalization for unicode files.

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 import errors, osutils
4
5
from bzrlib.add import smart_add, smart_add_tree
5
 
from bzrlib.tests import TestCaseWithTransport, TestCase
 
6
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
6
7
from bzrlib.errors import NoSuchFile
7
8
from bzrlib.inventory import InventoryFile, Inventory
8
9
from bzrlib.workingtree import WorkingTree
9
10
 
 
11
 
10
12
class TestSmartAdd(TestCaseWithTransport):
11
13
 
12
14
    def test_add_dot_from_root(self):
15
17
        paths = ("original/", "original/file1", "original/file2")
16
18
        self.build_tree(paths)
17
19
        wt = self.make_branch_and_tree('.')
18
 
        branch = wt.branch
19
20
        smart_add_tree(wt, (u".",))
20
21
        for path in paths:
21
22
            self.assertNotEqual(wt.path2id(path), None)
26
27
        paths = ("original/", "original/file1", "original/file2")
27
28
        self.build_tree(paths)
28
29
        wt = self.make_branch_and_tree('.')
29
 
        branch = wt.branch
30
30
        os.chdir("original")
31
31
        smart_add_tree(wt, (u".",))
32
32
        for path in paths:
40
40
                        "branch/original/file2")
41
41
        self.build_tree(branch_paths)
42
42
        wt = self.make_branch_and_tree('branch')
43
 
        branch = wt.branch
44
43
        smart_add_tree(wt, ("branch",))
45
44
        for path in paths:
46
45
            self.assertNotEqual(wt.path2id(path), None)
56
55
        
57
56
        self.build_tree(build_paths)
58
57
        wt = self.make_branch_and_tree('.')
59
 
        branch = wt.branch
60
58
        child_tree = self.make_branch_and_tree('original/child')
61
59
        smart_add_tree(wt, (".",))
62
60
        for path in paths:
103
101
        from bzrlib.commands import run_bzr
104
102
        eq = self.assertEqual
105
103
        wt = self.make_branch_and_tree('.')
106
 
        branch = wt.branch
107
104
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
108
105
        eq(list(wt.unknowns()), ['inertiatic'])
109
106
        self.capture('add --dry-run .')
113
110
        """Test smart-adding a file that does not exist."""
114
111
        from bzrlib.add import smart_add
115
112
        wt = self.make_branch_and_tree('.')
116
 
        branch = wt.branch
117
113
        self.assertRaises(NoSuchFile, smart_add_tree, wt, 'non-existant-file')
118
114
 
119
115
    def test_returns_and_ignores(self):
120
116
        """Correctly returns added/ignored files"""
121
117
        from bzrlib.commands import run_bzr
122
118
        wt = self.make_branch_and_tree('.')
123
 
        branch = wt.branch
124
119
        # no files should be ignored by default, so we need to create
125
120
        # an ignore rule - we create one for the pyc files, which means
126
121
        # CVS should not be ignored.
142
137
        paths = ("original/", "original/file1", "original/file2")
143
138
        self.build_tree(paths)
144
139
        wt = self.make_branch_and_tree('.')
145
 
        branch = wt.branch
146
140
        smart_add_tree(wt, (u".",))
147
141
        for path in paths:
148
142
            self.assertNotEqual(wt.path2id(path), None)
149
143
 
150
144
    def test_add_dot_from_subdir(self):
151
145
        """Test adding . from a subdir of the tree.""" 
152
 
        from bzrlib.add import smart_add_tree
153
146
        paths = ("original/", "original/file1", "original/file2")
154
147
        self.build_tree(paths)
155
148
        wt = self.make_branch_and_tree('.')
156
 
        branch = wt.branch
157
149
        os.chdir("original")
158
150
        smart_add_tree(wt, (u".",))
159
151
        for path in paths:
161
153
 
162
154
    def test_add_tree_from_above_tree(self):
163
155
        """Test adding a tree from above the tree.""" 
164
 
        from bzrlib.add import smart_add_tree
165
156
        paths = ("original/", "original/file1", "original/file2")
166
157
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
167
158
                        "branch/original/file2")
168
159
        self.build_tree(branch_paths)
169
160
        tree = self.make_branch_and_tree('branch')
170
 
        branch = tree.branch
171
161
        smart_add_tree(tree, ("branch",))
172
162
        for path in paths:
173
163
            self.assertNotEqual(tree.path2id(path), None)
174
164
 
175
165
    def test_add_above_tree_preserves_tree(self):
176
166
        """Test nested trees are not affect by an add above them."""
177
 
        from bzrlib.add import smart_add_tree
178
167
        paths = ("original/", "original/file1", "original/file2")
179
168
        child_paths = ("path")
180
169
        full_child_paths = ("original/child", "original/child/path")
182
171
                       "original/child/", "original/child/path")
183
172
        self.build_tree(build_paths)
184
173
        tree = self.make_branch_and_tree('.')
185
 
        branch = tree.branch
186
174
        child_tree = self.make_branch_and_tree("original/child")
187
175
        smart_add_tree(tree, (u".",))
188
176
        for path in paths:
196
184
 
197
185
    def test_add_paths(self):
198
186
        """Test smart-adding a list of paths."""
199
 
        from bzrlib.add import smart_add_tree
200
187
        paths = ("file1", "file2")
201
188
        self.build_tree(paths)
202
189
        wt = self.make_branch_and_tree('.')
203
 
        branch = wt.branch
204
190
        smart_add_tree(wt, paths)
205
191
        for path in paths:
206
192
            self.assertNotEqual(wt.path2id(path), None)
207
193
 
208
194
 
 
195
class TestAddNonNormalized(TestCaseWithTransport):
 
196
 
 
197
    def make(self):
 
198
        try:
 
199
            self.build_tree([u'a\u030a'])
 
200
        except UnicodeError:
 
201
            raise TestSkipped('Filesystem cannot create unicode filenames')
 
202
 
 
203
        self.wt = self.make_branch_and_tree('.')
 
204
 
 
205
    def test_accessible_explicit(self):
 
206
        self.make()
 
207
        orig = osutils.normalized_filename
 
208
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
209
        try:
 
210
            smart_add_tree(self.wt, [u'a\u030a'])
 
211
            self.assertEqual([(u'\xe5', 'file')],
 
212
                    [(path, ie.kind) for path,ie in 
 
213
                        self.wt.inventory.iter_entries()])
 
214
        finally:
 
215
            osutils.normalized_filename = orig
 
216
 
 
217
    def test_accessible_implicit(self):
 
218
        self.make()
 
219
        orig = osutils.normalized_filename
 
220
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
221
        try:
 
222
            smart_add_tree(self.wt, [])
 
223
            self.assertEqual([(u'\xe5', 'file')],
 
224
                    [(path, ie.kind) for path,ie in 
 
225
                        self.wt.inventory.iter_entries()])
 
226
        finally:
 
227
            osutils.normalized_filename = orig
 
228
 
 
229
    def test_inaccessible_explicit(self):
 
230
        self.make()
 
231
        orig = osutils.normalized_filename
 
232
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
 
233
        try:
 
234
            self.assertRaises(errors.InvalidNormalization,
 
235
                    smart_add_tree, self.wt, [u'a\u030a'])
 
236
        finally:
 
237
            osutils.normalized_filename = orig
 
238
 
 
239
    def test_inaccessible_implicit(self):
 
240
        self.make()
 
241
        orig = osutils.normalized_filename
 
242
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
 
243
        try:
 
244
            # TODO: jam 20060701 In the future, this should probably
 
245
            #       just ignore files that don't fit the normalization
 
246
            #       rules, rather than exploding
 
247
            self.assertRaises(errors.InvalidNormalization,
 
248
                    smart_add_tree, self.wt, [])
 
249
        finally:
 
250
            osutils.normalized_filename = orig
 
251
 
 
252
 
209
253
class TestAddActions(TestCase):
210
254
 
211
255
    def test_quiet(self):