-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
35b1c99
commit 603a95f
Showing
3 changed files
with
47 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Azure API versions follow the next formats: YYYY-MM-DD or YYYY-MM-DD-preview | ||
def compare_versions(v1: str, v2: str): | ||
if len(v1) < 10 or len(v2) < 10: | ||
return None | ||
|
||
v1 = v1[0:10] | ||
v2 = v2[0:10] | ||
|
||
if v1 < v2: | ||
return -1 | ||
elif v1 > v2: | ||
return 1 | ||
else: | ||
return 0 |
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,20 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from aidial_adapter_openai.utils.versions import compare_versions | ||
|
||
compare_versions_dataset = [ | ||
("2023-07-01", "2023-07-01", 0), | ||
("2023-07-01", "2023-07-01-preview", 0), | ||
("2023-07-01-preview", "2023-07-01", 0), | ||
("2023-07-01-preview", "2023-07-01-preview", 0), | ||
("2023-07-0", "2023-07-01", None), | ||
("2022-12-01", "2023-06-01-preview", -1), | ||
("2023-09-01-preview", "2023-05-15", 1), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("v1, v2, result", compare_versions_dataset) | ||
def test_compare_versions(v1: str, v2: str, result: Optional[int]): | ||
assert compare_versions(v1, v2) == result |