~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2006-11-02 22:48:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2132.
  • Revision ID: john@arbash-meinel.com-20061102224849-9683d741ce3fbe38
Update file and revision id generators.
Move id generation to its own file, deprecate the old functions, 
make gen_revision_id() not require an email address in the
username, and use rand_chars() instead of hexlify(rand_bytes())

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib.lockdir import LockDir
28
28
from bzrlib.mutabletree import needs_tree_write_lock
29
29
from bzrlib.osutils import pathjoin, getcwd, has_symlinks
 
30
from bzrlib.symbol_versioning import zero_thirteen
30
31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
31
32
from bzrlib.trace import mutter
32
33
from bzrlib.transport import get_transport
258
259
class TestNonFormatSpecificCode(TestCaseWithTransport):
259
260
    """This class contains tests of workingtree that are not format specific."""
260
261
 
261
 
    
262
262
    def test_gen_file_id(self):
263
 
        gen_file_id = bzrlib.workingtree.gen_file_id
264
 
 
265
 
        # We try to use the filename if possible
266
 
        self.assertStartsWith(gen_file_id('bar'), 'bar-')
267
 
 
268
 
        # but we squash capitalization, and remove non word characters
269
 
        self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
270
 
 
271
 
        # We also remove leading '.' characters to prevent hidden file-ids
272
 
        self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
273
 
        self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
274
 
 
275
 
        # we remove unicode characters, and still don't end up with a 
276
 
        # hidden file id
277
 
        self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
 
263
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
 
264
                                      'filename')
 
265
        self.assertStartsWith(file_id, 'filename-')
 
266
 
 
267
    def test_gen_root_id(self):
 
268
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
 
269
        self.assertStartsWith(file_id, 'tree_root-')
278
270
        
279
 
        # Our current method of generating unique ids adds 33 characters
280
 
        # plus an serial number (log10(N) characters)
281
 
        # to the end of the filename. We now restrict the filename portion to
282
 
        # be <= 20 characters, so the maximum length should now be approx < 60
283
 
 
284
 
        # Test both case squashing and length restriction
285
 
        fid = gen_file_id('A'*50 + '.txt')
286
 
        self.assertStartsWith(fid, 'a'*20 + '-')
287
 
        self.failUnless(len(fid) < 60)
288
 
 
289
 
        # restricting length happens after the other actions, so
290
 
        # we preserve as much as possible
291
 
        fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
292
 
        self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
293
 
        self.failUnless(len(fid) < 60)
294
 
 
295
 
    def test_next_id_suffix(self):
296
 
        bzrlib.workingtree._gen_id_suffix = None
297
 
        bzrlib.workingtree._next_id_suffix()
298
 
        self.assertNotEqual(None, bzrlib.workingtree._gen_id_suffix)
299
 
        bzrlib.workingtree._gen_id_suffix = "foo-"
300
 
        bzrlib.workingtree._gen_id_serial = 1
301
 
        self.assertEqual("foo-2", bzrlib.workingtree._next_id_suffix())
302
 
        self.assertEqual("foo-3", bzrlib.workingtree._next_id_suffix())
303
 
        self.assertEqual("foo-4", bzrlib.workingtree._next_id_suffix())
304
 
        self.assertEqual("foo-5", bzrlib.workingtree._next_id_suffix())
305
 
        self.assertEqual("foo-6", bzrlib.workingtree._next_id_suffix())
306
 
        self.assertEqual("foo-7", bzrlib.workingtree._next_id_suffix())
307
 
        self.assertEqual("foo-8", bzrlib.workingtree._next_id_suffix())
308
 
        self.assertEqual("foo-9", bzrlib.workingtree._next_id_suffix())
309
 
        self.assertEqual("foo-10", bzrlib.workingtree._next_id_suffix())
310
 
 
311
271
    def test__translate_ignore_rule(self):
312
272
        tree = self.make_branch_and_tree('.')
313
273
        # translation should return the regex, the number of groups in it,