/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_log.py

  • Committer: Guillermo Gonzalez
  • Date: 2008-07-05 23:06:12 UTC
  • mto: (3542.1.1 logdisplayers)
  • mto: This revision was merged to the branch mainline in revision 3556.
  • Revision ID: guillo.gonzo@gmail.com-20080705230612-0v78sasowqo8yflr
 * bzrlib.log.show_roperties don't hide handler errors
 * renames custom_properties_handler_registry to properties_handler_registry  
 * tests moved out of blackbox 
 * created TestCaseWithoutPropsHandler to avoid using properties handlers 
   in log tests that assertDiff against the full log output

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
 
20
from bzrlib import log, registry
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(TestLongLogFormatter, self).tearDown()
 
53
        # restore the custom properties handler registry
 
54
        log.properties_handler_registry = \
 
55
            self.properties_handler_registry
 
56
 
 
57
 
41
58
class LogCatcher(LogFormatter):
42
59
    """Pull log messages into list rather than displaying them.
43
60
 
355
372
            wt.unlock()
356
373
 
357
374
 
358
 
class TestLongLogFormatter(TestCaseWithTransport):
 
375
class TestLongLogFormatter(TestCaseWithoutPropsHandler):
359
376
 
360
377
    def test_verbose_log(self):
361
378
        """Verbose log includes changed files
561
578
  add a
562
579
''')
563
580
 
 
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_author_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_author_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')
564
648
 
565
649
 
566
650
class TestLineLogFormatter(TestCaseWithTransport):