swaggerconformance.strategies package

Module contents

This package provides access to two main classes of objects:

  • StrategyFactory for generating PrimitiveStrategy instances matching the parameter values defines by a parameter entry in a swagger schema. This can be inherited from to generate new PrimitiveStrategy instances matching custom parameters in a user’s schema.
  • The PrimitiveStrategy itself and child classes used to generate hypothesis strategies for generating parameter values with certain constraints. Again, users may create new PrimitiveStrategy subclasses to define their own new value types.
class swaggerconformance.strategies.StrategyFactory[source]

Bases: object

Factory for building PrimitiveStrategy from swagger definitions.

produce(swagger_definition)[source]

Create a template for the value specified by the definition.

Parameters:swagger_definition (schema.Primitive) – The schema of the parameter to create.
Return type:PrimitiveStrategy
register(type_str, format_str, creator)[source]

Register a function to generate PrimitiveStrategy instances for this type and format pair.

The function signature of the creator parameter must be:

def fn( schema.Primitive , StrategyFactory ) -> PrimitiveStrategy

Parameters:
  • type_str (str) – The Swagger schema type to register for.
  • format_str (str) – The Swagger schema format to register for.
  • creator (callable) – The function to create a PrimitiveStrategy.
register_type_default(type_str, creator)[source]

Register a function to generate PrimitiveStrategy instances for this type paired with any format with no other registered creator.

The function signature of the creator parameter must be:

def fn( schema.Primitive , StrategyFactory ) -> PrimitiveStrategy

Parameters:
  • type_str (str) – The Swagger schema type to register for.
  • creator (callable) – The function to create a PrimitiveStrategy.
swaggerconformance.strategies.string_primitive_strategy(swagger_definition, factory)[source]

Function for creating an appropriately formatted string value depending on the location of the string parameter.

Parameters:swagger_definition (schema.Primitive) – The schema of the parameter to create.
Return type:PrimitiveStrategy