From 0c4c02d085f41723dde9c7883f1ef5a5da75055c Mon Sep 17 00:00:00 2001 From: Michal-Babins Date: Tue, 5 Mar 2024 13:08:20 -0700 Subject: [PATCH] fix logic for comparing versions --- nmdc_automation/workflow_automation/sched.py | 9 ++++++--- tests/test_sched.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nmdc_automation/workflow_automation/sched.py b/nmdc_automation/workflow_automation/sched.py index 59639371..3acbd406 100644 --- a/nmdc_automation/workflow_automation/sched.py +++ b/nmdc_automation/workflow_automation/sched.py @@ -42,7 +42,6 @@ def get_version(wf): v_string = wf.version.lstrip("b").lstrip("v") return Version.parse(v_string) - # Check for different workflow names if wf1.name != wf2.name: return False @@ -52,8 +51,12 @@ def get_version(wf): if force: return v1 == v2 - if getattr(v1, version_range) == getattr(v2, version_range): - return True + if version_range == "major": + return v1.major == v2.major + elif version_range == "minor": + return v1.major == v2.major and v1.minor == v2.minor + elif version_range == "patch": + return v1 == v2 return False diff --git a/tests/test_sched.py b/tests/test_sched.py index 7610a4ae..a74f5c98 100644 --- a/tests/test_sched.py +++ b/tests/test_sched.py @@ -111,7 +111,7 @@ def test_within_range(): "Name": "TestWF", "Version": "v1.1.5", } - + # Instantiate Workflow objects from dictionaries wf1_major = Workflow(wf1_major_dict) wf2_major = Workflow(wf2_major_dict) @@ -131,6 +131,9 @@ def test_within_range(): # Test patch version range assert within_range(wf1_patch, wf2_patch, "patch") == False assert within_range(wf1_patch, wf1_minor, "patch") == True + + assert within_range(wf1_patch, wf1_patch, "mafor", force=True) == True + def test_submit(db, mock_api): """