/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 breezy/tests/test__dirstate_helpers.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 12:50:32 UTC
  • mfrom: (6679 work)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610125032-xb5rd5fjskjallos
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
500
500
        return lt_by_dirs
501
501
 
502
502
 
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()
505
505
 
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.
508
508
 
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
510
510
    implementation.
511
511
    """
512
512
 
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
517
517
 
518
 
    def assertCmpPathByDirblock(self, paths):
 
518
    def assertLtPathByDirblock(self, paths):
519
519
        """Compare all paths and make sure they evaluate to the correct order.
520
520
 
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)
531
531
 
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)
536
 
                if idx1 < idx2:
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))
541
 
                elif idx1 > idx2:
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))
546
 
                else: # idx1 == idx2
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))
551
540
 
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'])
556
545
 
557
546
    def test_tricky_paths(self):
558
 
        self.assertCmpPathByDirblock([
 
547
        self.assertLtPathByDirblock([
559
548
            # Contents of ''
560
549
            '', 'a', 'a-a', 'a=a', 'b',
561
550
            # Contents of 'a'
583
572
            # Contents of 'b',
584
573
            'b/a', 'b/b',
585
574
            ])
586
 
        self.assertCmpPathByDirblock([
 
575
        self.assertLtPathByDirblock([
587
576
                 # content of '/'
588
577
                 '', 'a', 'a-a', 'a-z', 'a=a', 'a=z',
589
578
                 # content of 'a/'
614
603
                ])
615
604
 
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')
624
613
 
625
614
    def test_nonascii(self):
626
 
        self.assertCmpPathByDirblock([
 
615
        self.assertLtPathByDirblock([
627
616
            # content of '/'
628
617
            '', 'a', '\xc2\xb5', '\xc3\xa5',
629
618
            # content of 'a'
641
630
            ])
642
631
 
643
632
 
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"""
646
635
 
647
636
    _test_needs_features = [compiled_dirstate_helpers_feature]
648
637
 
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
652
641
 
653
642
 
654
643
class TestMemRChr(tests.TestCase):