SingleState Base Class

The SingleState base class provides a common superclass for State classes that can only validate a single API function call, such as Command and Error. It inherits from the State base class and extends the protocol defined there in the following way:

  • Subclasses of SingleState are recommended to define an __init__ method that takes at least two parameters, the second of which is optional.

    The first parameter will be a function-type object; this is the object that must be passed as the second parameter of __call__ if validation is to succeed. It is recommended that this object is stored in the instance's api_func attribute.

    The second parameter will be an iterable. This represents the arguments that must be passed to the API call if validation is to succeed. It is recommended that this object is stored in the instance's args attribute.

    This second parameter should default to an empty iterator, indicating that the API function call takes no arguments.

  • If the recommended storage strategy outlined in the above item has been followed, it is not necessary for subclasses of SingleState to define an __eq__ or __ne__ method. SingleState provides a default implementation of __eq__ that follows the above strategy.

    In this default implementation, the objects' api_func attributes will be compared with is and their args attributes with ==.

  • Subclasses of SingleState need not define a __len__ method; SingleState defines a __len__ implementation that always returns 1, which should be suitable for most, if not all, subclasses.

  • Subclasses of SingleState need not define a reset method. SingleState provides a default implementation that simply passes, which should be sufficient for most, if not all, subclasses.

Note that if the protocol outlined above does not meet your needs, you should probably consider subclassing State directly.

svnmock