Skip to main content

Advanced Types

spock also supports nested List, Tuple, and Dict types and advanced argument types (such as repeated objects) that use Enum or @spock decorated classes. All of the advanced types support the use of Optional and setting default values. Example usage of advanced types can be found in the unittests here.

Nested List, Tuple, and Dict Types#

Some examples (not the full combinatorics space, but to illustrate what is possible) are:

List[List[int]] -- Defines a list of list of integers.

List[List[Callable]] -- Defines a list of list of callable objects.

Tuple[List[str], List[str]] -- Defines a two length tuple of lists of strings.

Dict[str, List[str]] -- Defines a dictionary where keys are strings and values must be lists of strings

Lists and Tuple of Enum#

from enum import Enumfrom spock.config import spockfrom typing import List

class StrChoice(Enum):    option_1 = 'option_1'    option_2 = 'option_2'
@spockclass TypeConfig:    list_choice_p_str: List[StrChoice]

With YAML definitions:

list_choice_p_str: ['option_1', 'option_2']

Enum of @spock Classes#

from enum import Enumfrom spock.config import spock

@spockclass ClassOne:    one: int    two: str

@spockclass ClassTwo:    one: int    two: str

class ClassChoice(Enum):    class_one = ClassOne    class_two = ClassTwo
@spockclass TypeConfig:    param: ClassChoice

With YAML definitions:

# Nested List configurationTypeConfig:  param: ClassTwo
ClassOne:    one: 20    two: bye
ClassTwo:    one: 10    two: hello