From bc0c2b78c4608354ab6e6e717295c3fbd1ada456 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Wed, 26 Jun 2024 14:51:52 -0400 Subject: [PATCH] Abstract away URL fetch, remove GH reference --- src/rapids_metadata/{http.py => remote.py} | 10 ++++++---- tests/{test_http.py => test_remote.py} | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) rename src/rapids_metadata/{http.py => remote.py} (74%) rename tests/{test_http.py => test_remote.py} (74%) diff --git a/src/rapids_metadata/http.py b/src/rapids_metadata/remote.py similarity index 74% rename from src/rapids_metadata/http.py rename to src/rapids_metadata/remote.py index 360b9ef..33789b7 100644 --- a/src/rapids_metadata/http.py +++ b/src/rapids_metadata/remote.py @@ -19,13 +19,15 @@ from .metadata import RAPIDSMetadata -GITHUB_METADATA_URL = "https://raw.githubusercontent.com/rapidsai/rapids-metadata/main/rapids-metadata.json" +__all__ = ["fetch_latest"] +_GITHUB_METADATA_URL = "https://raw.githubusercontent.com/rapidsai/rapids-metadata/main/rapids-metadata.json" -def fetch_from_url(url: str) -> RAPIDSMetadata: + +def _fetch_from_url(url: str) -> RAPIDSMetadata: with urllib.request.urlopen(url) as f: return pydantic.TypeAdapter(RAPIDSMetadata).validate_json(f.read()) -def fetch_from_github() -> RAPIDSMetadata: - return fetch_from_url(GITHUB_METADATA_URL) +def fetch_latest() -> RAPIDSMetadata: + return _fetch_from_url(_GITHUB_METADATA_URL) diff --git a/tests/test_http.py b/tests/test_remote.py similarity index 74% rename from tests/test_http.py rename to tests/test_remote.py index 3210240..07c145f 100644 --- a/tests/test_http.py +++ b/tests/test_remote.py @@ -17,7 +17,7 @@ from pytest_httpserver import HTTPServer from pydantic import TypeAdapter -import rapids_metadata.http as rapids_http +import rapids_metadata.remote as rapids_remote from rapids_metadata import all_metadata from rapids_metadata.metadata import RAPIDSMetadata @@ -27,13 +27,13 @@ def test_fetch_from_url(httpserver: HTTPServer): TypeAdapter(RAPIDSMetadata).dump_python(all_metadata) ) assert ( - rapids_http.fetch_from_url(httpserver.url_for("/rapids-metadata.json")) + rapids_remote._fetch_from_url(httpserver.url_for("/rapids-metadata.json")) == all_metadata ) -def test_fetch_from_github(): - with patch("rapids_metadata.http.fetch_from_url") as patch_fetch_from_url: - return_value = rapids_http.fetch_from_github() - patch_fetch_from_url.assert_called_once_with(rapids_http.GITHUB_METADATA_URL) +def test_fetch_latest(): + with patch("rapids_metadata.remote._fetch_from_url") as patch_fetch_from_url: + return_value = rapids_remote.fetch_latest() + patch_fetch_from_url.assert_called_once_with(rapids_remote._GITHUB_METADATA_URL) assert return_value == patch_fetch_from_url()