forked from chroma-core/chroma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Chroma client upgrade check
- __version__ is now exported at chromadb package level - New check against pypi for latest chroma version (failures are ignored) Refs: chroma-core#846
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from pytest_httpserver import HTTPServer | ||
|
||
import chromadb | ||
|
||
|
||
def test_new_release_available(caplog: pytest.LogCaptureFixture) -> None: | ||
with patch( | ||
"chromadb.api.client.Client._upgrade_check_url", | ||
new="http://localhost:8008/pypi/chromadb/json", | ||
): | ||
with HTTPServer(port=8008) as httpserver: | ||
# Define the response | ||
httpserver.expect_request("/pypi/chromadb/json").respond_with_data( | ||
json.dumps({"info": {"version": "99.99.99"}}) | ||
) | ||
|
||
# Your code that makes the HTTP call | ||
chromadb.Client() | ||
|
||
assert "A new release of chromadb is available" in caplog.text | ||
|
||
|
||
def test_on_latest_release(caplog: pytest.LogCaptureFixture) -> None: | ||
with HTTPServer(port=8008) as httpserver: | ||
# Define the response | ||
httpserver.expect_request("/pypi/chromadb/json").respond_with_data( | ||
json.dumps({"info": {"version": chromadb.__version__}}) | ||
) | ||
|
||
# Your code that makes the HTTP call | ||
chromadb.Client() | ||
|
||
assert "A new release of chromadb is available" not in caplog.text | ||
|
||
|
||
def test_local_version_newer_than_latest(caplog: pytest.LogCaptureFixture) -> None: | ||
with patch( | ||
"chromadb.api.client.Client._upgrade_check_url", | ||
new="http://localhost:8008/pypi/chromadb/json", | ||
): | ||
with HTTPServer(port=8008) as httpserver: | ||
# Define the response | ||
httpserver.expect_request("/pypi/chromadb/json").respond_with_data( | ||
json.dumps({"info": {"version": "0.0.1"}}) | ||
) | ||
|
||
# Your code that makes the HTTP call | ||
chromadb.Client() | ||
|
||
assert "A new release of chromadb is available" not in caplog.text | ||
|
||
|
||
def test_pypi_unavailable(caplog: pytest.LogCaptureFixture) -> None: | ||
with patch( | ||
"chromadb.api.client.Client._upgrade_check_url", | ||
new="http://localhost:8008/pypi/chromadb/json", | ||
): | ||
with HTTPServer(port=8009) as httpserver: | ||
# Define the response | ||
httpserver.expect_request("/pypi/chromadb/json").respond_with_data( | ||
json.dumps({"info": {"version": "99.99.99"}}) | ||
) | ||
|
||
chromadb.Client() | ||
|
||
assert "A new release of chromadb is available" not in caplog.text |
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,19 @@ | ||
def compare_versions(version1: str, version2: str) -> int: | ||
"""Compares two versions of the format X.Y.Z and returns 1 if version1 is greater than version2, -1 if version1 is | ||
less than version2, and 0 if version1 is equal to version2. | ||
""" | ||
v1_components = list(map(int, version1.split("."))) | ||
v2_components = list(map(int, version2.split("."))) | ||
|
||
for v1, v2 in zip(v1_components, v2_components): | ||
if v1 > v2: | ||
return 1 | ||
elif v1 < v2: | ||
return -1 | ||
|
||
if len(v1_components) > len(v2_components): | ||
return 1 | ||
elif len(v1_components) < len(v2_components): | ||
return -1 | ||
|
||
return 0 |