~free.ekanayaka/storm/any-expr

« back to all changes in this revision

Viewing changes to tests/mocker.py

  • Committer: Michael Hudson
  • Date: 2008-05-18 10:22:29 UTC
  • mto: (215.8.12 resultset-groupby-2)
  • mto: This revision was merged to the branch mainline in revision 229.
  • Revision ID: michael.hudson@canonical.com-20080518102229-rvh6oacfe9x1841w
the fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
627
627
    def patch(self, object, spec=True):
628
628
        """Patch an existing object to reproduce recorded events.
629
629
 
630
 
        @param object: Class or instance to be patched.
631
 
        @param spec: Method calls will be checked for correctness against
632
 
                     the given object, which may be a class or an instance
633
 
                     where attributes will be looked up.  Defaults to the
634
 
                     the C{object} parameter.  May be set to None explicitly,
635
 
                     in which case spec checking is disabled.  Checks may
636
 
                     also be disabled explicitly on a per-event basis with
637
 
                     the L{nospec()} method.
638
 
 
639
630
        The result of this method is still a mock object, which can be
640
631
        used like any other mock object to record events.  The difference
641
632
        is that when the mocker is put on replay mode, the *real* object
661
652
        to its original state once the L{restore()} method is called
662
653
        (explicitly, or implicitly with alternative conventions, such as
663
654
        a C{with mocker:} block, or a MockerTestCase class).
 
655
 
 
656
        @param object: Class or instance to be patched.
 
657
        @param spec: Method calls will be checked for correctness against
 
658
                     the given object, which may be a class or an instance
 
659
                     where attributes will be looked up.  Defaults to the
 
660
                     the C{object} parameter.  May be set to None explicitly,
 
661
                     in which case spec checking is disabled.  Checks may
 
662
                     also be disabled explicitly on a per-event basis with
 
663
                     the L{nospec()} method.
664
664
        """
665
665
        if spec is True:
666
666
            spec = object
875
875
    def after(self, *path_holders):
876
876
        """Last recorded event must happen after events referred to.
877
877
 
878
 
        @param path_holders: Objects returned as the result of recorded events
879
 
                             which should happen before the last recorded event
880
 
 
881
878
        As an example, the idiom::
882
879
 
883
880
            expect(mock.x).after(mock.y, mock.z)
891
888
            mocker.order(expr_z, expr_x)
892
889
 
893
890
        See L{order()} for more information.
 
891
 
 
892
        @param path_holders: Objects returned as the result of recorded events
 
893
                             which should happen before the last recorded event
894
894
        """
895
895
        last_path = self._events[-1].path
896
896
        for path_holder in path_holders:
899
899
    def before(self, *path_holders):
900
900
        """Last recorded event must happen before events referred to.
901
901
 
902
 
        @param path_holders: Objects returned as the result of recorded events
903
 
                             which should happen after the last recorded event
904
 
 
905
902
        As an example, the idiom::
906
903
 
907
904
            expect(mock.x).before(mock.y, mock.z)
915
912
            mocker.order(expr_x, expr_z)
916
913
 
917
914
        See L{order()} for more information.
 
915
 
 
916
        @param path_holders: Objects returned as the result of recorded events
 
917
                             which should happen after the last recorded event
918
918
        """
919
919
        last_path = self._events[-1].path
920
920
        for path_holder in path_holders:
940
940
    def passthrough(self, result_callback=None):
941
941
        """Make the last recorded event run on the real object once seen.
942
942
 
943
 
        @param result_callback: If given, this function will be called with
944
 
            the result of the *real* method call as the only argument.
945
 
 
946
943
        This can only be used on proxies, as returned by the L{proxy()}
947
944
        and L{replace()} methods, or on mocks representing patched objects,
948
945
        as returned by the L{patch()} method.
 
946
 
 
947
        @param result_callback: If given, this function will be called with
 
948
            the result of the *real* method call as the only argument.
949
949
        """
950
950
        event = self._events[-1]
951
951
        if event.path.root_object is None: