Skip to content

Commit

Permalink
update docstrings fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
toddsifleet committed Mar 16, 2015
1 parent 10ae689 commit 450823a
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 157 deletions.
65 changes: 24 additions & 41 deletions doubles/allowance.py
Expand Up @@ -50,8 +50,7 @@ def __init__(self, target, method_name, caller):
self._return_value = lambda *args, **kwargs: None

def and_raise(self, exception):
"""
Causes the double to raise the provided exception when called.
"""Causes the double to raise the provided exception when called.
:param Exception exception: The exception to raise.
"""
Expand All @@ -62,7 +61,8 @@ def proxy_exception(*args, **kwargs):
return self

def and_return(self, *return_values):
"""
"""Set a return value for an allowance
Causes the double to return the provided values in order. If multiple
values are provided, they are returned one at a time in sequence as the double is called.
If the double is called more times than there are return values, it should continue to
Expand All @@ -84,8 +84,7 @@ def and_return(self, *return_values):
return self

def and_return_result_of(self, return_value):
"""
Causes the double to return the result of calling the provided value.
""" Causes the double to return the result of calling the provided value.
:param return_value: A callable that will be invoked to determine the double's return value.
:type return_value: any callable object
Expand All @@ -98,18 +97,18 @@ def and_return_result_of(self, return_value):
return self

def is_satisfied(self):
"""
Returns a boolean indicating whether or not the double has been satisfied. Stubs are
always satisfied, but mocks are only satisifed if they've been called as was declared.
"""Returns a boolean indicating whether or not the double has been satisfied.
Stubs are always satisfied, but mocks are only satisifed if they've been
called as was declared.
:return: Whether or not the double is satisfied.
:rtype: bool
"""
return self._is_satisfied

def with_args(self, *args, **kwargs):
"""
Declares that the double can only be called with the provided arguments.
"""Declares that the double can only be called with the provided arguments.
:param args: Any positional arguments required for invocation.
:param kwargs: Any keyword arguments required for invocation.
Expand All @@ -131,8 +130,7 @@ def with_args_validator(self, matching_function):
return self

def __call__(self, *args, **kwargs):
"""
A short hand syntax for with_args
"""A short hand syntax for with_args
Allows callers to do:
allow(module).foo.with_args(1, 2)
Expand All @@ -153,8 +151,8 @@ def with_no_args(self):
return self

def satisfy_any_args_match(self):
"""
Returns a boolean indicating whether or not the stub will accept arbitrary arguments.
"""Returns a boolean indicating whether or not the stub will accept arbitrary arguments.
This will be true unless the user has specified otherwise using ``with_args`` or
``with_no_args``.
Expand All @@ -165,8 +163,7 @@ def satisfy_any_args_match(self):
return self.args is _any and self.kwargs is _any

def satisfy_exact_match(self, args, kwargs):
"""
Returns a boolean indicating whether or not the stub will accept the provided arguments.
"""Returns a boolean indicating whether or not the stub will accept the provided arguments.
:return: Whether or not the stub accepts the provided arguments.
:rtype: bool
Expand Down Expand Up @@ -206,8 +203,7 @@ def satisfy_custom_matcher(self, args, kwargs):
return False

def return_value(self, *args, **kwargs):
"""
Extracts the real value to be returned from the wrapping callable.
"""Extracts the real value to be returned from the wrapping callable.
:return: The value the double should return when called.
"""
Expand All @@ -216,8 +212,7 @@ def return_value(self, *args, **kwargs):
return self._return_value(*args, **kwargs)

def verify_arguments(self, args=None, kwargs=None):
"""
Ensures that the arguments specified match the signature of the real method.
"""Ensures that the arguments specified match the signature of the real method.
:raise: ``VerifyingDoubleError`` if the arguments do not match.
"""
Expand All @@ -233,8 +228,7 @@ def verify_arguments(self, args=None, kwargs=None):

@verify_count_is_non_negative
def exactly(self, n):
"""
Set an exact call count allowance
"""Set an exact call count allowance
:param integer n:
"""
Expand All @@ -244,8 +238,7 @@ def exactly(self, n):

@verify_count_is_non_negative
def at_least(self, n):
"""
Set a minimum call count allowance
"""Set a minimum call count allowance
:param integer n:
"""
Expand All @@ -255,8 +248,7 @@ def at_least(self, n):

@verify_count_is_non_negative
def at_most(self, n):
"""
Set a maximum call count allowance
"""Set a maximum call count allowance
:param integer n:
"""
Expand All @@ -265,25 +257,19 @@ def at_most(self, n):
return self

def never(self):
"""
Set an expected call count allowance of 0
"""
"""Set an expected call count allowance of 0"""

self.exactly(0)
return self

def once(self):
"""
Set an expected call count allowance of 1
"""
"""Set an expected call count allowance of 1"""

self.exactly(1)
return self

def twice(self):
"""
Set an expected call count allowance of 2
"""
"""Set an expected call count allowance of 2"""

self.exactly(2)
return self
Expand All @@ -294,8 +280,7 @@ def times(self):
time = times

def _called(self):
"""
Indicate that the allowance was called
"""Indicate that the allowance was called
:raise MockExpectationError if the allowance has been called too many times
"""
Expand All @@ -304,8 +289,7 @@ def _called(self):
self.raise_failure_exception()

