500
500
return lt_by_dirs
503
class TestCmpPathByDirblock(tests.TestCase):
504
"""Test an implementation of _cmp_path_by_dirblock()
503
class TestLtPathByDirblock(tests.TestCase):
504
"""Test an implementation of _lt_path_by_dirblock()
506
_cmp_path_by_dirblock() compares two paths using the sort order used by
506
_lt_path_by_dirblock() compares two paths using the sort order used by
507
507
DirState. All paths in the same directory are sorted together.
509
Child test cases can override ``get_cmp_path_by_dirblock`` to test a specific
509
Child test cases can override ``get_lt_path_by_dirblock`` to test a specific
513
def get_cmp_path_by_dirblock(self):
514
"""Get a specific implementation of _cmp_path_by_dirblock."""
515
from breezy.bzr._dirstate_helpers_py import _cmp_path_by_dirblock
516
return _cmp_path_by_dirblock
513
def get_lt_path_by_dirblock(self):
514
"""Get a specific implementation of _lt_path_by_dirblock."""
515
from ..bzr._dirstate_helpers_py import _lt_path_by_dirblock
516
return _lt_path_by_dirblock
518
def assertCmpPathByDirblock(self, paths):
518
def assertLtPathByDirblock(self, paths):
519
519
"""Compare all paths and make sure they evaluate to the correct order.
521
521
This does N^2 comparisons. It is assumed that ``paths`` is properly
529
529
return dirname.split('/'), basename
530
530
self.assertEqual(sorted(paths, key=_key), paths)
532
cmp_path_by_dirblock = self.get_cmp_path_by_dirblock()
532
lt_path_by_dirblock = self.get_lt_path_by_dirblock()
533
533
for idx1, path1 in enumerate(paths):
534
534
for idx2, path2 in enumerate(paths):
535
cmp_val = cmp_path_by_dirblock(path1, path2)
537
self.assertTrue(cmp_val < 0,
538
'%s did not state that %r came before %r, cmp=%s'
539
% (cmp_path_by_dirblock.__name__,
540
path1, path2, cmp_val))
542
self.assertTrue(cmp_val > 0,
543
'%s did not state that %r came after %r, cmp=%s'
544
% (cmp_path_by_dirblock.__name__,
545
path1, path2, cmp_val))
547
self.assertTrue(cmp_val == 0,
548
'%s did not state that %r == %r, cmp=%s'
549
% (cmp_path_by_dirblock.__name__,
550
path1, path2, cmp_val))
535
lt_result = lt_path_by_dirblock(path1, path2)
536
self.assertEqual(idx1 < idx2, lt_result,
537
'%s did not state that %r < %r, lt=%s'
538
% (lt_path_by_dirblock.__name__,
539
path1, path2, lt_result))
552
541
def test_cmp_simple_paths(self):
553
542
"""Compare against the empty string."""
554
self.assertCmpPathByDirblock(['', 'a', 'ab', 'abc', 'a/b/c', 'b/d/e'])
555
self.assertCmpPathByDirblock(['kl', 'ab/cd', 'ab/ef', 'gh/ij'])
543
self.assertLtPathByDirblock(['', 'a', 'ab', 'abc', 'a/b/c', 'b/d/e'])
544
self.assertLtPathByDirblock(['kl', 'ab/cd', 'ab/ef', 'gh/ij'])
557
546
def test_tricky_paths(self):
558
self.assertCmpPathByDirblock([
547
self.assertLtPathByDirblock([
560
549
'', 'a', 'a-a', 'a=a', 'b',
561
550
# Contents of 'a'
616
605
def test_unicode_not_allowed(self):
617
cmp_path_by_dirblock = self.get_cmp_path_by_dirblock()
618
self.assertRaises(TypeError, cmp_path_by_dirblock, u'Uni', 'str')
619
self.assertRaises(TypeError, cmp_path_by_dirblock, 'str', u'Uni')
620
self.assertRaises(TypeError, cmp_path_by_dirblock, u'Uni', u'Uni')
621
self.assertRaises(TypeError, cmp_path_by_dirblock, u'x/Uni', 'x/str')
622
self.assertRaises(TypeError, cmp_path_by_dirblock, 'x/str', u'x/Uni')
623
self.assertRaises(TypeError, cmp_path_by_dirblock, u'x/Uni', u'x/Uni')
606
lt_path_by_dirblock = self.get_lt_path_by_dirblock()
607
self.assertRaises(TypeError, lt_path_by_dirblock, u'Uni', 'str')
608
self.assertRaises(TypeError, lt_path_by_dirblock, 'str', u'Uni')
609
self.assertRaises(TypeError, lt_path_by_dirblock, u'Uni', u'Uni')
610
self.assertRaises(TypeError, lt_path_by_dirblock, u'x/Uni', 'x/str')
611
self.assertRaises(TypeError, lt_path_by_dirblock, 'x/str', u'x/Uni')
612
self.assertRaises(TypeError, lt_path_by_dirblock, u'x/Uni', u'x/Uni')
625
614
def test_nonascii(self):
626
self.assertCmpPathByDirblock([
615
self.assertLtPathByDirblock([
628
617
'', 'a', '\xc2\xb5', '\xc3\xa5',
644
class TestCompiledCmpPathByDirblock(TestCmpPathByDirblock):
645
"""Test the pyrex implementation of _cmp_path_by_dirblock"""
633
class TestCompiledLtPathByDirblock(TestLtPathByDirblock):
634
"""Test the pyrex implementation of _lt_path_by_dirblock"""
647
636
_test_needs_features = [compiled_dirstate_helpers_feature]
649
def get_cmp_by_dirs(self):
650
from breezy.bzr._dirstate_helpers_pyx import _cmp_path_by_dirblock
651
return _cmp_path_by_dirblock
638
def get_lt_path_by_dirblock(self):
639
from ..bzr._dirstate_helpers_pyx import _lt_path_by_dirblock
640
return _lt_path_by_dirblock
654
643
class TestMemRChr(tests.TestCase):