-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: select a S2 version compatible with TNO RM (#103)
* fix: select a S2 version compatible with TNO RM Signed-off-by: Victor Garcia Reolid <victor@seita.nl> * feat: create function get_latest_compatible_version to find te latest compatible version to use in a S2 connection. Signed-off-by: Victor Garcia Reolid <victor@seita.nl> * test: fix test where the selected version is the latest compatible version (the one provided by the RM). Signed-off-by: Victor Garcia Reolid <victor@seita.nl> --------- Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
- Loading branch information
1 parent
20981c1
commit 8a75aba
Showing
4 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
|
||
import pytest | ||
from packaging.version import Version | ||
|
||
from flexmeasures_client.s2.utils import get_latest_compatible_version | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"supported_versions, current_version, expected_version", | ||
[ | ||
([], "2.3.4", "2.3.4"), # No supported versions → return current_version | ||
(None, "2.3.4", "2.3.4"), # No supported versions → return current_version | ||
( | ||
["1.2.3", "1.2.5", "1.2.9"], | ||
"1.2.4", | ||
"1.2.9", | ||
), # Pick highest supported (>= 1.2.4) | ||
(["2.3.0", "2.3.5", "2.3.9"], "2.3.1", "2.3.9"), # Pick latest >= 2.3.1 | ||
( | ||
["1.4.0", "1.3.0", "1.2.3"], | ||
"1.2.4", | ||
"1.4.0", | ||
), # Pick highest overall (>= 1.2.4) | ||
( | ||
["1.1.0", "1.2.1"], | ||
"2.3.4", | ||
"2.3.4", | ||
), # No compatible version (higher major) → return current_version | ||
( | ||
["2.3.9-alpha", "2.3.5", "2.3.9"], | ||
"2.3.1", | ||
"2.3.9", | ||
), # Pre-release ignored, pick latest valid | ||
( | ||
["2.1.0+build123", "2.1.4"], | ||
"2.1.2", | ||
"2.1.4", | ||
), # Build metadata ignored, pick latest valid | ||
], | ||
) | ||
def test_get_latest_compatible_version( | ||
supported_versions, current_version, expected_version, caplog | ||
): | ||
caplog.set_level(logging.WARNING) # Capture warnings | ||
|
||
latest_version = get_latest_compatible_version( | ||
supported_versions, current_version, logger=logging.getLogger() | ||
) | ||
|
||
assert str(latest_version) == expected_version | ||
|
||
if not supported_versions: | ||
assert "RM didn't provide any supported version" in caplog.text | ||
elif latest_version == Version(current_version): | ||
assert "There are no compatible S2 versions" in caplog.text |