Skip to content

Commit

Permalink
add model_attribute test in test_async. update changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
aleneum committed Feb 13, 2021
1 parent 11a918e commit a900d7d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion transitions/extensions/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a900d7d

Please sign in to comment.