Beispiel #1
0
def verify(obj, times=1, atleast=None, atmost=None, between=None):
  if times < 0:
    raise ArgumentError("""'times' argument has invalid value. 
                           It should be at least 0. You wanted to set it to: %i""" % times)
  if _multiple_arguments_in_use(atleast, atmost, between):
    raise ArgumentError("""Sure you know what you are doing?
                           You can set only one of the arguments: 'atleast', 'atmost' or 'between'.""")
  if _invalid_argument(atleast):
    raise ArgumentError("""'atleast' argument has invalid value.
                           It should be at least 1.  You wanted to set it to: %i""" % atleast)
  if _invalid_argument(atmost):
    raise ArgumentError("""'atmost' argument has invalid value.
                           It should be at least 1.  You wanted to set it to: %i""" % atmost)
  if _invalid_between(between):
    raise ArgumentError("""'between' argument has invalid value.
                           It should consist of positive values with second number not greater than first
                           e.g. [1, 4] or [0, 3] or [2, 2]
                           You wanted to set it to: %s""" % between)

  if isinstance(obj, Mock):
    mock = obj
  else:
    mock = mock_registry.mock_for(obj)
               
  if atleast:
    mock.verification = verification.AtLeast(atleast)
  elif atmost:
    mock.verification = verification.AtMost(atmost)
  elif between:
    mock.verification = verification.Between(*between)
  else:
    mock.verification = verification.Times(times)
  return mock
Beispiel #2
0
def when(obj, strict=True):
    if isinstance(obj, Mock):
        mock = obj
    else:
        mock = mock_registry.mock_for(obj)
        if mock is None:
            mock = Mock(obj, strict=strict)

    mock.expect_stubbing()
    return mock
Beispiel #3
0
def when(obj, strict=True):
    if isinstance(obj, Mock):
        mock = obj
    else:
        mock = mock_registry.mock_for(obj)
        if mock is None:
            mock = Mock(obj, strict=strict)

    mock.expect_stubbing()
    return mock
Beispiel #4
0
def when(obj, strict=True):
    if isinstance(obj, mock):
        theMock = obj
    else:
        theMock = mock_registry.mock_for(obj)
        if theMock is None:
            theMock = mock(obj, strict=strict)
            # If we call when on something that is not TestDouble that means we're trying to stub real object,
            # (class, module etc.). Not to be confused with generating stubs from real classes.
            theMock.stubbing_real_object = True

    theMock.expect_stubbing()
    return theMock
Beispiel #5
0
def when(obj, strict=True):
    if isinstance(obj, mock):
        theMock = obj
    else:
        theMock = mock_registry.mock_for(obj)
        if theMock is None:
            theMock = mock(obj, strict=strict)
            # If we call when on something that is not TestDouble that means we're trying to stub real object,
            # (class, module etc.). Not to be confused with generating stubs from real classes.
            theMock.stubbing_real_object = True

    theMock.expect_stubbing()
    return theMock
Beispiel #6
0
def verify(obj,
           times=1,
           atleast=None,
           atmost=None,
           between=None,
           inorder=False):
    if times < 0:
        raise ArgumentError("""'times' argument has invalid value. 
                           It should be at least 0. You wanted to set it to: %i"""
                            % times)
    if _multiple_arguments_in_use(atleast, atmost, between):
        raise ArgumentError("""Sure you know what you are doing?
                           You can set only one of the arguments: 'atleast', 'atmost' or 'between'."""
                            )
    if _invalid_argument(atleast):
        raise ArgumentError("""'atleast' argument has invalid value.
                           It should be at least 1.  You wanted to set it to: %i"""
                            % atleast)
    if _invalid_argument(atmost):
        raise ArgumentError("""'atmost' argument has invalid value.
                           It should be at least 1.  You wanted to set it to: %i"""
                            % atmost)
    if _invalid_between(between):
        raise ArgumentError("""'between' argument has invalid value.
                           It should consist of positive values with second number not greater than first
                           e.g. [1, 4] or [0, 3] or [2, 2]
                           You wanted to set it to: %s""" % between)

    if isinstance(obj, TestDouble):
        mocked_object = obj
    else:
        mocked_object = mock_registry.mock_for(obj)

    if atleast:
        mocked_object.verification = verification.AtLeast(atleast)
    elif atmost:
        mocked_object.verification = verification.AtMost(atmost)
    elif between:
        mocked_object.verification = verification.Between(*between)
    else:
        mocked_object.verification = verification.Times(times)

    if inorder:
        mocked_object.verification = verification.InOrder(
            mocked_object.verification)

    return mocked_object
Beispiel #7
0
def verify(obj, times=1, atleast=None, atmost=None, between=None,
           inorder=False):
    if times < 0:
        raise ArgumentError("'times' argument has invalid value.\n"
                            "It should be at least 0. You wanted to set it to:"
                            " %i" % times)
    if _multiple_arguments_in_use(atleast, atmost, between):
        raise ArgumentError("You can set only one of the arguments: 'atleast', "
                            "'atmost' or 'between'.""")
    if _invalid_argument(atleast):
        raise ArgumentError("'atleast' argument has invalid value.\n"
                            "It should be at least 1.  You wanted to set it "
                            "to: %i" % atleast)
    if _invalid_argument(atmost):
        raise ArgumentError("'atmost' argument has invalid value.\n"
                            "It should be at least 1.  You wanted to set it "
                            "to: %i""" % atmost)
    if _invalid_between(between):
        raise ArgumentError("""'between' argument has invalid value.
            It should consist of positive values with second number not greater
            than first e.g. [1, 4] or [0, 3] or [2, 2]
            You wanted to set it to: %s""" % between)

    if isinstance(obj, TestDouble):
        mocked_object = obj
    else:
        mocked_object = mock_registry.mock_for(obj)

    if atleast:
        mocked_object.verification = verification.AtLeast(atleast)
    elif atmost:
        mocked_object.verification = verification.AtMost(atmost)
    elif between:
        mocked_object.verification = verification.Between(*between)
    else:
        mocked_object.verification = verification.Times(times)

    if inorder:
        mocked_object.verification = verification.InOrder(
            mocked_object.verification)

    return mocked_object