|
| 1 | +#!/usr/bin/env python |
| 2 | +# |
| 3 | +# License: BSD |
| 4 | +# https://raw.githubusercontent.com/splintered-reality/py_trees/devel/LICENSE |
| 5 | +# |
| 6 | + |
| 7 | +############################################################################## |
| 8 | +# Imports |
| 9 | +############################################################################## |
| 10 | + |
| 11 | +import py_trees |
| 12 | +import py_trees.console as console |
| 13 | +import py_trees.tests |
| 14 | +import pytest |
| 15 | + |
| 16 | +############################################################################## |
| 17 | +# Logging Level |
| 18 | +############################################################################## |
| 19 | + |
| 20 | +py_trees.logging.level = py_trees.logging.Level.DEBUG |
| 21 | +logger = py_trees.logging.Logger("Tests") |
| 22 | + |
| 23 | +############################################################################## |
| 24 | +# Tests |
| 25 | +############################################################################## |
| 26 | + |
| 27 | + |
| 28 | +def test_probabilistic_behaviour_workflow() -> None: |
| 29 | + console.banner("Probabilistic Behaviour") |
| 30 | + |
| 31 | + with pytest.raises(ValueError) as context: # if raised, context survives |
| 32 | + # intentional error -> silence mypy |
| 33 | + unused_root = py_trees.behaviours.ProbabilisticBehaviour( # noqa: F841 [unused] |
| 34 | + name="ProbabilisticBehaviour", weights="invalid_type" # type: ignore[arg-type] |
| 35 | + ) |
| 36 | + py_trees.tests.print_assert_details("ValueError raised", "raised", "not raised") |
| 37 | + py_trees.tests.print_assert_details("ValueError raised", "yes", "yes") |
| 38 | + assert "ValueError" == context.typename |
| 39 | + |
| 40 | + root = py_trees.behaviours.ProbabilisticBehaviour( |
| 41 | + name="ProbabilisticBehaviour", weights=[0.0, 0.0, 1.0] |
| 42 | + ) |
| 43 | + |
| 44 | + py_trees.tests.print_assert_details( |
| 45 | + text="task not yet ticked", |
| 46 | + expected=py_trees.common.Status.INVALID, |
| 47 | + result=root.status, |
| 48 | + ) |
| 49 | + assert root.status == py_trees.common.Status.INVALID |
| 50 | + |
| 51 | + root.tick_once() |
| 52 | + py_trees.tests.print_assert_details( |
| 53 | + text="task ticked once", |
| 54 | + expected=py_trees.common.Status.RUNNING, |
| 55 | + result=root.status, |
| 56 | + ) |
| 57 | + assert root.status == py_trees.common.Status.RUNNING |
0 commit comments