Skip to content

Commit

Permalink
chore(KONFLUX-887): show nicer output for missing compose input file
Browse files Browse the repository at this point in the history
Currently, if the input YAML is missing, a generic error exception
will tell the file is missing. This change raises a clearer exception.

Signed-off-by: Yftach Herzog <[email protected]>
  • Loading branch information
yftacherzog committed Jan 14, 2024
1 parent c63ac8a commit 60cd062
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion generate_compose/odcs_compose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def main(
Get inputs from container and content_sets YAMLs and relay them to an ODCS
compose generator that will request a compose and store it in a TBD location.
"""
compose_inputs: dict = yaml.safe_load(compose_input_yaml_path.read_text())
try:
compose_inputs: dict = yaml.safe_load(compose_input_yaml_path.read_text())
except FileNotFoundError as ex:
raise FileNotFoundError(
f"Could not find compose input file at {compose_input_yaml_path.resolve()}"
) from ex

compose_generator = ComposeGenerator(
configurations_generator=ODCSConfigurationsGenerator(
Expand Down
22 changes: 22 additions & 0 deletions tests/test_odcs_compose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,25 @@ def test_main( # pylint: disable=too-many-arguments
fetcher=mock_fetcher.return_value,
)
mock_compose_generator.return_value.assert_called_once_with()

def test_main_missing_input_file( # pylint: disable=too-many-arguments
self,
compose_dir_path: Path,
) -> None:
"""Test call to odcs_compose_generator.py main function"""
input_yaml = Path("no/such/file")
with pytest.raises(FileNotFoundError) as ex:
odcs_compose_generator.main( # pylint: disable=no-value-for-parameter
args=[
"--compose-dir-path",
str(compose_dir_path),
"--compose-input-yaml-path",
str(input_yaml),
],
obj={},
standalone_mode=False,
)
assert (
str(ex.value)
== f"Could not find compose input file at {input_yaml.resolve()}"
)

0 comments on commit 60cd062

Please sign in to comment.