diff --git a/conda_forge_tick/cli.py b/conda_forge_tick/cli.py index f644f55ce4..022a811703 100644 --- a/conda_forge_tick/cli.py +++ b/conda_forge_tick/cli.py @@ -54,7 +54,7 @@ def invoke(self, ctx: click.Context): @click.option( "--online/--offline", default=False, - help="Online: Use the GitHub API for accessing the dependency graph. This is useful for local testing. Note " + help="online: Use the GitHub API for accessing the dependency graph. This is useful for local testing. Note " "however that any write operations will not be performed. Important: The current working directory will be " "used to cache JSON files. Local files will be used if they exist.", ) diff --git a/conda_forge_tick/lazy_json_backends.py b/conda_forge_tick/lazy_json_backends.py index 2c16ae27fb..9592f9553c 100644 --- a/conda_forge_tick/lazy_json_backends.py +++ b/conda_forge_tick/lazy_json_backends.py @@ -269,6 +269,8 @@ def hget(self, name: str, key: str) -> str: sharded_path = get_sharded_path(f"{name}/{key}.json") url = urllib.parse.urljoin(self.base_url, sharded_path) r = requests.get(url) + if r.status_code == 404: + raise KeyError(f"Key {key} not found in hashmap {name}") r.raise_for_status() return r.text diff --git a/tests/test_lazy_json_backends.py b/tests/test_lazy_json_backends.py index 900967a85b..d77bec8335 100644 --- a/tests/test_lazy_json_backends.py +++ b/tests/test_lazy_json_backends.py @@ -550,3 +550,35 @@ def test_hexists_failure( mock_head.assert_called_once_with( f"{TestGithubLazyJsonBackend.base_url}/name/key.json", ) + + def test_hkeys(self, backend: GithubLazyJsonBackend) -> None: + assert backend.hkeys("name") == [] + + def test_hgetall(self, backend: GithubLazyJsonBackend) -> None: + assert backend.hgetall("name") == {} + + @mock.patch("requests.get") + def test_hget_success( + self, + mock_get: MagicMock, + backend: GithubLazyJsonBackend, + ) -> None: + mock_get.return_value.status_code = 200 + mock_get.return_value.text = "{'key': 'value'}" + assert backend.hget("name", "key") == "{'key': 'value'}" + mock_get.assert_called_once_with( + f"{TestGithubLazyJsonBackend.base_url}/name/4/4/0/9/d/key.json", + ) + + @mock.patch("requests.get") + def test_hget_not_found( + self, + mock_get: MagicMock, + backend: GithubLazyJsonBackend, + ) -> None: + mock_get.return_value.status_code = 404 + with pytest.raises(KeyError): + backend.hget("name", "key") + mock_get.assert_called_once_with( + f"{TestGithubLazyJsonBackend.base_url}/name/4/4/0/9/d/key.json", + )