examples.22_unknown_strategy_handler

Demonstrates how the framework handles a pipeline strategy that does not implement either the transformation or validation interface.

This example shows:
  • A subclass of PipeLineStrategy that provides no transformation or validation behavior.
  • The resulting ConstrainedValue fails with Status.EXCEPTION.
  • The failure details explain that the strategy type is unsupported.
Run directly:

python examples/22_unknown_strategy_handler.py

Expected output:

status: EXCEPTION details: Missing strategy handler

 1"""Demonstrates how the framework handles a pipeline strategy that does not
 2implement either the transformation or validation interface.
 3
 4This example shows:
 5  * A subclass of :class:`PipeLineStrategy` that provides no transformation
 6    or validation behavior.
 7  * The resulting :class:`ConstrainedValue` fails with `Status.EXCEPTION`.
 8  * The failure details explain that the strategy type is unsupported.
 9
10Run directly:
11
12    python examples/22_unknown_strategy_handler.py
13
14Expected output:
15
16    status: EXCEPTION
17    details: Missing strategy handler
18"""
19
20import sys
21import pathlib
22
23# ---------------------------------------------------------------------------
24# Make repo root importable when running this file directly
25# ---------------------------------------------------------------------------
26sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
27
28from constrained_values.value import PipeLineStrategy, ConstrainedValue
29
30
31class Unknown(PipeLineStrategy):
32    """A pipeline strategy that implements neither transform nor validation.
33
34    Used to test how :class:`ConstrainedValue` responds when it encounters an
35    unrecognized strategy type. This should trigger an internal exception
36    path, resulting in `Status.EXCEPTION`.
37    """
38    pass
39
40
41class UsesUnknown(ConstrainedValue[int]):
42    """A `ConstrainedValue` subclass that includes an invalid strategy."""
43
44    def get_strategies(self):
45        """Return a pipeline containing one unknown, invalid strategy."""
46        return [Unknown()]
47
48
49def main() -> None:
50    """Run the unknown-strategy demonstration.
51
52    Creates an instance of :class:`UsesUnknown` containing an unsupported
53    pipeline strategy. The value initialization fails internally and sets:
54
55      * `status = Status.EXCEPTION`
56      * `details` to a description of the invalid strategy type.
57
58    Prints:
59        * `"status: EXCEPTION"`
60        * `"details: Missing strategy handler"`
61    """
62    x = UsesUnknown(5)
63    print("status:", x.status.name)
64    print("details:", x.details)
65
66
67if __name__ == "__main__":
68    main()
class Unknown(constrained_values.value.PipeLineStrategy):
32class Unknown(PipeLineStrategy):
33    """A pipeline strategy that implements neither transform nor validation.
34
35    Used to test how :class:`ConstrainedValue` responds when it encounters an
36    unrecognized strategy type. This should trigger an internal exception
37    path, resulting in `Status.EXCEPTION`.
38    """
39    pass

A pipeline strategy that implements neither transform nor validation.

Used to test how ConstrainedValue responds when it encounters an unrecognized strategy type. This should trigger an internal exception path, resulting in Status.EXCEPTION.

class UsesUnknown(constrained_values.value.ConstrainedValue[int]):
42class UsesUnknown(ConstrainedValue[int]):
43    """A `ConstrainedValue` subclass that includes an invalid strategy."""
44
45    def get_strategies(self):
46        """Return a pipeline containing one unknown, invalid strategy."""
47        return [Unknown()]

A ConstrainedValue subclass that includes an invalid strategy.

def get_strategies(self):
45    def get_strategies(self):
46        """Return a pipeline containing one unknown, invalid strategy."""
47        return [Unknown()]

Return a pipeline containing one unknown, invalid strategy.

Inherited Members
constrained_values.value.ConstrainedValue
ConstrainedValue
status
details
value
unwrap
ok
def main() -> None:
50def main() -> None:
51    """Run the unknown-strategy demonstration.
52
53    Creates an instance of :class:`UsesUnknown` containing an unsupported
54    pipeline strategy. The value initialization fails internally and sets:
55
56      * `status = Status.EXCEPTION`
57      * `details` to a description of the invalid strategy type.
58
59    Prints:
60        * `"status: EXCEPTION"`
61        * `"details: Missing strategy handler"`
62    """
63    x = UsesUnknown(5)
64    print("status:", x.status.name)
65    print("details:", x.details)

Run the unknown-strategy demonstration.

Creates an instance of UsesUnknown containing an unsupported pipeline strategy. The value initialization fails internally and sets:

  • status = Status.EXCEPTION
  • details to a description of the invalid strategy type.
Prints:
  • "status: EXCEPTION"
  • "details: Missing strategy handler"