State :: AnyOrder

The AnyOrder class is what underlies the add_any_order() methods on MockSession and other Container classes. AnyOrder instances are used to assert that the order in which a group of API function calls occur is unimportant, only that they do indeed occur (in contrast with Sequence).

Details

  • AnyOrder inherits from the Container and State base classes (in that order) and conforms to the protocols defined by both.

    This page details only areas where AnyOrder extends or deviates from those protocols.

  • The AnyOrder() constructor takes a single, optional argument.

    AnyOrder()
    AnyOrder([state_1, state_2, ..., state_n])

    If AnyOrder() is invoked without arguments, an empty AnyOrder instance will be created. This instance must be populated manually using the add_* methods defined in the Container protocol.

    If AnyOrder() is invoked with an argument, the passed-in object must be capable of iteration (all Containers are capable of iteration), and all elements in the iterable must be instances of the State class. These states will be used to populate the newly-created AnyOrder object.

  • AnyOrder.__call__ conforms to the Container protocol.

    When AnyOrder.__call__ is invoked to validate an API function call, the invocant will delegate the validation to a contained state. For example:

    anyorder = AnyOrder()
                                
    seq_1 = anyorder.add_sequence()
    seq_1.add_command(function_1)
    seq_1.add_command(function_2)
    
    seq_2 = anyorder.add_sequence()
    seq_2.add_command(function_1)
    seq_2.add_command(function_3)

    When anyorder is asked to validate a call to function_1, it will iterate over its pool of available states until it finds one that approves the call. Subsequent validation requests will be directed to this state; if the state rejects an API call, it will be placed back in the available state pool. When this happens (the so-called "active state" is placed back in the pool), the states that anyorder tries next have to not only match the current call, but all calls that the just-demoted active state had approved.

    When the active state signals (via it's Container's next() method) that it has matched all the states it can, anyorder will it from the available state pool to a pool for exhausted states.

  • Invocations of AnyOrder.reset cause the pool of exhausted states to be merged back into the available state pool. AnyOrder.reset() also clears the queue of API calls that candidate active states must match, setting the invocant back to square one.

  • When iterating over AnyOrder instances, the order in which State objects will be returned is undefined.

svnmock