Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 8: Stubs cannot raise exceptions fix #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion ludibrio/specification/unit/stub.dt
Expand Up @@ -51,7 +51,6 @@ Stubs are test doubles programmed to provide inputs to and outputs from collabor
>>> greetings
Greetings


4. Should support both method and property configuration:
>>> with greetings as greetings:
... greetings.excuse_me() >> 'Com licença'
Expand Down Expand Up @@ -79,3 +78,11 @@ Stubs are test doubles programmed to provide inputs to and outputs from collabor
>>> print greetings.hello('Gustavo')
Ola, Gustavo

5. Stubs should be able to raise exceptions
>>> with Stub() as stubException:
... stubException.hello() >> KeyError('KEY ERROR')
>>> stubException.hello()
Traceback (most recent call last):
...
KeyError: 'KEY ERROR'

7 changes: 5 additions & 2 deletions ludibrio/stub.py
Expand Up @@ -55,14 +55,17 @@ def _new_expectation(self, expectation):
self.__expectation__.append(expectation)

def __rshift__(self, response):
self.__expectation__[-1][3] = response
self.__expectation__[-1][3] = response
__lshift__ = __rshift__

def _expectation_value(self, attr, args=[], kargs={}):
for position, (attr_expectation, args_expectation, kargs_expectation, response) in enumerate(self.__expectation__):
if (attr_expectation, args_expectation, kargs_expectation) == (attr, args, kargs):
self._to_the_end(position)
return response
if isinstance(response, Exception):
raise response
else:
return response
if self._has_proxy():
return self._proxy(attr, args, kargs)
self._attribute_expectation(attr, args, kargs)
Expand Down