-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
History in context #26
Changes from 1 commit
ba5078d
27f7bd1
65e4170
0ce4ae3
6202cf7
d83e853
a702980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"""Context definition for exit condition programs.""" | ||
import datetime | ||
from typing import Any, Dict, Iterable, Sequence | ||
from typing import Any, Dict, Iterable, Optional, Sequence | ||
|
||
import dateutil.tz | ||
|
||
|
@@ -19,6 +19,7 @@ def __init__( | |
now: datetime.datetime = None, | ||
feeds: Dict[str, Feed] = {}, | ||
accessed_variables: Iterable[str] = [], | ||
current_history_entry: Optional[Any] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really not have a type for the entry? Or is it that SqlAlchemy doesn't provide a useful type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The latter, because we aren't using the ORM. This will change eventually I hope. |
||
) -> None: | ||
"""Create an execution context.""" | ||
if now is None: | ||
|
@@ -31,6 +32,7 @@ def __init__( | |
self.now = now | ||
self.metadata = metadata | ||
self.feeds = feeds | ||
self.current_history_entry = current_history_entry | ||
|
||
self._pre_warm_feeds(label, accessed_variables) | ||
|
||
|
@@ -42,6 +44,7 @@ def lookup(self, path: Sequence[str]) -> Any: | |
return { | ||
'metadata': self._lookup_metadata, | ||
'feeds': self._lookup_feed_data, | ||
'history': self._lookup_history, | ||
}[location](rest) | ||
except (KeyError, ValueError): | ||
return None | ||
|
@@ -53,6 +56,16 @@ def _lookup_feed_data(self, path: Sequence[str]) -> Any: | |
feed_name, *rest = path | ||
return self.feeds[feed_name].lookup(rest) | ||
|
||
def _lookup_history(self, path: Sequence[str]) -> Any: | ||
if self.current_history_entry is None: | ||
raise ValueError("Accessed uninitialised variable") | ||
|
||
variable_name, = path | ||
return { | ||
'entered_state': self.current_history_entry.created, | ||
'previous_state': self.current_history_entry.old_state, | ||
}[variable_name] | ||
|
||
def property_handler(self, property_name, value, **kwargs): | ||
"""Handle a property in execution.""" | ||
if property_name == ('passed',): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that having these mutable defaults is a good idea (maybe add
flake8-mutable
?).Perhaps a better way to solve this would be a helper used in tests which handles the non-interesting defaults?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed these with a test factory method that has the defaults (but not as mutable args).