| Home | Trees | Indices | Help |
|
|---|
|
|
object --+
|
type --+
|
RuleBasedStateMachineMetaClass
A metaclass that makes it easy to create simple rules for a
RuleBasedStateMachine.
'Simple' in this context means that the rule we want to create
a) calls a method that takes no argument, and then
b) doesn't check any results
The only thing that we're testing with a rule like this is that calling the
method never results in an unhandled exception. Ideally, we would check the
results of calling methods, but even the lazy route is surprisingly useful
in a state machine test. Advice: begin by adding as many of these simple
rules as possible and then gradually replace them with richer rules and
checks as the tests develop and experience indicates which checks are most
valuable.
Suppose that we are testing self.panel in our state machine and want to call
the methods 'foo' on self.panel.bar and 'gar' on self.panel.mar. We could
write this:
class PanelMachine(stateful.RuleBaseStateMachine):
def __init__(self):
super(PanelMachine, self).__init__()
self.panel = MyPanel()
@stateful.rule()
def foo(self):
self.panel.bar.foo()
@stateful.rule()
def gar(self):
self.panel.mar.gar()
But this quickly becomes tedious if we want to test a large number of such
methods. Our metaclass will allow us to generate the desired rules for our
state machine by adding strings to the SIMPLE_RULES tuple defined on the
class:
class PanelMachine(stateful.RuleBaseStateMachine):
__metaclass__ = RuleBasedStateMachineMetaClass
SIMPLE_RULES = ('panel.bar.foo', 'panel.bar.gar')
def __init__(self):
super(PanelMachine, self).__init__()
self.panel = MyPanel()
|
|||
|
Inherited from Inherited from |
|||
|
|||
| function |
|
||
|
|||
| a new object with type S, a subtype of T |
|
||
|
|||
|
Inherited from |
|||
|
|||
Prior to regular class creation, iterates through the SIMPLE_RULES tuple defined on the state machine class and add stateful.rules for each of the items.
|
Returns a test function that simply calls the method specified by component_path
|
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Aug 8 02:53:06 2017 | http://epydoc.sourceforge.net |