This module holds classes to help test the running of the infrastructure.
The Dummy module holds dummy classes that do nothing. They is primarily used to test implementations of infrastructure components.
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.
This is a Dummy that raises an error when called.
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
This is a Dummy that will block forever.
HangingDummy(*args, **kwargs) | A dummy that hangs |
HangingDummy.__call__(*args, **kwargs) | Sleeps for three years in an infinite loop |
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')
'[34mrampage[0;0m' attribute called on [31mKingKong[0;0m
[31mKingKong[0;0m Called
[1mArgs:[0;0m ('fay wray',)
[1mKwargs:[0;0m {}
'[34mrampage[0;0m' attribute called on [31mKingKong[0;0m
[31mKingKong[0;0m Called
[1mArgs:[0;0m ('fay wray',)
[1mKwargs:[0;0m {}
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).