The Dummy

This module holds classes to help test the running of the infrastructure.

The Dummy Class

The Dummy module holds dummy classes that do nothing. They is primarily used to test implementations of infrastructure components.

DummyClass -|> BaseClass
DummyClass o- CallClass

DummyClass(*args, **kwargs) The Dummy Class does nothing
DummyClass.__call__(*args, **kwargs) Logs the fact that it was called
DummyClass.__str__() Returns the class name
DummyClass.__getattr__(attribute) To catch unimplemented parts of the class and log them

The Dummy Class logs (at the info) level when it is created and when it is called.

A Crash Dummy

This is a Dummy that raises an error when called.

CrashDummy -|> DummyClass

CrashDummy(error[, error_message, function]) A dummy that crashes
CrashDummy.check_rep() crashes on check_rep() if that’s the function
CrashDummy.close() Crashes if close is the function
CrashDummy.__getattr__(attribute) To catch unimplemented parts of the class and log them

Note

check_rep and close don’t need to be implemented to crash, but the Composite is checking if it has the attributes before calling them so they have to be implemented to crash them

The Hanging Dummy

This is a Dummy that will block forever.

HangingDummy -|> DummyClass

HangingDummy(*args, **kwargs) A dummy that hangs
HangingDummy.__call__(*args, **kwargs) Sleeps for three years in an infinite loop

An Example

As an example we can create an operator and make some fake calls to it (I do not think the logging will get captured by Pweave, though).

if output_documentation:
    class FakeLogger(object):
        def info(self, output):
            print output

    class KingKong(DummyClass):
        def __init__(self, *args, **kwargs):
            super(KingKong, self).__init__(*args, **kwargs)
            self._logger = FakeLogger()
            return


    kongs = (KingKong(index, name) for index,name in enumerate('Kong MightyJoe'.split()))
    for kong in kongs:
        kong.rampage()
        kong('fay wray')
'rampage' attribute called on KingKong
KingKong Called
Args: ('fay wray',)
Kwargs: {}
'rampage' attribute called on KingKong
KingKong Called
Args: ('fay wray',)
Kwargs: {}

I had to add a fake logger because pweave does not capture logging output. If you run this module:

python dummy.py

You should see what is being sent to the logger in full color (without the extra ANSI codes).