~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Aaron Bentley
  • Date: 2007-12-25 04:17:50 UTC
  • mto: This revision was merged to the branch mainline in revision 3160.
  • Revision ID: aaron.bentley@utoronto.ca-20071225041750-t6chr3pmgnebvqcz
Handle non-directory parent conflicts (abentley, #177390)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
from cStringIO import StringIO
19
19
 
20
 
from bzrlib import log, registry
 
20
from bzrlib import log
21
21
from bzrlib.tests import TestCase, TestCaseWithTransport
22
22
from bzrlib.log import (show_log,
23
23
                        get_view_revisions,
38
38
    )
39
39
 
40
40
 
41
 
class TestCaseWithoutPropsHandler(TestCaseWithTransport):
42
 
 
43
 
    def setUp(self):
44
 
        super(TestCaseWithoutPropsHandler, self).setUp()
45
 
        # keep a reference to the "current" custom prop. handler registry
46
 
        self.properties_handler_registry = \
47
 
            log.properties_handler_registry
48
 
        # clean up the registry in log
49
 
        log.properties_handler_registry = registry.Registry()
50
 
        
51
 
    def _cleanup(self):
52
 
        super(TestCaseWithoutPropsHandler, self)._cleanup()
53
 
        # restore the custom properties handler registry
54
 
        log.properties_handler_registry = \
55
 
            self.properties_handler_registry
56
 
 
57
 
 
58
41
class LogCatcher(LogFormatter):
59
42
    """Pull log messages into list rather than displaying them.
60
43
 
372
355
            wt.unlock()
373
356
 
374
357
 
375
 
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
 
358
class TestLongLogFormatter(TestCaseWithTransport):
376
359
 
377
360
    def test_verbose_log(self):
378
361
        """Verbose log includes changed files
442
425
    message:
443
426
      merge branch 2
444
427
        ------------------------------------------------------------
445
 
        revno: 1.2.1
 
428
        revno: 1.1.1.1.1
446
429
        committer: Lorem Ipsum <test@example.com>
447
430
        branch nick: smallerchild
448
431
        timestamp: Just now
578
561
  add a
579
562
''')
580
563
 
581
 
    def test_properties_in_log(self):
582
 
        """Log includes the custom properties returned by the registered 
583
 
        handlers.
584
 
        """
585
 
        wt = self.make_branch_and_tree('.')
586
 
        b = wt.branch
587
 
        self.build_tree(['a'])
588
 
        wt.add('a')
589
 
        b.nick = 'test_properties_in_log'
590
 
        wt.commit(message='add a',
591
 
                  timestamp=1132711707,
592
 
                  timezone=36000,
593
 
                  committer='Lorem Ipsum <test@example.com>',
594
 
                  author='John Doe <jdoe@example.com>')
595
 
        sio = StringIO()
596
 
        formatter = LongLogFormatter(to_file=sio)
597
 
        try:
598
 
            def trivial_custom_prop_handler(revision):
599
 
                return {'test_prop':'test_value'}
600
 
            
601
 
            log.properties_handler_registry.register(
602
 
                'trivial_custom_prop_handler', 
603
 
                trivial_custom_prop_handler)
604
 
            show_log(b, formatter)
605
 
        finally:
606
 
            log.properties_handler_registry.remove(
607
 
                'trivial_custom_prop_handler')
608
 
            self.assertEqualDiff(sio.getvalue(), '''\
609
 
------------------------------------------------------------
610
 
revno: 1
611
 
test_prop: test_value
612
 
author: John Doe <jdoe@example.com>
613
 
committer: Lorem Ipsum <test@example.com>
614
 
branch nick: test_properties_in_log
615
 
timestamp: Wed 2005-11-23 12:08:27 +1000
616
 
message:
617
 
  add a
618
 
''')
619
 
 
620
 
    def test_error_in_properties_handler(self):
621
 
        """Log includes the custom properties returned by the registered 
622
 
        handlers.
623
 
        """
624
 
        wt = self.make_branch_and_tree('.')
625
 
        b = wt.branch
626
 
        self.build_tree(['a'])
627
 
        wt.add('a')
628
 
        b.nick = 'test_author_log'
629
 
        wt.commit(message='add a',
630
 
                  timestamp=1132711707,
631
 
                  timezone=36000,
632
 
                  committer='Lorem Ipsum <test@example.com>',
633
 
                  author='John Doe <jdoe@example.com>',
634
 
                  revprops={'first_prop':'first_value'})
635
 
        sio = StringIO()
636
 
        formatter = LongLogFormatter(to_file=sio)
637
 
        try:
638
 
            def trivial_custom_prop_handler(revision):
639
 
                raise StandardError("a test error")
640
 
            
641
 
            log.properties_handler_registry.register(
642
 
                'trivial_custom_prop_handler', 
643
 
                trivial_custom_prop_handler)
644
 
            self.assertRaises(StandardError, show_log, b, formatter,)
645
 
        finally:
646
 
            log.properties_handler_registry.remove(
647
 
                'trivial_custom_prop_handler')
648
 
                
649
 
    def test_properties_handler_bad_argument(self):
650
 
        wt = self.make_branch_and_tree('.')
651
 
        b = wt.branch
652
 
        self.build_tree(['a'])
653
 
        wt.add('a')
654
 
        b.nick = 'test_author_log'
655
 
        wt.commit(message='add a',
656
 
                  timestamp=1132711707,
657
 
                  timezone=36000,
658
 
                  committer='Lorem Ipsum <test@example.com>',
659
 
                  author='John Doe <jdoe@example.com>',
660
 
                  revprops={'a_prop':'test_value'})
661
 
        sio = StringIO()
662
 
        formatter = LongLogFormatter(to_file=sio)
663
 
        try:
664
 
            def bad_argument_prop_handler(revision):
665
 
                return {'custom_prop_name':revision.properties['a_prop']}
666
 
                
667
 
            log.properties_handler_registry.register(
668
 
                'bad_argument_prop_handler', 
669
 
                bad_argument_prop_handler)
670
 
            
671
 
            self.assertRaises(AttributeError, formatter.show_properties, 
672
 
                'a revision', '')
673
 
            
674
 
            revision = b.repository.get_revision(b.last_revision())
675
 
            formatter.show_properties(revision, '')
676
 
            self.assertEqualDiff(sio.getvalue(),
677
 
                '''custom_prop_name: test_value\n''')
678
 
        finally:
679
 
            log.properties_handler_registry.remove(
680
 
                'bad_argument_prop_handler')
681
564
 
682
565
 
683
566
class TestLineLogFormatter(TestCaseWithTransport):
791
674
        full_rev_nos_for_reference = {
792
675
            '1': '1',
793
676
            '2': '2',
794
 
            '3a': '2.1.1', #first commit tree 3
795
 
            '3b': '2.2.1', # first commit tree 2
 
677
            '3a': '2.2.1', #first commit tree 3
 
678
            '3b': '2.1.1', # first commit tree 2
796
679
            '3c': '3', #merges 3b to main
797
 
            '4a': '2.2.2', # second commit tree 2
 
680
            '4a': '2.1.2', # second commit tree 2
798
681
            '4b': '4', # merges 4a to main
799
682
            }
800
683
        return mainline_revs, rev_nos, wt
802
685
    def test_get_view_revisions_forward(self):
803
686
        """Test the get_view_revisions method"""
804
687
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
805
 
        wt.lock_read()
806
 
        self.addCleanup(wt.unlock)
807
688
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
808
689
                                            'forward'))
809
690
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0)],
815
696
    def test_get_view_revisions_reverse(self):
816
697
        """Test the get_view_revisions with reverse"""
817
698
        mainline_revs, rev_nos, wt = self.make_tree_with_commits()
818
 
        wt.lock_read()
819
 
        self.addCleanup(wt.unlock)
820
699
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
821
700
                                            'reverse'))
822
701
        self.assertEqual([('3', '3', 0), ('2', '2', 0), ('1', '1', 0), ],
828
707
    def test_get_view_revisions_merge(self):
829
708
        """Test get_view_revisions when there are merges"""
830
709
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
831
 
        wt.lock_read()
832
 
        self.addCleanup(wt.unlock)
833
710
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
834
711
                                            'forward'))
835
712
        self.assertEqual([('1', '1', 0), ('2', '2', 0), ('3', '3', 0),
844
721
    def test_get_view_revisions_merge_reverse(self):
845
722
        """Test get_view_revisions in reverse when there are merges"""
846
723
        mainline_revs, rev_nos, wt = self.make_tree_with_merges()
847
 
        wt.lock_read()
848
 
        self.addCleanup(wt.unlock)
849
724
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
850
725
                                            'reverse'))
851
726
        self.assertEqual([('4b', '4', 0), ('4a', '3.1.1', 1),
860
735
    def test_get_view_revisions_merge2(self):
861
736
        """Test get_view_revisions when there are merges"""
862
737
        mainline_revs, rev_nos, wt = self.make_tree_with_many_merges()
863
 
        wt.lock_read()
864
 
        self.addCleanup(wt.unlock)
865
738
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
866
739
                                            'forward'))
867
740
        expected = [('1', '1', 0), ('2', '2', 0), ('3c', '3', 0),
868
 
            ('3a', '2.1.1', 1), ('3b', '2.2.1', 1), ('4b', '4', 0),
869
 
            ('4a', '2.2.2', 1)]
 
741
            ('3a', '2.2.1', 1), ('3b', '2.1.1', 1), ('4b', '4', 0),
 
742
            ('4a', '2.1.2', 1)]
870
743
        self.assertEqual(expected, revisions)
871
744
        revisions = list(get_view_revisions(mainline_revs, rev_nos, wt.branch,
872
745
                                             'forward', include_merges=False))
1008
881
        # f3 should be marked as modified by revisions A, B, C, and D
1009
882
        self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1010
883
 
1011
 
    def test_file_id_with_ghosts(self):
1012
 
        # This is testing bug #209948, where having a ghost would cause
1013
 
        # _filter_revisions_touching_file_id() to fail.
1014
 
        tree = self.create_tree_with_single_merge()
1015
 
        # We need to add a revision, so switch back to a write-locked tree
1016
 
        tree.unlock()
1017
 
        tree.lock_write()
1018
 
        first_parent = tree.last_revision()
1019
 
        tree.set_parent_ids([first_parent, 'ghost-revision-id'])
1020
 
        self.build_tree_contents([('tree/f1', 'A\nB\nXX\n')])
1021
 
        tree.commit('commit with a ghost', rev_id='XX')
1022
 
        self.assertAllRevisionsForFileID(tree, 'f1-id', ['XX', 'B', 'A'])
1023
 
        self.assertAllRevisionsForFileID(tree, 'f2-id', ['D', 'C', 'A'])
1024
 
 
1025
884
 
1026
885
class TestShowChangedRevisions(TestCaseWithTransport):
1027
886