Skip to content

Commit

Permalink
Trailing whitespaces & unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDecan committed Aug 27, 2018
1 parent 75f6adb commit 8181177
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 89 deletions.
6 changes: 3 additions & 3 deletions sismic/bdd/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def state_is_not_entered(context, name):

test = not testing.state_is_entered(context.monitored_trace, name)
assert test, 'State {} is entered'.format(name)


@then('state {name} is exited')
def state_is_exited(context, name):
Expand All @@ -95,7 +95,7 @@ def state_is_not_exited(context, name):

test = not testing.state_is_exited(context.monitored_trace, name)
assert test, 'State {} is exited'.format(name)


@then('state {name} is active')
def state_is_active(context, name):
Expand Down Expand Up @@ -125,7 +125,7 @@ def event_is_fired(context, name, parameter=None, value=None):
parameters[parameter.strip()] = eval(value.strip(), {}, {})

test = testing.event_is_fired(context.monitored_trace, name, parameters)

if len(parameters) == 0:
assert test, 'Event {} is not fired'.format(name)
else:
Expand Down
26 changes: 13 additions & 13 deletions sismic/clock/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Clock(metaclass=abc.ABCMeta):
Abstract implementation of a clock, as used by an interpreter.
The purpose of a clock instance is to provide a way for the interpreter
to get the current time during the execution of a statechart.
to get the current time during the execution of a statechart.
"""
@abc.abstractproperty
def time(self) -> float:
Expand All @@ -27,12 +27,12 @@ def __repr__(self):
class SimulatedClock(Clock):
"""
A simulated clock, starting from 0, that can be manually or automatically
incremented.
incremented.
Manual incrementation can be done by setting a new value to the time attribute.
Automatic incrementation occurs when start() is called, until stop() is called.
In that case, clock speed can be adjusted with the speed attribute.
A value strictly greater than 1 increases clock speed while a value strictly
In that case, clock speed can be adjusted with the speed attribute.
A value strictly greater than 1 increases clock speed while a value strictly
lower than 1 slows down the clock.
"""
def __init__(self) -> None:
Expand All @@ -44,10 +44,10 @@ def __init__(self) -> None:
@property
def _elapsed(self):
return (time() - self._base) * self._speed if self._play else 0

def start(self) -> None:
"""
Clock will be automatically updated both based on real time and
Clock will be automatically updated both based on real time and
its speed attribute.
"""
if not self._play:
Expand All @@ -56,7 +56,7 @@ def start(self) -> None:

def stop(self) -> None:
"""
Clock won't be automatically updated.
Clock won't be automatically updated.
"""
if self._play:
self._time += self._elapsed
Expand All @@ -81,7 +81,7 @@ def time(self) -> float:
Time value of this clock.
"""
return self._time + self._elapsed

@time.setter
def time(self, new_time):
"""
Expand All @@ -92,7 +92,7 @@ def time(self, new_time):
current_time = self.time
if new_time < current_time:
raise ValueError('Time must be monotonic, cannot change time from {} to {}'.format(current_time, new_time))

self._time = new_time
self._base = time()

Expand All @@ -107,14 +107,14 @@ def __repr__(self):
'>' if self._play else '=',
)


class UtcClock(Clock):
"""
A clock that simulates a wall clock in UTC.
A clock that simulates a wall clock in UTC.
The returned time value is based on Python time.time() function.
"""

@property
def time(self) -> float:
return time()
Expand All @@ -124,7 +124,7 @@ class SynchronizedClock(Clock):
"""
A clock that is synchronized with a given interpreter.
The synchronization is based on the interpreter's internal time value, not
The synchronization is based on the interpreter's internal time value, not
on its clock. As a consequence, the time value of a SynchronizedClock only
changes when the underlying interpreter is executed.
Expand Down
14 changes: 7 additions & 7 deletions sismic/code/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _create_send_function(event_list: List[Event]) -> Callable[..., None]:
def send(name, **kwargs):
event_list.append(InternalEvent(name, **kwargs))
return send

def _create_notify_function(event_list: List[Event]) -> Callable[..., None]:
def notify(name, **kwargs):
event_list.append(MetaEvent(name, **kwargs))
Expand All @@ -67,13 +67,13 @@ class PythonEvaluator(Evaluator):
that makes use of this evaluator.
- On code execution:
- A *send(name: str, **kwargs) -> None* function that takes an event name and additional keyword parameters and
raises an internal event with it. Raised events are propagated to bound statecharts as external events and
raises an internal event with it. Raised events are propagated to bound statecharts as external events and
to the current statechart as internal event. If delay is provided, a delayed event is created.
- A *notify(name: str, **kwargs) -> None* function that takes an event name and additional keyword parameters and
raises a meta-event with it. Meta-events are only sent to bound property statecharts.
- If the code is related to a transition, the *event: Event* that fires the transition is exposed.
- A *setdefault(name:str, value: Any) -> Any* function that defines and returns variable *name* in
the global scope if it is not yet defined.
- A *setdefault(name:str, value: Any) -> Any* function that defines and returns variable *name* in
the global scope if it is not yet defined.
- On guard or contract evaluation:
- If the code is related to a transition, the *event: Event* that fires the transition is exposed.
- On guard or contract (except preconditions) evaluation:
Expand Down Expand Up @@ -136,7 +136,7 @@ def on_step_starts(self, event: Optional[Event]=None) -> None:

def _setdefault(self, name: str, value: Any) -> Any:
"""
Define and return variable "name".
Define and return variable "name".
:param name: name of the variable
:param value: value to use for that variable, if not defined
Expand Down Expand Up @@ -283,7 +283,7 @@ def execute_action(self, transition: Transition, event: Optional[Event]=None) ->
:return: a list of sent events
"""
execution = self._execute_code(getattr(transition, 'action', None), additional_context={'event': event})

