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

  • Committer: Carl Friedrich Bolz
  • Date: 2006-09-06 21:17:57 UTC
  • mfrom: (1986 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2026.
  • Revision ID: cfbolz@gmx.de-20060906211757-b0d73953b54efbc9
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
import bzrlib.plugin
64
64
import bzrlib.progress as progress
65
65
from bzrlib.revision import common_ancestor
66
 
from bzrlib.revisionspec import RevisionSpec
67
66
import bzrlib.store
68
67
from bzrlib import symbol_versioning
69
68
import bzrlib.trace
580
579
            self.fail("%r is an instance of %s rather than %s" % (
581
580
                obj, obj.__class__, kls))
582
581
 
583
 
    def callDeprecated(self, expected, callable, *args, **kwargs):
584
 
        """Assert that a callable is deprecated in a particular way.
 
582
    def _capture_warnings(self, a_callable, *args, **kwargs):
 
583
        """A helper for callDeprecated and applyDeprecated.
585
584
 
586
 
        :param expected: a list of the deprecation warnings expected, in order
587
 
        :param callable: The callable to call
 
585
        :param a_callable: A callable to call.
588
586
        :param args: The positional arguments for the callable
589
587
        :param kwargs: The keyword arguments for the callable
 
588
        :return: A tuple (warnings, result). result is the result of calling
 
589
            a_callable(*args, **kwargs).
590
590
        """
591
591
        local_warnings = []
592
592
        def capture_warnings(msg, cls, stacklevel=None):
 
593
            # we've hooked into a deprecation specific callpath,
 
594
            # only deprecations should getting sent via it.
593
595
            self.assertEqual(cls, DeprecationWarning)
594
596
            local_warnings.append(msg)
595
 
        method = symbol_versioning.warn
 
597
        original_warning_method = symbol_versioning.warn
596
598
        symbol_versioning.set_warning_method(capture_warnings)
597
599
        try:
598
 
            result = callable(*args, **kwargs)
 
600
            result = a_callable(*args, **kwargs)
599
601
        finally:
600
 
            symbol_versioning.set_warning_method(method)
601
 
        self.assertEqual(expected, local_warnings)
 
602
            symbol_versioning.set_warning_method(original_warning_method)
 
603
        return (local_warnings, result)
 
604
 
 
605
    def applyDeprecated(self, deprecation_format, a_callable, *args, **kwargs):
 
606
        """Call a deprecated callable without warning the user.
 
607
 
 
608
        :param deprecation_format: The deprecation format that the callable
 
609
            should have been deprecated with. This is the same type as the 
 
610
            parameter to deprecated_method/deprecated_function. If the 
 
611
            callable is not deprecated with this format, an assertion error
 
612
            will be raised.
 
613
        :param a_callable: A callable to call. This may be a bound method or
 
614
            a regular function. It will be called with *args and **kwargs.
 
615
        :param args: The positional arguments for the callable
 
616
        :param kwargs: The keyword arguments for the callable
 
617
        :return: The result of a_callable(*args, **kwargs)
 
618
        """
 
619
        call_warnings, result = self._capture_warnings(a_callable,
 
620
            *args, **kwargs)
 
621
        expected_first_warning = symbol_versioning.deprecation_string(
 
622
            a_callable, deprecation_format)
 
623
        if len(call_warnings) == 0:
 
624
            self.fail("No assertion generated by call to %s" %
 
625
                a_callable)
 
626
        self.assertEqual(expected_first_warning, call_warnings[0])
 
627
        return result
 
628
 
 
629
    def callDeprecated(self, expected, callable, *args, **kwargs):
 
630
        """Assert that a callable is deprecated in a particular way.
 
631
 
 
632
        This is a very precise test for unusual requirements. The 
 
633
        applyDeprecated helper function is probably more suited for most tests
 
634
        as it allows you to simply specify the deprecation format being used
 
635
        and will ensure that that is issued for the function being called.
 
636
 
 
637
        :param expected: a list of the deprecation warnings expected, in order
 
638
        :param callable: The callable to call
 
639
        :param args: The positional arguments for the callable
 
640
        :param kwargs: The keyword arguments for the callable
 
641
        """
 
642
        call_warnings, result = self._capture_warnings(callable,
 
643
            *args, **kwargs)
 
644
        self.assertEqual(expected, call_warnings)
602
645
        return result
603
646
 
604
647
    def _startLogFile(self):
874
917
        def cleanup_environment():
875
918
            for env_var, value in env_changes.iteritems():
876
919
                if value is None:
877
 
                    del os.environ[env_var]
 
920
                    if env_var in os.environ:
 
921
                        del os.environ[env_var]
878
922
                else:
879
923
                    os.environ[env_var] = value
880
924
 
943
987
            sys.stderr = real_stderr
944
988
            sys.stdin = real_stdin
945
989
 
 
990
    @symbol_versioning.deprecated_method(symbol_versioning.zero_eleven)
946
991
    def merge(self, branch_from, wt_to):
947
992
        """A helper for tests to do a ui-less merge.
948
993