69.1.7
by Ursula Junque (Ursinha)
very basic implementation of a fakemethod to be able to test methods that need lplib |
1 |
__metaclass__ = type |
2 |
||
3 |
class FakeMethod: |
|
4 |
"""Catch any function or method call, and record the fact."""
|
|
5 |
||
6 |
def __init__(self, result=None, failure=None): |
|
7 |
"""Set up a fake function or method.
|
|
8 |
||
9 |
:param result: Value to return.
|
|
10 |
:param failure: Exception to raise.
|
|
11 |
"""
|
|
12 |
self.result = result |
|
13 |
self.failure = failure |
|
14 |
||
15 |
def __call__(self, *args, **kwargs): |
|
16 |
"""Catch an invocation to the method."""
|
|
17 |
||
18 |
if self.failure is None: |
|
19 |
return self.result |
|
20 |
else: |
|
21 |
raise self.failure |