Skip to content

Commit

Permalink
Raise error when invalid requirements are parsed
Browse files Browse the repository at this point in the history
Fixes: #364

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde committed Jun 6, 2023
1 parent 6fa55e3 commit 519ac1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ansible_builder/_target_scripts/introspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def sanitize_requirements(collection_py_reqs):
consolidated.append(req)
seen_pkgs.add(req.name)
except Exception as e:
logger.warning('Warning: failed to parse requirements from %s, error: %s', collection, e)
logger.error('Failed to parse requirements from %s, error: %s', collection, e)
sys.exit(1)

Check warning on line 349 in src/ansible_builder/_target_scripts/introspect.py

View check run for this annotation

Codecov / codecov/patch

src/ansible_builder/_target_scripts/introspect.py#L348-L349

Added lines #L348 - L349 were not covered by tests

# removal of unwanted packages
sanitized = []
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_introspect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pytest

from ansible_builder._target_scripts.introspect import process, process_collection, simple_combine, sanitize_requirements

Expand Down Expand Up @@ -32,3 +33,9 @@ def test_single_collection_metadata(data_dir):

assert py_reqs == ['pyvcloud>=14']
assert sys_reqs == []


def test_corrupt_python_requirements():
with pytest.raises(SystemExit) as excinfo:
sanitize_requirements({'test.metadata': ['invalid_package=1']})
assert excinfo.value.code == 1

0 comments on commit 519ac1e

Please sign in to comment.