def raise_failure_exception(self, expect_or_allow='Allowed'):
"""
Raises a ``MockExpectationError`` with a useful message.
"""Raises a ``MockExpectationError`` with a useful message.
:raise: ``MockExpectationError``
"""
Expand All @@ -323,8 +307,7 @@ def raise_failure_exception(self, expect_or_allow='Allowed'):
)

def _expected_argument_string(self):
"""
Generates a string describing what arguments the double expected.
"""Generates a string describing what arguments the double expected.
:return: A string describing expected arguments.
:rtype: str
Expand Down
47 changes: 15 additions & 32 deletions doubles/call_count_accumulator.py
Expand Up @@ -7,35 +7,31 @@ def __init__(self):
self._call_count = 0

def set_exact(self, n):
"""
Set an exact call count expectation
"""Set an exact call count expectation
:param integer n:
"""

self._exact = n

def set_minimum(self, n):
"""
Set a minimum call count expectation
"""Set a minimum call count expectation
:param integer n:
"""

self._minimum = n

def set_maximum(self, n):
"""
Set a maximum call count expectation
"""Set a maximum call count expectation
:param integer n:
"""

self._maximum = n

def has_too_many_calls(self):
"""
Test if there have been too many calls
"""Test if there have been too many calls
:rtype boolean
"""
Expand All @@ -47,8 +43,7 @@ def has_too_many_calls(self):
return False

def has_too_few_calls(self):
"""
Test if there have not been enough calls
"""Test if there have not been enough calls
:rtype boolean
"""
Expand All @@ -60,44 +55,38 @@ def has_too_few_calls(self):
return False

def has_incorrect_call_count(self):
"""
Test if there have not been a valid number of calls
"""Test if there have not been a valid number of calls
:rtype boolean
"""

return self.has_too_few_calls() or self.has_too_many_calls()

def has_correct_call_count(self):
"""
Test if there have been a valid number of calls
"""Test if there have been a valid number of calls
:rtype boolean
"""

return not self.has_incorrect_call_count()

def never(self):
"""
Test if the number of expect is 0
"""Test if the number of expect is 0
:rtype: boolean
"""

return self.has_exact and self._exact == 0

def called(self):
"""
Increment the call count
"""
"""Increment the call count"""

self._call_count += 1
return self

@property
def count(self):
"""
Extract the current call count
"""Extract the current call count
:rtype integer
"""
Expand All @@ -106,8 +95,7 @@ def count(self):

@property
def has_minimum(self):
"""
Test if self has a minimum call count set
"""Test if self has a minimum call count set
:rtype boolean
"""
Expand All @@ -116,8 +104,7 @@ def has_minimum(self):

@property
def has_maximum(self):
"""
Test if self has a maximum call count set
"""Test if self has a maximum call count set
:rtype boolean
"""
Expand All @@ -126,17 +113,15 @@ def has_maximum(self):

@property
def has_exact(self):
"""
Test if self has an exact call count set
"""Test if self has an exact call count set
:rtype boolean
"""

return getattr(self, '_exact', None) is not None

def _restriction_string(self):
"""
Get a string explaining the expectation currently set
"""Get a string explaining the expectation currently set
e.g `at least 5 times`, `at most 1 time`, or `2 times`
Expand All @@ -159,9 +144,7 @@ def _restriction_string(self):
)

def error_string(self):
"""
Get a string explaining the difference between the expected and
actual call count.
"""Returns a well formed error message
e.g at least 5 times but was called 4 times
Expand Down
9 changes: 3 additions & 6 deletions doubles/class_double.py
Expand Up @@ -6,8 +6,7 @@


def patch_class(input_class):
"""
Create a new class based on the input_class.
"""Create a new class based on the input_class.
:param class input_class: The class to patch.
:rtype class:
Expand Down Expand Up @@ -41,8 +40,7 @@ def __init__(self, path):
self._target = Target(self._doubles_target)

def __call__(self, *args, **kwargs):
"""
Verify arguments and proxy to _doubles__new__
"""Verify arguments and proxy to _doubles__new__
:rtype obj:
:raises VerifyingDoubleArgumentError: If args/kwargs don't match the expected argumenst of
Expand All @@ -52,8 +50,7 @@ def __call__(self, *args, **kwargs):
return self._doubles__new__(*args, **kwargs)

def _doubles__new__(self, *args, **kwargs):
"""
Raises an UnallowedMethodCallError
"""Raises an UnallowedMethodCallError
NOTE: This method is here only to raise if it has not been stubbed
"""
Expand Down
6 changes: 2 additions & 4 deletions doubles/instance_double.py
Expand Up @@ -6,8 +6,7 @@


def _get_doubles_target(module, class_name, path):
"""
Validate and return the class to be doubled.
"""Validate and return the class to be doubled.
:param module module: The module that contains the class that will be doubled.
:param str class_name: The name of the class that will be doubled.
Expand Down Expand Up @@ -35,8 +34,7 @@ def _get_doubles_target(module, class_name, path):


class InstanceDouble(ObjectDouble):
"""
A pure double representing an instance of the target class.
"""A pure double representing an instance of the target class.
Any kwargs supplied will be set as attributes on the instance that is
created.
Expand Down

0 comments on commit 450823a

Please sign in to comment.