Data Types and User-defined TypesΒΆ

The following sections describe in more detail how user-defined data types are used in behave. The type converter functionality, that is described here, is only supported by the:

  • “parse” matcher (based on: parse module)
  • “cfparse” matcher (based on: parse_type module)



Part of the functionality, that is described here, is based on parse_type, an extension of the excellent parse module.

The parse module is the inverse of Python string.format function. The parse_type module extends it to simplify the generation of types (actually type converter functions for types).

parse features:

  • Optional pattern attribute (for regex) in user-defined type converters.
  • The with_pattern() decorator for type-converters.

parse_type features:

  • Simplifies the creation of type converters for some common cases

  • Creates type converter variants based on cardinality

  • parse_type extensions (TypeBuilder functionality).

  • Provides an extended parser with cardinality field support. A cardinality field is a type suffix in parse expression, like:

    Cardinality Example Description
    0..1 “{person:Person?}” Zero or one: For optional parts.
    0..* “{persons:Person*}” Zero or more: For list<T> (many0).
    1..* “{persons:Person+}” One or more: For list<T> (many).