def comparator(self, subject, params):
        was_called_matcher = WasCalledMatcher()
        if not was_called_matcher.matches(subject):
            self._reason = was_called_matcher.reason()
            return False
        subject = Spy.get_spy(subject)
        expected_call_args, expected_call_kwargs = params

        call_args, call_kwargs = subject.last_call

        expected_named_args = _get_all_named_args(subject.signature,
                                                  expected_call_args,
                                                  expected_call_kwargs)
        actual_named_args = _get_all_named_args(subject.signature, call_args,
                                                call_kwargs)

        expected_varargs = _get_varargs(subject.signature, expected_call_args)
        actual_varargs = _get_varargs(subject.signature, call_args)

        matches_varargs = MatchesListMatcher(expected_varargs)
        matches_named_args = MatchesDictMatcher(expected_named_args)
        self._reason = "it was called with <" + format_arguments(
            call_args, call_kwargs) + ">"
        return matches_varargs.list_comparator(actual_varargs, expected_varargs) and \
               matches_named_args.comparator(actual_named_args, expected_named_args)
Exemple #2
0
 def _(self):
     with stub(SomeClass.some_class_method) as spy:
         SomeClass.some_class_method("anything", ["can"], go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
         expect(Spy.get_spy(SomeClass.some_class_method)).to_be(spy)
Exemple #3
0
 def _(self):
     some_instance = SomeClass()
     with stub('some_method', on=some_instance) as spy:
         some_instance.some_method("some_arg 123")
         expect(spy.last_call).to_be((("some_arg 123", ), {}))
         expect(Spy.get_spy(
             some_instance.some_method)).to_be(spy)
Exemple #4
0
 def _(self):
     with stub(some_class.some_module_method, on=some_class) as spy:
         some_class.some_module_method("anything", ["can"],
                                       go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
         expect(Spy.get_spy(
             some_class.some_module_method)).to_be(spy)
Exemple #5
0
 def comparator(self, subject):
     subject = Spy.get_spy(subject)
     if not hasattr(subject, 'last_call'):
         self._reason = "its calls were not tracked. Hint: use stub() to track its calls"
         return False
     elif subject.last_call is None:
         self._reason = "it was never called"
         return False
     else:
         return True
Exemple #6
0
 def unmatcherify(self, params, subject):
     return Expectation.unmatcherify(self, params, Spy.get_spy(subject))