def _record_method_call(self, name, args, kwargs, result): method_repr = create_method_repr(name, args, kwargs) if self._recording_mode: if self._check_return: print "recording: %s => %s" % (method_repr, result) else: print "recording: %s" % method_repr if self._check_args: if self._check_return: self._legacy_object_record.append( (name, self._dump_args(args, kwargs), result)) else: self._legacy_object_record.append( (name, self._dump_args(args, kwargs), None)) else: if self._check_return: self._legacy_object_record.append( (name, None, None, result)) else: self._legacy_object_record.append( (name, None, None, None)) else: if len(self._legacy_object_record) == 0: raise AssertionError("Unexpected method was called: %s" % method_repr) record = self._legacy_object_record[0] del self._legacy_object_record[0] if name != record[0]: raise AssertionError("Unexpected method was called: %s" % method_repr) if self._check_args: str_args = self._dump_args(args, kwargs) if str_args != record[1]: expected = create_method_repr(name, record[1][0], dict(record[1][1])) raise AssertionError( "Argument value of %s() was changed: %s => %s" % (name, method_repr, expected)) if self._check_return: if result != record[2]: raise AssertionError( "Return value of %s was changed: %s => %s" % (method_repr, record[2], result))
def _record_method_call(self, name, args, kwargs, result): method_repr = create_method_repr(name, args, kwargs) if self._recording_mode: if self._check_return: print "recording: %s => %s" % (method_repr, result) else: print "recording: %s" % method_repr if self._check_args: if self._check_return: self._legacy_object_record.append( (name, self._dump_args(args, kwargs), result)) else: self._legacy_object_record.append( (name, self._dump_args(args, kwargs), None)) else: if self._check_return: self._legacy_object_record.append( (name, None, None, result)) else: self._legacy_object_record.append((name, None, None, None)) else: if len(self._legacy_object_record) == 0: raise AssertionError("Unexpected method was called: %s" % method_repr) record = self._legacy_object_record[0] del self._legacy_object_record[0] if name != record[0]: raise AssertionError("Unexpected method was called: %s" % method_repr) if self._check_args: str_args = self._dump_args(args, kwargs) if str_args != record[1]: expected = create_method_repr(name, record[1][0], dict(record[1][1])) raise AssertionError( "Argument value of %s() was changed: %s => %s" % (name, method_repr, expected)) if self._check_return: if result != record[2]: raise AssertionError( "Return value of %s was changed: %s => %s" % (method_repr, record[2], result))
def str_for_status(self, args, kwargs): return "MockObject.%s" % create_method_repr(self.name, args, kwargs)