ScatterHQ / machinist

A library for constructing finite state machines
Apache License 2.0
57 stars 12 forks source link

Not sure if trivialInput actually produces a provider of IRichInput #14

Closed cyli closed 10 years ago

cyli commented 10 years ago

The docstring for _FiniteStateInterpreter.receive says:

Deliver an input symbol to the wrapped L{IFiniteStateMachine} from the given rich 
input and deliver the resulting outputs to the wrapped L{IOutputExecutor}.

    @param input: An instance of one of the rich input types this state
        machine was initialized with.

While it doesn't say that it must be an IRichInput provider, I am not sure why it wouldn't and also how else one would accept both rich inputs and symbols directly, as per https://github.com/hybridcluster/machinist/issues/7.

However, the implementation of trivialInput is such that:

>>> from machinist import IRichInput, trivialInput
>>> from twisted.python.constants import Names, NamedConstant
>>> from zope.interface.verify import verifyObject
>>> class Input(Names):
...    apple = NamedConstant()
...    
>>> a = trivialInput(Input.apple)
>>> verifyObject(IRichInput, a)
True
>>> IRichInput.providedBy(a())
False
>>> verifyObject(IRichInput, a())
    Traceback (most recent call last):
  File "test_stuff.py", line 13, in <module>
    print verifyObject(IRichInput, a())
  File "/Users/cyli/.virtualenvs/machinist/lib/python2.7/site-packages/zope/interface/verify.py", line 105, in verifyObject
    return _verify(iface, candidate, tentative, vtype='o')
  File "/Users/cyli/.virtualenvs/machinist/lib/python2.7/site-packages/zope/interface/verify.py", line 50, in _verify
    raise DoesNotImplement(iface)
zope.interface.exceptions.DoesNotImplement: An object does not implement interface <InterfaceClass machinist._fsm.IRichInput>

trivialInput should probably produce something whose instance would also be a provider of IRichInput