/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-26 19:35:47 UTC
  • mfrom: (1813.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060626193547-43661d1377f72b4d
(robertc) Misc minor typos and the like.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import bzrlib
22
22
from bzrlib.branch import Branch
23
 
import bzrlib.bzrdir as bzrdir
 
23
from bzrlib import bzrdir, conflicts, errors, workingtree
24
24
from bzrlib.bzrdir import BzrDir
25
 
from bzrlib.conflicts import *
26
 
import bzrlib.errors as errors
27
25
from bzrlib.errors import NotBranchError, NotVersionedError
28
26
from bzrlib.lockdir import LockDir
29
27
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
30
28
from bzrlib.tests import TestCaseWithTransport, TestSkipped
31
29
from bzrlib.trace import mutter
32
30
from bzrlib.transport import get_transport
33
 
import bzrlib.workingtree as workingtree
34
31
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
35
32
                                WorkingTree)
36
33
 
205
202
        tree.unlock()
206
203
        self.assertEquals(our_lock.peek(), None)
207
204
 
 
205
 
 
206
class TestFormat2WorkingTree(TestCaseWithTransport):
 
207
    """Tests that are specific to format 2 trees."""
 
208
 
208
209
    def create_format2_tree(self, url):
209
 
        return BzrDir.create_standalone_workingtree(url)
 
210
        return self.make_branch_and_tree(
 
211
            url, format=bzrlib.bzrdir.BzrDirFormat6())
210
212
 
211
 
    def test_conflicts_format2(self):
 
213
    def test_conflicts(self):
212
214
        # test backwards compatability
213
215
        tree = self.create_format2_tree('.')
214
216
        self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
215
217
                          None)
216
218
        file('lala.BASE', 'wb').write('labase')
217
 
        expected = ContentsConflict('lala')
 
219
        expected = conflicts.ContentsConflict('lala')
218
220
        self.assertEqual(list(tree.conflicts()), [expected])
219
221
        file('lala', 'wb').write('la')
220
222
        tree.add('lala', 'lala-id')
221
 
        expected = ContentsConflict('lala', file_id='lala-id')
 
223
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
222
224
        self.assertEqual(list(tree.conflicts()), [expected])
223
225
        file('lala.THIS', 'wb').write('lathis')
224
226
        file('lala.OTHER', 'wb').write('laother')
225
227
        # When "text conflict"s happen, stem, THIS and OTHER are text
226
 
        expected = TextConflict('lala', file_id='lala-id')
 
228
        expected = conflicts.TextConflict('lala', file_id='lala-id')
227
229
        self.assertEqual(list(tree.conflicts()), [expected])
228
230
        os.unlink('lala.OTHER')
229
231
        os.mkdir('lala.OTHER')
230
 
        expected = ContentsConflict('lala', file_id='lala-id')
 
232
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
231
233
        self.assertEqual(list(tree.conflicts()), [expected])
 
234
 
 
235
 
 
236
class TestNonFormatSpecificCode(TestCaseWithTransport):
 
237
    """This class contains tests of workingtree that are not format specific."""
 
238
 
 
239
    
 
240
    def test_gen_file_id(self):
 
241
        self.assertStartsWith(bzrlib.workingtree.gen_file_id('bar'), 'bar-')
 
242
        self.assertStartsWith(bzrlib.workingtree.gen_file_id('Mwoo oof\t m'), 'Mwoooofm-')
 
243
        self.assertStartsWith(bzrlib.workingtree.gen_file_id('..gam.py'), 'gam.py-')
 
244
        self.assertStartsWith(bzrlib.workingtree.gen_file_id('..Mwoo oof\t m'), 'Mwoooofm-')
 
245
 
 
246
    def test_next_id_suffix(self):
 
247
        bzrlib.workingtree._gen_id_suffix = None
 
248
        bzrlib.workingtree._next_id_suffix()
 
