~ursinha/lp-qa-tools/bzr-tarmacland

« back to all changes in this revision

Viewing changes to tests/fakemethod.py

  • Committer: James Henstridge
  • Date: 2007-12-17 14:51:19 UTC
  • Revision ID: james@jamesh.id.au-20071217145119-bxw361m02rkbk5w4
update Launchpad URL in setup.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
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