From d0472d05888e78cc183b7c1bda9a1f3f69de0e0e Mon Sep 17 00:00:00 2001 From: Cordell Blakkan Date: Mon, 30 Dec 2024 15:04:55 -0500 Subject: [PATCH] Require path to exist --- yamale/command_line.py | 10 ++++++---- yamale/tests/test_command_line.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/yamale/command_line.py b/yamale/command_line.py index ad9c1f8..127ceb1 100644 --- a/yamale/command_line.py +++ b/yamale/command_line.py @@ -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(): diff --git a/yamale/tests/test_command_line.py b/yamale/tests/test_command_line.py index 00aabe4..2102fe5 100644 --- a/yamale/tests/test_command_line.py +++ b/yamale/tests/test_command_line.py @@ -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(