self._idle_time[transition.source] = self._interpreter.time

return execution
Expand All @@ -302,7 +302,7 @@ def execute_on_entry(self, state: StateMixin) -> List[Event]:
self._idle_time[state.name] = self._interpreter.time

return execution


def execute_on_exit(self, state: StateMixin) -> List[Event]:
"""
Expand Down
2 changes: 1 addition & 1 deletion sismic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections import Counter
from functools import wraps
from typing import Any, Callable, List, Mapping, Optional
from typing import Any, Callable, List, Mapping

from .interpreter import Interpreter
from .model import MacroStep
Expand Down
37 changes: 18 additions & 19 deletions sismic/interpreter/default.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import abc
import bisect
import warnings

Expand Down Expand Up @@ -140,7 +139,7 @@ def bind(self, interpreter_or_callable: Union['Interpreter', Callable[[Event], A

def unbind(self, interpreter_or_callable: Union['Interpreter', Callable[[Event], Any]]) -> None:
"""
Unbind a previously bound interpreter or callable.
Unbind a previously bound interpreter or callable.
:param interpreter_or_callable: interpreter or callable to unbind
"""
Expand Down Expand Up @@ -175,7 +174,7 @@ def bind_property_statechart(self, statechart: Statechart, *, interpreter_klass:
Since Sismic 1.4.0, passing an interpreter as first argument is deprecated.
:param statechart: A statechart instance.
:param interpreter_klass: An optional callable that accepts a statechart as first parameter and a
:param interpreter_klass: An optional callable that accepts a statechart as first parameter and a
named parameter clock. Default to Interpreter.
"""
if isinstance(statechart, Interpreter):
Expand All @@ -185,19 +184,19 @@ def bind_property_statechart(self, statechart: Statechart, *, interpreter_klass:
else:
interpreter_klass = Interpreter if interpreter_klass is None else interpreter_klass
interpreter = interpreter_klass(statechart, clock=SynchronizedClock(self))

self._bound_properties.append(interpreter)

def queue(self, event_or_name:Union[str, Event], *event_or_names:Union[str, Event], **parameters) -> 'Interpreter':
"""
Create and queue given events to the external event queue.
If an event has a `delay` parameter, it will be processed by the first call to `execute_once`
Create and queue given events to the external event queue.
If an event has a `delay` parameter, it will be processed by the first call to `execute_once`
as soon as `self.clock.time` exceeds current `self.time + event.delay`.
If named parameters are provided, they will be added to all events
that are provided by name.
If named parameters are provided, they will be added to all events
that are provided by name.
:param event_or_name: name of the event or Event instance
:param event_or_names: additional events
:param parameters: event parameters.
Expand Down Expand Up @@ -305,14 +304,14 @@ def _raise_event(self, event: Union[InternalEvent, MetaEvent]) -> None:
"""
Raise an event from the statechart.
Only InternalEvent and MetaEvent (and their subclasses) are accepted.
Only InternalEvent and MetaEvent (and their subclasses) are accepted.
InternalEvent instances are propagated to bound interpreters as normal events, and added to
the event queue of the current interpreter as InternalEvent instance. If given event is
InternalEvent instances are propagated to bound interpreters as normal events, and added to
the event queue of the current interpreter as InternalEvent instance. If given event is
delayed, it is propagated as DelayedEvent to bound interpreters, and put into current
event queue as a DelayedInternalEvent.
event queue as a DelayedInternalEvent.
MetaEvent instances are only propagated to bound property statecharts.
MetaEvent instances are only propagated to bound property statecharts.
:param event: event to be sent by the statechart.
"""
Expand Down Expand Up @@ -363,13 +362,13 @@ def _check_properties(self, macro_step: Optional[MacroStep]):

def _select_event(self, *, consume: bool=False) -> Optional[Event]:
"""
Return the next event to process.
Internal events have priority over external ones.
Return the next event to process.
Internal events have priority over external ones.
:param consume: Indicates whether event should be consumed, default to False.
:return: An instance of Event or None if no event is available
"""
for queue in (self._internal_queue, self._external_queue): # type: List[Tuple[float, Event]]
for queue in cast(Tuple[List[Tuple[float, Event]]], (self._internal_queue, self._external_queue)):
if len(queue) > 0:
time, event = queue[0]
if time <= self.time:
Expand Down
2 changes: 1 addition & 1 deletion sismic/io/datadict.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _import_transition_from_dict(state_name: str, transition_d: Mapping[str, Any
guard = transition_d.get('guard', None)
action = transition_d.get('action', None)
priority = transition_d.get('priority', None)

if priority == 'low':
priority = Transition.LOW_PRIORITY
elif priority == 'high':
Expand Down
6 changes: 3 additions & 3 deletions sismic/model/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Event:
An event with a name and (optionally) some data passed as named parameters.
The list of parameters can be obtained using *dir(event)*. Notice that
*name* and *data* are reserved names. If a *delay* parameter is provided,
then this event will be considered as a delayed event (and won't be
*name* and *data* are reserved names. If a *delay* parameter is provided,
then this event will be considered as a delayed event (and won't be
executed until delay has elapsed).
When two events are compared, they are considered equal if their names
Expand Down Expand Up @@ -67,7 +67,7 @@ class InternalEvent(Event):

class DelayedEvent(Event):
"""
An event that is delayed.
An event that is delayed.
Deprecated since 1.4.0, use `Event` with a `delay` parameter instead.
"""
Expand Down

0 comments on commit 8181177

Please sign in to comment.