From a900d7d9a3a11dea604774a0fbfb67f1306eeff3 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 13 Feb 2021 12:23:12 +0100 Subject: [PATCH] add model_attribute test in test_async. update changelog --- Changelog.md | 5 ++++- tests/test_async.py | 16 ++++++++++++++++ tests/test_core.py | 2 +- transitions/extensions/asyncio.py | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 383cc4af..6e4fee94 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,12 @@ # Changelog -## 0.8.7 () +## 0.8.7 (February 2020) - State configuration dictionaries passed to `HierarchicalMachine` can also use `states` as a keyword to define substates. If `children` and `states` are present, only `children` will be considered. - Feature #500: `HierarchicalMachine` with custom separator now adds `is_state` partials for nested states (e.g. `is_C.s3.a()`) to models (thanks @alterscape) +- Bugfix #512: Use `model_attribute` consistently in `AsyncMachine` (thanks @thedrow) +- Testing now treats most warnings as errors (thanks @thedrow) +- As a consequence, `pygraphviz.Agraph` in `diagrams_pygraphviz` are now copied by `transitions` since `AGraph.copy` as of version `1.6` does not close temporary files appropriately ## 0.8.6 (December 2020) diff --git a/tests/test_async.py b/tests/test_async.py index 3e705546..31699564 100644 --- a/tests/test_async.py +++ b/tests/test_async.py @@ -62,6 +62,22 @@ async def on_enter_B(): machine.on_enter_B(on_enter_B) asyncio.run(machine.to_B()) + def test_dynamic_model_state_attribute(self): + class Model: + def __init__(self): + self.status = None + self.state = 'some_value' + + m = self.machine_cls(Model(), states=['A', 'B'], initial='A', model_attribute='status') + self.assertEqual(m.model.status, 'A') + self.assertEqual(m.model.state, 'some_value') + + m.add_transition('move', 'A', 'B') + asyncio.run(m.model.move()) + + self.assertEqual(m.model.status, 'B') + self.assertEqual(m.model.state, 'some_value') + def test_async_machine_cb(self): mock = MagicMock() diff --git a/tests/test_core.py b/tests/test_core.py index 51206370..d65b1d2c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1113,7 +1113,7 @@ def __init__(self): self.status = None self.state = 'some_value' - m = Machine(Model(), states=['A', 'B'], initial='A', model_attribute='status') + m = self.machine_cls(Model(), states=['A', 'B'], initial='A', model_attribute='status') self.assertEqual(m.model.status, 'A') self.assertEqual(m.model.state, 'some_value') diff --git a/transitions/extensions/asyncio.py b/transitions/extensions/asyncio.py index d4bd6399..2b00272c 100644 --- a/transitions/extensions/asyncio.py +++ b/transitions/extensions/asyncio.py @@ -480,7 +480,8 @@ async def trigger_event(self, _model, _trigger, *args, **kwargs): async def _trigger_event(self, _model, _trigger, _state_tree, *args, **kwargs): if _state_tree is None: - _state_tree = self._build_state_tree(listify(getattr(_model, self.model_attribute)), self.state_cls.separator) + _state_tree = self._build_state_tree(listify(getattr(_model, self.model_attribute)), + self.state_cls.separator) res = {} for key, value in _state_tree.items(): if value: