Skip to content

Commit

Permalink
Result status comparison (#1578)
Browse files Browse the repository at this point in the history
* improve result status comparison

* add changelog

* add tests

* add tests for not equal comparison

---------

Co-authored-by: Alejandro Esquivel <[email protected]>
  • Loading branch information
madhur-tandon and AlejandroEsquivel authored Apr 18, 2023
1 parent ef0bcaf commit 4b4d76b
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ repos:
rev: 23.1.0
hooks:
- id: black
language_version: python3.8

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED]

### Authors

- Madhur Tandon <[email protected]>

### Fixed

- Result status comparison

## [0.221.0-rc.0] - 2023-04-17

### Authors
Expand Down
10 changes: 10 additions & 0 deletions covalent/_shared_files/util_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ def __bool__(self):
def __str__(self) -> str:
return self.STATUS

def __eq__(self, __value: object) -> bool:
if isinstance(__value, self.__class__):
return self.STATUS == __value.STATUS
elif isinstance(__value, str):
return self.STATUS == __value
return False

def __ne__(self, __value: object) -> bool:
return not self.__eq__(__value)


class RESULT_STATUS:
NEW_OBJECT = Status("NEW_OBJECT")
Expand Down
2 changes: 1 addition & 1 deletion covalent/triggers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def trigger(self) -> None:

status = self._get_status()

if status == str(Result.NEW_OBJ) or status is None:
if status == Result.NEW_OBJ or status is None:
# To continue the pending dispatch
same_dispatch_id = self._do_redispatch(True)
app_log.debug(f"Initiating run for pending dispatch_id: {same_dispatch_id}")
Expand Down
2 changes: 1 addition & 1 deletion tests/covalent_dispatcher_tests/_service/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_get_result(mocker, client, test_db_file):
response = client.get(f"/api/result/{DISPATCH_ID}")
result = response.json()
assert result["id"] == DISPATCH_ID
assert result["status"] == str(Result.COMPLETED)
assert result["status"] == Result.COMPLETED
os.remove("/tmp/testdb.sqlite")


Expand Down
8 changes: 8 additions & 0 deletions tests/covalent_tests/results_manager_tests/results_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def test_str_result(result_2, mocker):
assert "task_1" in s


def test_result_status_comparison(result_2, mocker):
"""Test result.status __eq__ and __ne__ methods"""
assert result_2.status == "NEW_OBJECT"
assert result_2.status == Result.NEW_OBJ
assert result_2.status != "COMPLETED"
assert result_2.status != Result.COMPLETED


def test_result_root_dispatch_id(result_1):
"""Test the `root_dispatch_id` property`"""

Expand Down
2 changes: 1 addition & 1 deletion tests/functional_tests/basic_dispatcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def outer_lattice(y):
rm._delete_result(dispatch_id, results_dir="/tmp/results")

assert result_object.error == ""
assert result_object.status == str(result_object.COMPLETED)
assert result_object.status == result_object.COMPLETED

assert output == 25

Expand Down
4 changes: 2 additions & 2 deletions tests/functional_tests/workflow_stack_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,10 @@ def failing_workflow(x, y):
dispatch_id = ct.dispatch(failing_workflow)(1, 0)
result = ct.get_result(dispatch_id, wait=True)
assert result.result is None
assert str(result.status) == "FAILED"
assert result.status == "FAILED"

redispatch_id = ct.redispatch(dispatch_id=dispatch_id, reuse_previous_results=True)(1, 1)
result = ct.get_result(redispatch_id, wait=True)
assert int(result.result) == 1
assert str(result.status) == "COMPLETED"
assert result.status == "COMPLETED"
assert result.get_node_result(0)["start_time"] == result.get_node_result(0)["end_time"]

0 comments on commit 4b4d76b

Please sign in to comment.