Skip to content

Commit

Permalink
Merge a735311 into 02076d3
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjbremner committed Oct 21, 2019
2 parents 02076d3 + a735311 commit f3c96b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def goodbye(self):
assert s.is_ONE()
assert s.message == 'Goodbye'

def test_str_enum(self):
class States(str, enum.Enum):
ONE = "one"
TWO = "two"

class Stuff(object):
def __init__(self, machine_cls):
self.state = None
self.machine = machine_cls(states=States, initial=States.ONE, model=self)
self.machine.add_transition("advance", States.ONE, States.TWO)

s = Stuff(self.machine_cls)
assert s.is_ONE()
s.advance()
assert s.is_TWO()


@skipIf(enum is None, "enum is not available")
class TestNestedStateEnums(TestEnumsAsStates):
Expand Down
2 changes: 1 addition & 1 deletion transitions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def add_transition(self, trigger, source, dest, conditions=None,
for model in self.models:
self._add_trigger_to_model(trigger, model)

if isinstance(source, string_types):
if isinstance(source, string_types) and not isinstance(source, Enum):
source = list(self.states.keys()) if source == self.wildcard_all else [source]
else:
source = [s.name if self._has_state(s) or isinstance(s, Enum) else s for s in listify(source)]
Expand Down

0 comments on commit f3c96b4

Please sign in to comment.