Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_listify(self):
self.assertEqual(listify(4), [4])
self.assertEqual(listify(None), [])
self.assertEqual(listify((4, 5)), (4, 5))
self.assertEqual(listify([1, 3]), [1, 3])
def test_listify(self):
self.assertEqual(listify(4), [4])
self.assertEqual(listify(None), [])
self.assertEqual(listify((4, 5)), (4, 5))
self.assertEqual(listify([1, 3]), [1, 3])
def test_listify(self):
self.assertEqual(listify(4), [4])
self.assertEqual(listify(None), [])
self.assertEqual(listify((4, 5)), (4, 5))
self.assertEqual(listify([1, 3]), [1, 3])
def add_model(self, model, initial=None):
""" Extends transitions.core.Machine.add_model by applying a custom 'to' function to
the added model.
"""
_super(HierarchicalMachine, self).add_model(model, initial=initial)
models = listify(model)
for mod in models:
mod = self if mod == 'self' else mod
# TODO: Remove 'mod != self' in 0.7.0
if hasattr(mod, 'to') and mod != self:
_LOGGER.warning("%sModel already has a 'to'-method. It will NOT "
"be overwritten by NestedMachine", self.name)
else:
to_func = partial(self.to_state, mod)
setattr(mod, 'to', to_func)
def add_model(self, model, initial=None, model_context=None):
""" Extends `transitions.core.Machine.add_model` by `model_context` keyword.
Args:
model (list or object): A model (list) to be managed by the machine.
initial (string or State): The initial state of the passed model[s].
model_context (list or object): If passed, assign the context (list) to the machines
model specific context map.
"""
models = listify(model)
model_context = listify(model_context) if model_context is not None else []
output = _super(LockedMachine, self).add_model(models, initial)
for mod in models:
mod = self if mod == 'self' else mod
self.model_context_map[mod].extend(self.machine_context)
self.model_context_map[mod].extend(model_context)
return output
def add_model(self, model, initial=None, model_context=None):
""" Extends `transitions.core.Machine.add_model` by `model_context` keyword.
Args:
model (list or object): A model (list) to be managed by the machine.
initial (str, Enum or State): The initial state of the passed model[s].
model_context (list or object): If passed, assign the context (list) to the machines
model specific context map.
"""
models = listify(model)
model_context = listify(model_context) if model_context is not None else []
output = _super(LockedMachine, self).add_model(models, initial)
for mod in models:
mod = self if mod == 'self' else mod
self.model_context_map[mod].extend(self.machine_context)
self.model_context_map[mod].extend(model_context)
return output
def remove_model(self, model):
""" Extends `transitions.core.Machine.remove_model` by removing model specific context maps
from the machine when the model itself is removed. """
models = listify(model)
for mod in models:
del self.model_context_map[mod]
return _super(LockedMachine, self).remove_model(models)
def add_model(self, model, initial=None, model_context=None):
""" Extends `transitions.core.Machine.add_model` by `model_context` keyword.
Args:
model (list or object): A model (list) to be managed by the machine.
initial (str, Enum or State): The initial state of the passed model[s].
model_context (list or object): If passed, assign the context (list) to the machines
model specific context map.
"""
models = listify(model)
model_context = listify(model_context) if model_context is not None else []
output = _super(LockedMachine, self).add_model(models, initial)
for mod in models:
mod = self if mod == 'self' else mod
self.model_context_map[mod].extend(self.machine_context)
self.model_context_map[mod].extend(model_context)
return output
def remove_model(self, model):
""" Extends `transitions.core.Machine.remove_model` by removing model specific context maps
from the machine when the model itself is removed. """
models = listify(model)
for mod in models:
del self.model_context_map[mod]
return _super(LockedMachine, self).remove_model(models)
entered. Only valid if first argument is string.
on_exit (str or list): callbacks to trigger when the state is
exited. Only valid if first argument is string.
ignore_invalid_triggers: when True, any calls to trigger methods
that are not valid for the present state (e.g., calling an
a_to_b() trigger when the current state is c) will be silently
ignored rather than raising an invalid transition exception.
Note that this argument takes precedence over the same
argument defined at the Machine level, and is in turn
overridden by any ignore_invalid_triggers explicitly
passed in an individual state's initialization arguments.
parent (NestedState or str): parent state for nested states.
remap (dict): reassigns transitions named `key from nested machines to parent state `value`.
Returns: list of new `NestedState` objects
"""
states = listify(states)
new_states = []
ignore = ignore_invalid_triggers
remap = {} if remap is None else remap
parent = self.get_state(parent) if isinstance(parent, (string_types, Enum)) else parent
if ignore is None:
ignore = self.ignore_invalid_triggers
for state in states:
tmp_states = []
# other state representations are handled almost like in the base class but a parent parameter is added
if isinstance(state, (string_types, Enum)):
if state in remap:
continue
tmp_states.append(self._create_state(state, on_enter=on_enter, on_exit=on_exit, parent=parent,
ignore_invalid_triggers=ignore))
elif isinstance(state, dict):