Skip to content

Commit

Permalink
adapt changelog; rename _should_skip_auto_transition to
Browse files Browse the repository at this point in the history
_omit_auto_transitions; integrate _omit_auto_transitions test into
test_to_method_filtering
  • Loading branch information
aleneum committed May 12, 2017
1 parent 8df9b11 commit a71107b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## 0.5.3 ()

- Bug #214: `LockedMachine` as a model prevented correct addition of `on_enter/exit_<state>`
- Bug #214: `LockedMachine` as a model prevented correct addition of `on_enter/exit_<state>` (thanks to @kr2)
- Bug #217: Filtering rules for auto transitions in graphs falsely filtered certain transitions (thanks to @KarolOlko)

## 0.5.2 (April, 2017)

Expand Down
12 changes: 4 additions & 8 deletions tests/test_graphing.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ def get_graph(self):
self.assertEqual(model.get_graph(), "This method already exists")

def test_to_method_filtering(self):
m = self.machine_cls(states=['A', 'B'], initial='A')
m = self.machine_cls(states=['A', 'B', 'C'], initial='A')
m.add_transition('to_state_A', 'B', 'A')
m.add_transition('to_end', '*', 'C')
e = m.get_graph().get_edge('B', 'A')
self.assertEqual(e.attr['label'], 'to_state_A')
e = m.get_graph().get_edge('A', 'C')
self.assertEqual(e.attr['label'], 'to_end')
with self.assertRaises(KeyError):
m.get_graph().get_edge('A', 'B')
m2 = self.machine_cls(states=['A', 'B'], initial='A', show_auto_transitions=True)
Expand All @@ -150,13 +153,6 @@ def test_roi(self):
self.assertEqual(len(g2.edges()), 4)
self.assertEqual(len(g2.nodes()), 4)

def test_trigger_prefixed_with_to_XXX_not_ignored_if_XXX_not_in_states(self):
m = self.machine_cls(states=['A', 'B', 'C', 'D'], initial='A', show_auto_transitions=False)
m.add_transition('to_end', '*', 'D')

g = m.get_graph()
self.assertEquals(4, len(g.edges()))


@skipIf(pgv is None, 'Graph diagram requires pygraphviz')
class TestDiagramsLocked(TestDiagrams):
Expand Down
8 changes: 5 additions & 3 deletions transitions/extensions/diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _add_nodes(self, states, container):
def _add_edges(self, events, container):
for event in events.values():
label = str(event.name)
if self._should_skip_auto_transition(event, label):
if self._omit_auto_transitions(event, label):
continue

for transitions in event.transitions.items():
Expand All @@ -104,9 +104,11 @@ def _add_edges(self, events, container):
else:
container.add_edge(src, dst, **edge_attr)

def _should_skip_auto_transition(self, event, label):
def _omit_auto_transitions(self, event, label):
return self._is_auto_transition(event, label) and not self.machine.show_auto_transitions

# auto transition events commonly a) start with the 'to_' prefix, followed by b) the state name
# and c) contain a transition from each state to the target state (including the target)
def _is_auto_transition(self, event, label):
if label.startswith('to_') and len(event.transitions) == len(self.machine.states):
state_name = label[len('to_'):]
Expand Down Expand Up @@ -189,7 +191,7 @@ def _add_edges(self, events, container):

for event in events.values():
label = str(event.name)
if self._should_skip_auto_transition(event, label):
if self._omit_auto_transitions(event, label):
continue

for transitions in event.transitions.items():
Expand Down

0 comments on commit a71107b

Please sign in to comment.