Repository: AgnostiqHQ/covalent
Pull request #1578 (2023-04-15 19:27:58)

Result status comparison
<!--
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Increment the version number in the /VERSION file. If this is a bugfix, increment the patch version (the rightmost number), for example 0.18.2 becomes 0.18.3. If it's a new feature, increment the minor version (the middle number), for example 0.18.2 becomes 0.19.0.
⚠️ Add a note to /CHANGELOG.md with your version number and the date, summarizing the changes.
⚠️ If your pull request fixes an open issue, please link to the issue.
⚠️ Rebase the latest changes from the develop branch. Assuming origin points to https://github.com/AgnostiqHQ/covalent, you should run git rebase origin/develop.
-->

- [x] I have added the tests to cover my changes.
- [x] I have updated the documentation and CHANGELOG accordingly.
- [x] I have read the CONTRIBUTING document.

Fixes https://github.com/AgnostiqHQ/covalent/issues/832

Let me know if I am editing the CHANGELOG correctly.

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/AgnostiqHQ/covalent?pullRequest=1578) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/AgnostiqHQ/covalent?pullRequest=1578) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/AgnostiqHQ/covalent?pullRequest=1578) it.</sub>
madhur-tandon: @santoshkumarradha can I have a review here?
codecov[bot]: ## [Codecov](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1578?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) Report
> Merging [#1578](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1578?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (3e6a8e2) into [develop](https://codecov.io/gh/AgnostiqHQ/covalent/commit/316e8287099e4ed345ee2e97f82bd3d450f0ceb6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ) (316e828) will **increase** coverage by `0.00%`.
> The diff coverage is `88.88%`.

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1578/graphs/tree.svg?width=650&height=150&src=pr&token=YGHCB3DE4P&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)](https://codecov.io/gh/AgnostiqHQ/covalent/pull/1578?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=AgnostiqHQ)

```diff
@@           Coverage Diff            @@
##           develop    #1578   +/-   ##
========================================
  Coverage    85.67%   85.67%           
========================================
  Files          158      158           
  Lines         6568     6576    +8     
  Branches       145      145           
========================================
+ Hits          5627     5634    +7     
- Misses         839      840    +1     
  Partials       102      102           
```

| Flag | Coverage Δ | |
|---|---|---|
| Dispatcher | `87.28% <ø> (ø)` | |
| Functional_Tests | `59.35% <66.66%> (+0.02%)` | :arrow_up: |
| SDK | `86.02% <88.88%> (+0.03%)` | :arrow_up: |
| UI_Frontend | `72.13% <ø> (ø)` | |

</details>

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 760327ef..e6479427 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a127eb61..b257fc7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [UNRELEASED]
 
+### Authors
+
+- Madhur Tandon <madhurtandon23@gmail.com>
+
+### Fixed
+
+- Result status comparison
+
 ## [0.221.0-rc.0] - 2023-04-17
 
 ### Authors
diff --git a/covalent/_shared_files/util_classes.py b/covalent/_shared_files/util_classes.py
index 5c776a2c..1bbdd566 100644
--- a/covalent/_shared_files/util_classes.py
+++ b/covalent/_shared_files/util_classes.py
@@ -37,6 +37,16 @@ class Status:
     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")
diff --git a/covalent/triggers/base.py b/covalent/triggers/base.py
index 796c2a8e..fd98b483 100644
--- a/covalent/triggers/base.py
+++ b/covalent/triggers/base.py
@@ -167,7 +167,7 @@ class BaseTrigger:
 
         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}")


Test patch:
diff --git a/tests/covalent_dispatcher_tests/_service/app_test.py b/tests/covalent_dispatcher_tests/_service/app_test.py
index bd0319fd..48db5069 100644
--- a/tests/covalent_dispatcher_tests/_service/app_test.py
+++ b/tests/covalent_dispatcher_tests/_service/app_test.py
@@ -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")
 
 
diff --git a/tests/covalent_tests/results_manager_tests/results_test.py b/tests/covalent_tests/results_manager_tests/results_test.py
index f0746a82..205216d3 100644
--- a/tests/covalent_tests/results_manager_tests/results_test.py
+++ b/tests/covalent_tests/results_manager_tests/results_test.py
@@ -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`"""
 
diff --git a/tests/functional_tests/basic_dispatcher_test.py b/tests/functional_tests/basic_dispatcher_test.py
index ec540397..e62bb340 100644
--- a/tests/functional_tests/basic_dispatcher_test.py
+++ b/tests/functional_tests/basic_dispatcher_test.py
@@ -102,7 +102,7 @@ def test_results_dir_in_sublattice():
     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
 
diff --git a/tests/functional_tests/workflow_stack_test.py b/tests/functional_tests/workflow_stack_test.py
index c160feab..fd2b0c43 100644
--- a/tests/functional_tests/workflow_stack_test.py
+++ b/tests/functional_tests/workflow_stack_test.py
@@ -924,10 +924,10 @@ def test_redispatch_reusing_previous_results_and_new_args():
     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"]