From 03e82d4a67ac2cb2bccc61daab53a057a79c667e Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:26:13 +1000 Subject: [PATCH 01/15] feat: Add x-spice-user-agent --- .gitignore | 3 ++- spicepy/_client.py | 16 ++++++++++++---- spicepy/_http.py | 7 ++++++- spicepy/config.py | 31 ++++++++++++++++++++++++++++--- tests/test_main.py | 15 ++++++++++----- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 95cab01..f672ab8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .pytest_cache build dist -spicepy.egg-info \ No newline at end of file +spicepy.egg-info +.env \ No newline at end of file diff --git a/spicepy/_client.py b/spicepy/_client.py index 6236ae4..135bdc9 100644 --- a/spicepy/_client.py +++ b/spicepy/_client.py @@ -5,7 +5,11 @@ from typing import Dict, Union import certifi -from pyarrow._flight import FlightCallOptions, FlightClient, Ticket # pylint: disable=E0611 +from pyarrow._flight import ( + FlightCallOptions, + FlightClient, + Ticket, +) # pylint: disable=E0611 from ._http import HttpRequests from . import config @@ -56,17 +60,21 @@ class _SpiceFlight: def __init__(self, grpc: str, api_key: str, tls_root_certs): self._flight_client = flight.connect(grpc, tls_root_certs=tls_root_certs) self._api_key = api_key - self._flight_options = flight.FlightCallOptions() + self.headers = [("x-spice-user-agent", config.SPICE_USER_AGENT)] + self._flight_options = flight.FlightCallOptions(headers=self.headers) self._authenticate() def _authenticate(self): if self._api_key is not None: - self.headers = [self._flight_client.authenticate_basic_token("", self._api_key)] + self.headers = [ + self._flight_client.authenticate_basic_token("", self._api_key), + ("x-spice-user-agent", config.SPICE_USER_AGENT), + ] self._flight_options = flight.FlightCallOptions( headers=self.headers, timeout=DEFAULT_QUERY_TIMEOUT_SECS ) else: - self.headers = [] + self.headers = [("x-spice-user-agent", config.SPICE_USER_AGENT)] self._flight_options = flight.FlightCallOptions( headers=self.headers, timeout=DEFAULT_QUERY_TIMEOUT_SECS ) diff --git a/spicepy/_http.py b/spicepy/_http.py index 2f28788..ac44664 100644 --- a/spicepy/_http.py +++ b/spicepy/_http.py @@ -5,14 +5,19 @@ from requests.adapters import HTTPAdapter, Retry from .error import SpiceAIError +from .config import SPICE_USER_AGENT -HttpMethod = Literal['POST', 'GET', 'PUT', 'HEAD', 'POST'] +HttpMethod = Literal["POST", "GET", "PUT", "HEAD", "POST"] class HttpRequests: def __init__(self, base_url: str, headers: Dict[str, str]) -> None: self.session = self._create_session(headers) + + # set the x-spice-user-agent header + self.session.headers["X-Spice-User-Agent"] = SPICE_USER_AGENT + self.base_url = base_url def send_request( diff --git a/spicepy/config.py b/spicepy/config.py index 2fe1969..da401d0 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -1,8 +1,33 @@ import os +import pkg_resources +import platform DEFAULT_FLIGHT_URL = os.environ.get("SPICE_FLIGHT_URL", "grpc+tls://flight.spiceai.io") -DEFAULT_FIRECACHE_URL = os.environ.get("SPICE_FIRECACHE_URL", "grpc+tls://firecache.spiceai.io") +DEFAULT_FIRECACHE_URL = os.environ.get( + "SPICE_FIRECACHE_URL", "grpc+tls://firecache.spiceai.io" +) DEFAULT_HTTP_URL = os.environ.get("SPICE_HTTP_URL", "https://data.spiceai.io") -DEFAULT_LOCAL_FLIGHT_URL = os.environ.get("SPICE_LOCAL_FLIGHT_URL", "grpc://localhost:50051") -DEFAULT_LOCAL_HTTP_URL = os.environ.get("SPICE_LOCAL_HTTP_URL", "http://localhost:3000 ") +DEFAULT_LOCAL_FLIGHT_URL = os.environ.get( + "SPICE_LOCAL_FLIGHT_URL", "grpc://localhost:50051" +) +DEFAULT_LOCAL_HTTP_URL = os.environ.get( + "SPICE_LOCAL_HTTP_URL", "http://localhost:3000 " +) + + +def get_user_agent(): + package_version = pkg_resources.get_distribution("spicepy").version + system = platform.system() + release = platform.release() + arch = platform.architecture()[0] + if arch == "32bit": # expect a shorthand x32 or x64 + arch = "x32" + elif arch == "64bit": + arch = "x64" + + system_info = "%s/%s %s" % (system, release, arch) + return "spicepy %s (%s)" % (package_version, system_info) + + +SPICE_USER_AGENT = get_user_agent() diff --git a/tests/test_main.py b/tests/test_main.py index f450c50..be58fb6 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,8 +1,8 @@ - import os import time import pytest from spicepy import Client +from spicepy.config import SPICE_USER_AGENT # Skip cloud tests if TEST_SPICE_CLOUD is not set to true @@ -13,16 +13,21 @@ def skip_cloud(): def get_cloud_client(): api_key = os.environ["API_KEY"] - return Client( - api_key=api_key, - flight_url="grpc+tls://flight.spiceai.io" - ) + return Client(api_key=api_key, flight_url="grpc+tls://flight.spiceai.io") def get_local_client(): return Client(flight_url="grpc://localhost:50051") +def test_user_agent_is_populated(): + EXPECTED_PLATFORMS = ["x64", "x32"] + + assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" + assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" + assert SPICE_USER_AGENT.split(" ")[3][:3] in EXPECTED_PLATFORMS + + @skip_cloud() def test_flight_recent_blocks(): client = get_cloud_client() From a26fc0ee6e6f37a5efefac2fa864f4771fde0505 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:32:18 +1000 Subject: [PATCH 02/15] chore: pylint --- spicepy/_client.py | 4 +++- spicepy/config.py | 6 +++--- tests/test_main.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/spicepy/_client.py b/spicepy/_client.py index 135bdc9..da2854e 100644 --- a/spicepy/_client.py +++ b/spicepy/_client.py @@ -5,11 +5,13 @@ from typing import Dict, Union import certifi + +# pylint: disable=E0611 from pyarrow._flight import ( FlightCallOptions, FlightClient, Ticket, -) # pylint: disable=E0611 +) from ._http import HttpRequests from . import config diff --git a/spicepy/config.py b/spicepy/config.py index da401d0..e6c1ad4 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -1,6 +1,6 @@ import os -import pkg_resources import platform +import pkg_resources DEFAULT_FLIGHT_URL = os.environ.get("SPICE_FLIGHT_URL", "grpc+tls://flight.spiceai.io") DEFAULT_FIRECACHE_URL = os.environ.get( @@ -26,8 +26,8 @@ def get_user_agent(): elif arch == "64bit": arch = "x64" - system_info = "%s/%s %s" % (system, release, arch) - return "spicepy %s (%s)" % (package_version, system_info) + system_info = f"{system}/{release} {arch}" + return f"spicepy {package_version} {system_info}" SPICE_USER_AGENT = get_user_agent() diff --git a/tests/test_main.py b/tests/test_main.py index be58fb6..b7667e6 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,11 +21,11 @@ def get_local_client(): def test_user_agent_is_populated(): - EXPECTED_PLATFORMS = ["x64", "x32"] + expected_platforms = ["x64", "x32"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" - assert SPICE_USER_AGENT.split(" ")[3][:3] in EXPECTED_PLATFORMS + assert SPICE_USER_AGENT.split(" ")[3][:3] in expected_platforms @skip_cloud() From 5bcdff97288ce8c0c5380448e1067579124bba8e Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:46:34 +1000 Subject: [PATCH 03/15] fix: Use importlib, fix Flight expecting bytes --- spicepy/_client.py | 16 ++++++++++++---- spicepy/config.py | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spicepy/_client.py b/spicepy/_client.py index da2854e..535ab61 100644 --- a/spicepy/_client.py +++ b/spicepy/_client.py @@ -59,24 +59,32 @@ def read_cert(self, tls_root_cert): class _SpiceFlight: + @staticmethod + def _user_agent(): + # headers kwargs claim to support Tuple[str, str], but it's actually Tuple[bytes, bytes] :| + # Open issue in Arrow: https://github.com/apache/arrow/issues/35288 + return (str.encode("x-spice-user-agent"), str.encode(config.SPICE_USER_AGENT)) + def __init__(self, grpc: str, api_key: str, tls_root_certs): self._flight_client = flight.connect(grpc, tls_root_certs=tls_root_certs) self._api_key = api_key - self.headers = [("x-spice-user-agent", config.SPICE_USER_AGENT)] - self._flight_options = flight.FlightCallOptions(headers=self.headers) + self.headers = [_SpiceFlight._user_agent()] + self._flight_options = flight.FlightCallOptions( + headers=self.headers, timeout=DEFAULT_QUERY_TIMEOUT_SECS + ) self._authenticate() def _authenticate(self): if self._api_key is not None: self.headers = [ self._flight_client.authenticate_basic_token("", self._api_key), - ("x-spice-user-agent", config.SPICE_USER_AGENT), + _SpiceFlight._user_agent(), ] self._flight_options = flight.FlightCallOptions( headers=self.headers, timeout=DEFAULT_QUERY_TIMEOUT_SECS ) else: - self.headers = [("x-spice-user-agent", config.SPICE_USER_AGENT)] + self.headers = [_SpiceFlight._user_agent()] self._flight_options = flight.FlightCallOptions( headers=self.headers, timeout=DEFAULT_QUERY_TIMEOUT_SECS ) diff --git a/spicepy/config.py b/spicepy/config.py index e6c1ad4..a84430a 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -1,6 +1,6 @@ import os import platform -import pkg_resources +from importlib.metadata import version DEFAULT_FLIGHT_URL = os.environ.get("SPICE_FLIGHT_URL", "grpc+tls://flight.spiceai.io") DEFAULT_FIRECACHE_URL = os.environ.get( @@ -17,7 +17,7 @@ def get_user_agent(): - package_version = pkg_resources.get_distribution("spicepy").version + package_version = version("spicepy") system = platform.system() release = platform.release() arch = platform.architecture()[0] From 62d57c1d9c9867aba53ccbc8577bd47c0be5a455 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:51:41 +1000 Subject: [PATCH 04/15] fix: Make test workflow more robust --- .github/workflows/test.yml | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bd7bb40..58f4335 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,6 +15,7 @@ jobs: test_pip_install: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: python-version: ['3.11', '3.12'] name: Test with pip install ${{ matrix.python-version }} @@ -32,7 +33,7 @@ jobs: pytest: runs-on: ${{ matrix.os }} strategy: - max-parallel: 1 + fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.11', '3.12'] @@ -48,24 +49,20 @@ jobs: run: | pip install ".[test]" - - name: install Spice - if: matrix.os != 'windows-latest' + - name: Install Spice (https://install.spiceai.org) (Linux) + if: matrix.os == 'ubuntu-latest' env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - function curl() { - if [ -z "$GH_TOKEN" ] - then - command curl -H "Accept: application/vnd.github.v3.raw" \ - $@ - else - command curl -H "Accept: application/vnd.github.v3.raw" \ - -H "Authorization: token $GH_TOKEN" \ - $@ - fi - } curl https://install.spiceai.org | /bin/bash echo "$HOME/.spice/bin" >> $GITHUB_PATH + $HOME/.spice/bin/spice install + + - name: Install Spice (https://install.spiceai.org) (MacOS) + if: matrix.os == 'macos-latest' + run: | + brew install spiceai/spiceai/spice + brew install spiceai/spiceai/spiced - name: install Spice (Windows) if: matrix.os == 'windows-latest' @@ -84,9 +81,9 @@ jobs: spice init spice_qs cd spice_qs spice add spiceai/quickstart - spice run &> spice.log & + spiced &> spice.log & # time to initialize added dataset - sleep 10 + sleep 5 - name: Init and start spice app (Windows) if: matrix.os == 'windows-latest' @@ -96,7 +93,7 @@ jobs: spice add spiceai/quickstart Start-Process -FilePath spice run # time to initialize added dataset - Start-Sleep -Seconds 10 + Start-Sleep -Seconds 5 shell: pwsh - name: Running tests @@ -109,8 +106,7 @@ jobs: - name: Stop spice and check logs working-directory: spice_qs - if: matrix.os != 'windows-latest' + if: matrix.os != 'windows-latest' && always() run: | - sleep 10 - killall spice + killall spice || true cat spice.log From 9499abc0ab8acd190e976ebaf5cd1626860ab5c3 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:27:39 +1000 Subject: [PATCH 05/15] refactor: Use x86_64 for 32bit --- spicepy/config.py | 2 +- tests/test_main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spicepy/config.py b/spicepy/config.py index a84430a..e7dc72a 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -22,7 +22,7 @@ def get_user_agent(): release = platform.release() arch = platform.architecture()[0] if arch == "32bit": # expect a shorthand x32 or x64 - arch = "x32" + arch = "x86_64" elif arch == "64bit": arch = "x64" diff --git a/tests/test_main.py b/tests/test_main.py index b7667e6..a712c14 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x64", "x32"] + expected_platforms = ["x64", "x86_64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" From 132b071592a959960dd3fe3905c24e24097caab9 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:45:01 +1000 Subject: [PATCH 06/15] refactor: I'm very tired and made 32bit x86_64 instead of x86 --- spicepy/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spicepy/config.py b/spicepy/config.py index e7dc72a..b596524 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -22,9 +22,9 @@ def get_user_agent(): release = platform.release() arch = platform.architecture()[0] if arch == "32bit": # expect a shorthand x32 or x64 - arch = "x86_64" + arch = "x86" elif arch == "64bit": - arch = "x64" + arch = "x86_64" system_info = f"{system}/{release} {arch}" return f"spicepy {package_version} {system_info}" From d9c669fb0f5e5b19293bf841985b09be712dc34d Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:46:18 +1000 Subject: [PATCH 07/15] fix: Update the test --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index a712c14..475a89a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x64", "x86_64"] + expected_platforms = ["x86", "x86_64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" From a6039a7e1c5959532dcd7f99ce340a62e881a215 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:49:43 +1000 Subject: [PATCH 08/15] fix: Make machine type more robust --- spicepy/config.py | 6 ++---- tests/test_main.py | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spicepy/config.py b/spicepy/config.py index b596524..2bf9799 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -20,11 +20,9 @@ def get_user_agent(): package_version = version("spicepy") system = platform.system() release = platform.release() - arch = platform.architecture()[0] - if arch == "32bit": # expect a shorthand x32 or x64 + arch = platform.machine() + if arch == "i386": arch = "x86" - elif arch == "64bit": - arch = "x86_64" system_info = f"{system}/{release} {arch}" return f"spicepy {package_version} {system_info}" diff --git a/tests/test_main.py b/tests/test_main.py index 475a89a..c7a62c1 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,11 +21,13 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x86", "x86_64"] + expected_platforms = ["x86", "x86_64", "aarch64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" - assert SPICE_USER_AGENT.split(" ")[3][:3] in expected_platforms + + arch = SPICE_USER_AGENT.split(" ")[3].replace(")", "") + assert arch in expected_platforms @skip_cloud() From eeedf08ff20686a00f0028b3fcc9cf5ea914c0a7 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:51:21 +1000 Subject: [PATCH 09/15] fix: Standardize on i386 instead of x86 --- spicepy/config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/spicepy/config.py b/spicepy/config.py index 2bf9799..e3dfc2f 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -21,8 +21,6 @@ def get_user_agent(): system = platform.system() release = platform.release() arch = platform.machine() - if arch == "i386": - arch = "x86" system_info = f"{system}/{release} {arch}" return f"spicepy {package_version} {system_info}" From c1d70e34368f2e1682aa12d1974110000bf38eaf Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:05:12 +1000 Subject: [PATCH 10/15] fix: Add arm64 to expected platforms --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index c7a62c1..8fca709 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x86", "x86_64", "aarch64"] + expected_platforms = ["x86", "x86_64", "aarch64", "arm64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" From cff85d08afb2b2a5e5dbec7ca6ff09257e4031e5 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:05:47 +1000 Subject: [PATCH 11/15] fix: Increase sleep waiting for dataset setup --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58f4335..a213983 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,7 +83,7 @@ jobs: spice add spiceai/quickstart spiced &> spice.log & # time to initialize added dataset - sleep 5 + sleep 10 - name: Init and start spice app (Windows) if: matrix.os == 'windows-latest' @@ -93,7 +93,7 @@ jobs: spice add spiceai/quickstart Start-Process -FilePath spice run # time to initialize added dataset - Start-Sleep -Seconds 5 + Start-Sleep -Seconds 10 shell: pwsh - name: Running tests From 0667f441d7b32c742058ac30766ca143a1bba17d Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:19:40 +1000 Subject: [PATCH 12/15] fix: Rename AMD64 to x86_64 --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 8fca709..df4fa0a 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x86", "x86_64", "aarch64", "arm64"] + expected_platforms = ["x86", "x86_64", "aarch64", "arm64", "AMD64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" From 54626bbd35e6df2f172d157011ec3918353070c1 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:39:20 +1000 Subject: [PATCH 13/15] fix: Actually rename AMD64 to x86_64 --- spicepy/config.py | 2 ++ tests/test_main.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spicepy/config.py b/spicepy/config.py index e3dfc2f..1581bea 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -21,6 +21,8 @@ def get_user_agent(): system = platform.system() release = platform.release() arch = platform.machine() + if arch == "AMD64": + arch = "x86_64" system_info = f"{system}/{release} {arch}" return f"spicepy {package_version} {system_info}" diff --git a/tests/test_main.py b/tests/test_main.py index df4fa0a..8fca709 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x86", "x86_64", "aarch64", "arm64", "AMD64"] + expected_platforms = ["x86", "x86_64", "aarch64", "arm64"] assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" From 0910172754cd32df4e52cbd04eeb4911b3329e36 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:41:08 +1000 Subject: [PATCH 14/15] fix: Use regex to match expected user agent --- spicepy/config.py | 2 +- tests/test_main.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spicepy/config.py b/spicepy/config.py index 1581bea..62afba9 100644 --- a/spicepy/config.py +++ b/spicepy/config.py @@ -25,7 +25,7 @@ def get_user_agent(): arch = "x86_64" system_info = f"{system}/{release} {arch}" - return f"spicepy {package_version} {system_info}" + return f"spicepy {package_version} ({system_info})" SPICE_USER_AGENT = get_user_agent() diff --git a/tests/test_main.py b/tests/test_main.py index 8fca709..f1b1f72 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,5 +1,6 @@ import os import time +import re import pytest from spicepy import Client from spicepy.config import SPICE_USER_AGENT @@ -21,13 +22,10 @@ def get_local_client(): def test_user_agent_is_populated(): - expected_platforms = ["x86", "x86_64", "aarch64", "arm64"] + # use a regex to match the expected user agent string + matching_regex = r"spicepy \d+\.\d+\.\d+ \((Linux|Windows|macOS)/[\d\w\.\-\_]+ (x86_64|aarch64|i386|arm64)\)" - assert SPICE_USER_AGENT.split(" ")[0] == "spicepy" - assert SPICE_USER_AGENT.split(" ")[1] == "2.0.0" - - arch = SPICE_USER_AGENT.split(" ")[3].replace(")", "") - assert arch in expected_platforms + assert re.match(matching_regex, SPICE_USER_AGENT) @skip_cloud() From 9bf291a0291f4c1b346c42c8570a792c8c471ee1 Mon Sep 17 00:00:00 2001 From: peasee <98815791+peasee@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:56:02 +1000 Subject: [PATCH 15/15] test: Expect Darwin, not macOS --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index f1b1f72..05cbcd5 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -23,7 +23,7 @@ def get_local_client(): def test_user_agent_is_populated(): # use a regex to match the expected user agent string - matching_regex = r"spicepy \d+\.\d+\.\d+ \((Linux|Windows|macOS)/[\d\w\.\-\_]+ (x86_64|aarch64|i386|arm64)\)" + matching_regex = r"spicepy \d+\.\d+\.\d+ \((Linux|Windows|Darwin)/[\d\w\.\-\_]+ (x86_64|aarch64|i386|arm64)\)" assert re.match(matching_regex, SPICE_USER_AGENT)