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)
Contents:
- Type Definition Basics
- Predefined Data Types in
parse
- Cardinality: Zero or One (Optional)
- Cardinality: One or More (List of Type)
- Cardinality: Zero or More (List of Type)
- Choice (Word/String Alternatives)
- Choice2 (Word/String Alternatives)
- Enumeration (String-to-Value Mapping)
- More Complex Data Types
Important
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).