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

« back to all changes in this revision

Viewing changes to tests/fakemethod.py

  • Committer: Ursula Junque (Ursinha)
  • Date: 2010-12-16 13:57:20 UTC
  • Revision ID: ursinha@canonical.com-20101216135720-gdo31w7hqirijyu8
removing cruft

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