hydra.testing module

A model for unit testing.

class hydra.testing.EffectfulTestCase(actual: Annotated[Callable[[None], str], 'A thunk producing the effect to be interpreted by the test runner. The thunk defers construction of the effect until the runner forces it.'], expected: Annotated[Callable[[None], str], 'A thunk producing the expected result string.'])

Bases: object

An effectful test case: the actual value is a thunk producing an effect, which the test runner interprets (performing host interactions, e.g. file I/O within a per-case empty temporary directory) to obtain a result string; the expected value is a thunk producing a string.

ACTUAL = Name(value='actual')
class Builder(_actual: 'Callable[[None], str]' = None, _expected: 'Callable[[None], str]' = None)

Bases: object

actual(actual)
build()
expected(expected)
EXPECTED = Name(value='expected')
TYPE_ = Name(value='hydra.testing.EffectfulTestCase')
actual: Annotated[Callable[[None], str], 'A thunk producing the effect to be interpreted by the test runner. The thunk defers construction of the effect until the runner forces it.']
static builder()
expected: Annotated[Callable[[None], str], 'A thunk producing the expected result string.']
with_actual(actual)
with_expected(expected)
class hydra.testing.Tag(value: T)

Bases: Node[str]

A tag for test cases.

TYPE_ = Name(value='hydra.testing.Tag')
class hydra.testing.TestCase

Bases: object

TestCaseEffectful | TestCaseUniversal

EFFECTFUL = Name(value='effectful')
TYPE_ = Name(value='hydra.testing.TestCase')
UNIVERSAL = Name(value='universal')
class hydra.testing.TestCaseEffectful(value: T)

Bases: Node[EffectfulTestCase]

An effectful test case (interpret an effect, then string comparison)

class hydra.testing.TestCaseUniversal(value: T)

Bases: Node[UniversalTestCase]

A universal test case (string comparison)

class hydra.testing.TestCaseWithMetadata(name: Annotated[str, 'A short name for the test case'], case: Annotated[TestCase, 'The test case itself'], description: Annotated[object, 'An optional longer description of the test case'], tags: Annotated[Sequence[Tag], 'Zero or more tags for the test case'])

Bases: object

A test case together with metadata.

class Builder(_name: 'str' = None, _case: 'TestCase' = None, _description: 'Optional[str]' = None, _tags: 'Sequence[Tag]' = None)

Bases: object

build()
case(case)
description(description)
name(name)
tags(tags)
CASE = Name(value='case')
DESCRIPTION = Name(value='description')
NAME = Name(value='name')
TAGS = Name(value='tags')
TYPE_ = Name(value='hydra.testing.TestCaseWithMetadata')
static builder()
case: Annotated[TestCase, 'The test case itself']
description: Annotated[object, 'An optional longer description of the test case']
name: Annotated[str, 'A short name for the test case']
tags: Annotated[Sequence[Tag], 'Zero or more tags for the test case']
with_case(case)
with_description(description)
with_name(name)
with_tags(tags)
class hydra.testing.TestGroup(name: Annotated[str, 'A short name for the test group'], description: Annotated[object, 'An optional longer description of the test group'], subgroups: Annotated[Sequence[TestGroup], 'Zero or more subgroups'], cases: Annotated[Sequence[TestCaseWithMetadata], 'Zero or more test cases'])

Bases: object

A collection of test cases with a name and optional description.

class Builder(_name: 'str' = None, _description: 'Optional[str]' = None, _subgroups: 'Sequence[TestGroup]' = None, _cases: 'Sequence[TestCaseWithMetadata]' = None)

Bases: object

build()
cases(cases)
description(description)
name(name)
subgroups(subgroups)
CASES = Name(value='cases')
DESCRIPTION = Name(value='description')
NAME = Name(value='name')
SUBGROUPS = Name(value='subgroups')
TYPE_ = Name(value='hydra.testing.TestGroup')
static builder()
cases: Annotated[Sequence[TestCaseWithMetadata], 'Zero or more test cases']
description: Annotated[object, 'An optional longer description of the test group']
name: Annotated[str, 'A short name for the test group']
subgroups: Annotated[Sequence[TestGroup], 'Zero or more subgroups']
with_cases(cases)
with_description(description)
with_name(name)
with_subgroups(subgroups)
class hydra.testing.UniversalTestCase(actual: Annotated[Callable[[None], str], 'A thunk producing the actual result string. Wrapping in a thunk defers expression evaluation until the test runner forces it, so eagerly-evaluated hosts measure expression cost inside their timing bracket rather than at test-data load time.'], expected: Annotated[Callable[[None], str], 'A thunk producing the expected result string.'])

Bases: object

A universal test case: the actual and expected values are thunks producing strings.

ACTUAL = Name(value='actual')
class Builder(_actual: 'Callable[[None], str]' = None, _expected: 'Callable[[None], str]' = None)

Bases: object

actual(actual)
build()
expected(expected)
EXPECTED = Name(value='expected')
TYPE_ = Name(value='hydra.testing.UniversalTestCase')
actual: Annotated[Callable[[None], str], 'A thunk producing the actual result string. Wrapping in a thunk defers expression evaluation until the test runner forces it, so eagerly-evaluated hosts measure expression cost inside their timing bracket rather than at test-data load time.']
static builder()
expected: Annotated[Callable[[None], str], 'A thunk producing the expected result string.']
with_actual(actual)
with_expected(expected)