Skip to content

Commit e39ae17

Browse files
committed
Refactor error messages for clarity and consistency in registry handling
1 parent e634814 commit e39ae17

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

dem/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main() -> None:
3333
except LookupError as e:
3434
stderr.print("[red]" + str(e) + "[/]")
3535
except RegistryError as e:
36-
stderr.print("[red]" + str(e) + "\nUsing local tool images only![/]")
36+
stderr.print(f"[red]{str(e)}[/]")
3737
except docker.errors.DockerException as e:
3838
stderr.print("[red]" + str(e) + "[/]")
3939

dem/core/registry.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, registry_config: dict) -> None:
137137
super().__init__(registry_config)
138138

139139
if not self._namespace:
140-
raise RegistryError("Invalid registry configuration. For Docker Hub the namesapce must be set.")
140+
raise RegistryError("Invalid registry configuration. For Docker Hub the namespace must be set.")
141141

142142
def _append_repo_with_tag(self, endpoint_response: dict, repo: str) -> None:
143143
""" Get the tags from the endpoint response. Save the tags alongside with the actual repo

tests/core/test_registry.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,12 @@ def test_DockerHub_invalid_registry_config() -> None:
366366
}
367367

368368
# Run unit under test
369-
with pytest.raises(registry.RegistryError):
369+
with pytest.raises(registry.RegistryError) as exported_exception_info:
370370
registry.DockerHub(test_registry_config)
371371

372+
# Check expectations
373+
assert "Registry error: Invalid registry configuration. For Docker Hub the namespace must be set." == str(exported_exception_info.value)
374+
372375
@patch.object(registry.DockerHub, "__init__")
373376
def test_DockerHub__append_repo_with_tag(mock___init__: MagicMock) -> None:
374377
# Test setup

tests/test__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_cli_RegistryError(mock_Platform: MagicMock, mock_cli_main: MagicMock, m
9292
mock_Core.set_user_output.assert_called_once_with(mock_tui_user_output)
9393
mock_platform.config_file.update.assert_called_once()
9494
mock_cli_main.typer_cli.assert_called_once_with(prog_name=__command__)
95-
mock_stderr_print.assert_called_once_with("[red]Registry error: " + test_exception_text + "\nUsing local tool images only![/]")
95+
mock_stderr_print.assert_called_once_with(f"[red]Registry error: {test_exception_text}[/]")
9696

9797
@patch("dem.__main__.stdout.print")
9898
@patch("dem.__main__.stderr.print")

0 commit comments

Comments
 (0)