Skip to content

Commit

Permalink
Require path to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
cblakkan committed Dec 30, 2024
1 parent 9b7a74e commit d0472d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions yamale/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ def should_exclude(yaml_path):
return should_exclude

for path in paths:
path = os.path.abspath(path)
if os.path.isdir(path):
_validate_dir(path, schema_name, cpus, parser, strict, should_exclude)
abs_path = os.path.abspath(path)
if not os.path.exists(abs_path):
raise ValueError(f"Path does not exist: {path}")
if os.path.isdir(abs_path):
_validate_dir(abs_path, schema_name, cpus, parser, strict, should_exclude)
else:
_validate_file(path, schema_name, parser, strict, should_exclude)
_validate_file(abs_path, schema_name, parser, strict, should_exclude)


def main():
Expand Down
11 changes: 11 additions & 0 deletions yamale/tests/test_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def test_bad_dir():
command_line._router("yamale/tests/command_line_fixtures/yamls", "schema.yaml", 4, "PyYAML")


def test_bad_path_raises():
with pytest.raises(ValueError) as e:
command_line._router(
paths=["yamale/tests/command_line_fixtures/yamls/a path that does not exist.yaml"],
schema_name="schema.yaml",
cpus=1,
parser="PyYAML",
)
assert "Path does not exist" in str(e)


def test_bad_strict():
with pytest.raises(ValueError) as e:
command_line._router(
Expand Down

0 comments on commit d0472d0

Please sign in to comment.