State Base Class

The State base class is the common superclass to all other State classes in svnmock. It defines the following protocol:

  • Subclasses of State must define a __call__ method. This method, which is used to validate API calls, will accept three required parameters, not including the self parameter. The first parameter will be the state's Container. The second parameter will be a function-type object representing the API function that was called. The third parameter will be a tuple of the arguments passed to the function (the second parameter) in the course of the API call.

    The subclass may choose to either forward this validation request to another State instance or handle the request itself.

    When the instance has exhausted its ability to validate further states, it must invoke the next() method of the object passed in for the second parameter to __call__.

  • Subclasses of State must define either an __eq__ method or a __ne__ method, depending on which is more efficient for that class. It is not necessary to define both; the other will be filled it automatically.

  • Subclasses of State must define a __len__ method. This method should return the number of API calls the invocant can handle before being exhausted.

    For example, instances of the Command and Error classes always return 1.

  • Subclasses of State must define a clone method. This method take only the self parameter and return a deep copy of the invocant.

  • Subclasses of State must define a reset method. This method takes only the self parameter and should perform whatever operations are necessary to "rewind" the invocant to its initial state.

    That is, a freshly-created instance should be indistinguishable from an instance whose reset method has been called.

  • Subclasses of State must define a freeze method. This method takes only the self parameter and should return an instance of FrozenState that thaws to an identical shallow copy of the original invocant.

svnmock