249
        self.assertNotEqual(None, bzrlib.workingtree._gen_id_suffix)
 
250
        bzrlib.workingtree._gen_id_suffix = "foo-"
 
251
        bzrlib.workingtree._gen_id_serial = 1
 
252
        self.assertEqual("foo-2", bzrlib.workingtree._next_id_suffix())
 
253
        self.assertEqual("foo-3", bzrlib.workingtree._next_id_suffix())
 
254
        self.assertEqual("foo-4", bzrlib.workingtree._next_id_suffix())
 
255
        self.assertEqual("foo-5", bzrlib.workingtree._next_id_suffix())
 
256
        self.assertEqual("foo-6", bzrlib.workingtree._next_id_suffix())
 
257
        self.assertEqual("foo-7", bzrlib.workingtree._next_id_suffix())
 
258
        self.assertEqual("foo-8", bzrlib.workingtree._next_id_suffix())
 
259
        self.assertEqual("foo-9", bzrlib.workingtree._next_id_suffix())
 
260
        self.assertEqual("foo-10", bzrlib.workingtree._next_id_suffix())
 
261
 
 
262
    def test__translate_ignore_rule(self):
 
263
        tree = self.make_branch_and_tree('.')
 
264
        # translation should return the regex, the number of groups in it,
 
265
        # and the original rule in a tuple.
 
266
        # there are three sorts of ignore rules:
 
267
        # root only - regex is the rule itself without the leading ./
 
268
        self.assertEqual(
 
269
            "(rootdirrule$)", 
 
270
            tree._translate_ignore_rule("./rootdirrule"))
 
271
        # full path - regex is the rule itself
 
272
        self.assertEqual(
 
273
            "(path\\/to\\/file$)",
 
274
            tree._translate_ignore_rule("path/to/file"))
 
275
        # basename only rule - regex is a rule that ignores everything up
 
276
        # to the last / in the filename
 
277
        self.assertEqual(
 
278
            "((?:.*/)?(?!.*/)basenamerule$)",
 
279
            tree._translate_ignore_rule("basenamerule"))
 
280
 
 
281
    def test__combine_ignore_rules(self):
 
282
        tree = self.make_branch_and_tree('.')
 
283
        # the combined ignore regexs need the outer group indices
 
284
        # placed in a dictionary with the rules that were combined.
 
285
        # an empty set of rules
 
286
        # this is returned as a list of combined regex,rule sets, because
 
287
        # python has a limit of 100 combined regexes.
 
288
        compiled_rules = tree._combine_ignore_rules([])
 
289
        self.assertEqual([], compiled_rules)
 
290
        # one of each type of rule.
 
291
        compiled_rules = tree._combine_ignore_rules(
 
292
            ["rule1", "rule/two", "./three"])[0]
 
293
        # what type *is* the compiled regex to do an isinstance of ?
 
294
        self.assertEqual(3, compiled_rules[0].groups)
 
295
        self.assertEqual(
 
296
            {0:"rule1",1:"rule/two",2:"./three"},
 
297
            compiled_rules[1])
 
298
 
 
299
    def test__combine_ignore_rules_grouping(self):
 
300
        tree = self.make_branch_and_tree('.')
 
301
        # when there are too many rules, the output is split into groups of 100
 
302
        rules = []
 
303
        for index in range(198):
 
304
            rules.append('foo')
 
305
        self.assertEqual(2, len(tree._combine_ignore_rules(rules)))
 
306
 
 
307
    def test__get_ignore_rules_as_regex(self):
 
308
        tree = self.make_branch_and_tree('.')
 
309
        # test against the default rules.
 
310
        reference_output = tree._combine_ignore_rules(bzrlib.DEFAULT_IGNORE)[0]
 
311
        regex_rules = tree._get_ignore_rules_as_regex()[0]
 
312
        self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
 
313
        self.assertEqual(reference_output[1], regex_rules[1])