/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

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
577
576
            self.fail("%r is an instance of %s rather than %s" % (
578
577
                obj, obj.__class__, kls))
579
578
 
580
 
    def callDeprecated(self, expected, callable, *args, **kwargs):
581
 
        """Assert that a callable is deprecated in a particular way.
 
579
    def _capture_warnings(self, a_callable, *args, **kwargs):
 
580
        """A helper for callDeprecated and applyDeprecated.
582
581
 
583
 
        :param expected: a list of the deprecation warnings expected, in order
584
 
        :param callable: The callable to call
 
582
        :param a_callable: A callable to call.
585
583
        :param args: The positional arguments for the callable
586
584
        :param kwargs: The keyword arguments for the callable
 
585
        :return: A tuple (warnings, result). result is the result of calling
 
586
            a_callable(*args, **kwargs).
587
587
        """
588
588
        local_warnings = []
589
589
        def capture_warnings(msg, cls, stacklevel=None):
 
590
            # we've hooked into a deprecation specific callpath,
 
591
            # only deprecations should getting sent via it.
590
592
            self.assertEqual(cls, DeprecationWarning)
591
593
            local_warnings.append(msg)
592
 
        method = symbol_versioning.warn
 
594
        original_warning_method = symbol_versioning.warn
593
595
        symbol_versioning.set_warning_method(capture_warnings)
594
596
        try:
595
 
            result = callable(*args, **kwargs)
 
597
            result = a_callable(*args, **kwargs)
596
598
        finally:
597
 
            symbol_versioning.set_warning_method(method)
598
 
        self.assertEqual(expected, local_warnings)
 
599
            symbol_versioning.set_warning_method(original_warning_method)
 
600
        return (local_warnings, result)
 
601
 
 
602
    def applyDeprecated(self, deprecation_format, a_callable, *args, **kwargs):
 
603
        """Call a deprecated callable without warning the user.
 
604
 
 
605
        :param deprecation_format: The deprecation format that the callable
 
606
            should have been deprecated with. This is the same type as the 
 
607
            parameter to deprecated_method/deprecated_function. If the 
 
608
            callable is not deprecated with this format, an assertion error
 
609
            will be raised.
 
610
        :param a_callable: A callable to call. This may be a bound method or
 
611
            a regular function. It will be called with *args and **kwargs.
 
612
        :param args: The positional arguments for the callable
 
613
        :param kwargs: The keyword arguments for the callable
 
614
        :return: The result of a_callable(*args, **kwargs)
 
615
        """
 
616
        call_warnings, result = self._capture_warnings(a_callable,
 
617
            *args, **kwargs)
 
618
        expected_first_warning = symbol_versioning.deprecation_string(
 
619
            a_callable, deprecation_format)
 
620
        if len(call_warnings) == 0:
 
621
            self.fail("No assertion generated by call to %s" %
 
622
                a_callable)
 
623
        self.assertEqual(expected_first_warning, call_warnings[0])
 
624
        return result
 
625
 
 
626
    def callDeprecated(self, expected, callable, *args, **kwargs):
 
627
        """Assert that a callable is deprecated in a particular way.
 
628
 
 
629
        This is a very precise test for unusual requirements. The 
 
630
        applyDeprecated helper function is probably more suited for most tests
 
631
        as it allows you to simply specify the deprecation format being used
 
632
        and will ensure that that is issued for the function being called.
 
633
 
 
634
        :param expected: a list of the deprecation warnings expected, in order
 
635
        :param callable: The callable to call
 
636
        :param args: The positional arguments for the callable
 
637
        :param kwargs: The keyword arguments for the callable
 
638
        """
 
639
        call_warnings, result = self._capture_warnings(callable,
 
640
            *args, **kwargs)
 
641
        self.assertEqual(expected, call_warnings)
599
642
        return result
600
643
 
601
644
    def _startLogFile(self):
853
896
        def cleanup_environment():
854
897
            for env_var, value in env_changes.iteritems():
855
898
                if value is None:
856
 
                    del os.environ[env_var]
 
899
                    if env_var in os.environ:
 
900
                        del os.environ[env_var]
857
901
                else:
858
902
                    os.environ[env_var] = value
859
903
 
922
966
            sys.stderr = real_stderr
923
967
            sys.stdin = real_stdin
924
968
 
 
969
    @symbol_versioning.deprecated_method(symbol_versioning.zero_eleven)
925
970
    def merge(self, branch_from, wt_to):
926
971
        """A helper for tests to do a ui-less merge.
927
972
 
1057
1102
                # On jam's machine, make_kernel_like_tree is:
1058
1103
                #   put:    4.5-7.5s (averaging 6s)
1059
1104
                #   append: 2.9-4.5s
1060
 
                transport.append(urlutils.escape(name), StringIO(content))
 
1105
                #   put_non_atomic: 2.9-4.5s
 
1106
                transport.put_bytes_non_atomic(urlutils.escape(name), content)
1061
1107
 
1062
1108
    def build_tree_contents(self, shape):
1063
1109
        build_tree_contents(shape)