Skip to content

Commit

Permalink
Abstract away URL fetch, remove GH reference
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Jun 26, 2024
1 parent 9ad85cc commit bc0c2b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/rapids_metadata/http.py → src/rapids_metadata/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions tests/test_http.py → tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

0 comments on commit bc0c2b7

Please sign in to comment.