Skip to content
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

This PR addresses the issues #950 #951 #952

Merged
merged 3 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions aiida/backends/tests/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,52 @@ def test_workflow_info(self):
get_workflow_info(w)

def test_wf_get_state(self):
"""
Simple test that checks the state of the workflows. We create two
workflows since the test order in the SQLA was influencing the value
of aiida.backends.sqlalchemy.models.workflow.DbWorkflow.state which
should be a Choice object, according to the SQLA doc. Sometimes it
was automatically converted to unicode.

Since we are interested to get a unicode from
aiida.orm.implementation.general.workflow.AbstractWorkflow#get_state
we enforce this conversion at
aiida.orm.implementation.sqlalchemy.workflow.Workflow#get_state

For more info, check issue #951
"""
# Creating two simple workflows & storing them
wf1 = WFTestEmpty()
wf1.store()

wf2 = WFTestEmpty()
wf2.store()

# Checking that the get_state doesn't throw exceptions and that
# it is a valid state
self.assertIn(wf1.get_state(), wf_states)
self.assertIn(wf2.get_state(), wf_states)

def test_wf_ctime(self):
import datetime
import pytz

# Get the current datetime (before the creation of the workflow)
dt_before = datetime.datetime.now(pytz.utc)

# Creating a simple workflow & storing it
wf = WFTestEmpty()
wf.store()

# Checking that the get_state doesn't throw exceptions and that
# it is a valid state
self.assertIn(wf.get_state(), wf_states)
# Get the current datetime (after the creation of the workflow)
dt_after = datetime.datetime.now(pytz.utc)

self.assertLessEqual(dt_before, wf.ctime, "The workflow doesn't have"
"a valid creation time")

self.assertGreaterEqual(dt_after, wf.ctime, "The workflow doesn't "
"have a valid creation "
"time")

def test_failing_calc_in_wf(self):
"""
Expand Down
4 changes: 4 additions & 0 deletions aiida/orm/implementation/django/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def label(self):
def label(self, label):
self._update_db_label_field(label)

@property
def ctime(self):
return self.dbworkflowinstance.ctime

def _update_db_label_field(self, field_value):
"""
Safety method to store the label of the workflow
Expand Down
7 changes: 7 additions & 0 deletions aiida/orm/implementation/general/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ def label(self, label):
"""
pass

@abstractproperty
def ctime(self):
"""
Get the creation time of the workflow
"""
pass

@abstractmethod
def _update_db_label_field(self, field_value):
"""
Expand Down
6 changes: 5 additions & 1 deletion aiida/orm/implementation/sqlalchemy/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def label(self):
def label(self, label):
self._update_db_label_field(label)

@property
def ctime(self):
return self.dbworkflowinstance.ctime

def _update_db_label_field(self, field_value):
"""
Safety method to store the label of the workflow
Expand Down Expand Up @@ -403,7 +407,7 @@ def get_state(self):
Get the Workflow's state
:return: a state from wf_states in aiida.common.datastructures
"""
return self.dbworkflowinstance.state
return unicode(self.dbworkflowinstance.state)

def set_state(self, state):
"""
Expand Down