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

« back to all changes in this revision

Viewing changes to tests/fakemethod.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-14 06:47:52 UTC
  • Revision ID: andrew@bemusement.org-20091014064752-28xlcdfphzli4dce
Slightly hackish way to allow submitting branches I don't have locally.

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