From 70faa5832c5919e40ee72286959b2bb10efa1a60 Mon Sep 17 00:00:00 2001 From: Cordell Blakkan Date: Tue, 5 Mar 2024 11:58:40 -0500 Subject: [PATCH 1/7] Update tox --- .github/workflows/run-tests.yml | 2 +- README.md | 4 ++-- tox.ini | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b6b45f8..8f421b2 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.12"] + python-version: ["3.8", "3.10", "3.12"] steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 5a1cf7e..5671667 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Yamale (ya·ma·lē) | :warning: Ensure that your schema definitions come from internal or trusted sources. Yamale does not protect against intentionally malicious schemas. | |:------------| -Yamale +Yamale A schema and validator for YAML. @@ -35,7 +35,7 @@ building Python 3 from source; in all three cases, Apple's Command Line Tools (C may be required. See also [developers](#developers), below. ### Manual -1. Download Yamale from: https://github.com/23andMe/Yamale/archive/master.zip +1. Download Yamale from: https://github.com/23andMe/Yamale/archive/main.zip 2. Unzip somewhere temporary 3. Run `python setup.py install` (may have to prepend `sudo`) diff --git a/tox.ini b/tox.ini index fff02c0..4eb92da 100644 --- a/tox.ini +++ b/tox.ini @@ -4,6 +4,7 @@ envlist = py38, py310 [gh-actions] python = 3.8: py38 + 3.10: py310 3.12: py312 [testenv] From 39097b74883c4af94470d68015f00ecfe6552536 Mon Sep 17 00:00:00 2001 From: Cordell Blakkan Date: Tue, 5 Mar 2024 11:58:40 -0500 Subject: [PATCH 2/7] Prep for 5.0.0; Run tests on 3.8, 3.12 --- .github/workflows/run-tests.yml | 2 +- tox.ini | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 8f421b2..b6b45f8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.8", "3.10", "3.12"] + python-version: ["3.8", "3.12"] steps: - uses: actions/checkout@v2 diff --git a/tox.ini b/tox.ini index 4eb92da..fff02c0 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ envlist = py38, py310 [gh-actions] python = 3.8: py38 - 3.10: py310 3.12: py312 [testenv] From 2432211b793effcb7c285ff3f4526c9627ede20d Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Sun, 30 Jun 2024 15:37:20 +0200 Subject: [PATCH 3/7] feat: support multiple paths in yamale Currently only one path is supported. --- yamale/command_line.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/yamale/command_line.py b/yamale/command_line.py index 77fba4f..c5f20fa 100644 --- a/yamale/command_line.py +++ b/yamale/command_line.py @@ -98,18 +98,19 @@ def _validate_dir(root, schema_name, cpus, parser, strict): raise ValueError("\n----\n".join(set(error_messages))) -def _router(root, schema_name, cpus, parser, strict=True): - root = os.path.abspath(root) - if os.path.isfile(root): - _validate_single(root, schema_name, parser, strict) - else: - _validate_dir(root, schema_name, cpus, parser, strict) +def _router(paths, schema_name, cpus, parser, strict=True): + for path in paths: + path = os.path.abspath(path) + if os.path.isfile(path): + _validate_single(path, schema_name, parser, strict) + else: + _validate_dir(path, schema_name, cpus, parser, strict) def main(): parser = argparse.ArgumentParser(description="Validate yaml files.") parser.add_argument( - "path", metavar="PATH", default="./", nargs="?", help="folder to validate. Default is current directory." + "paths", metavar="PATHS", default=["./"], nargs="*", help="Paths to validate, either directories or files. Default is the current directory." ) parser.add_argument("-V", "--version", action="version", version=__version__) parser.add_argument("-s", "--schema", default="schema.yaml", help="filename of schema. Default is schema.yaml.") @@ -125,7 +126,7 @@ def main(): ) args = parser.parse_args() try: - _router(args.path, args.schema, args.cpu_num, args.parser, not args.no_strict) + _router(args.paths, args.schema, args.cpu_num, args.parser, not args.no_strict) except (SyntaxError, NameError, TypeError, ValueError) as e: print("Validation failed!\n%s" % str(e)) exit(1) From aebc0929e9e02d8aa194748dd1dac38d5b39aed4 Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Mon, 1 Jul 2024 19:55:05 +0200 Subject: [PATCH 4/7] update tests --- yamale/tests/test_command_line.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/yamale/tests/test_command_line.py b/yamale/tests/test_command_line.py index f728445..e1cbf70 100644 --- a/yamale/tests/test_command_line.py +++ b/yamale/tests/test_command_line.py @@ -25,7 +25,7 @@ def scoped_change_dir(new_dir): def test_bad_yaml(parser): with pytest.raises(ValueError) as e: command_line._router( - "yamale/tests/command_line_fixtures/yamls/bad.yaml", + ["yamale/tests/command_line_fixtures/yamls/bad.yaml"], "schema.yaml", 1, parser, @@ -37,7 +37,7 @@ def test_bad_yaml(parser): def test_required_keys_yaml(parser): with pytest.raises(ValueError) as e: command_line._router( - "yamale/tests/command_line_fixtures/yamls/required_keys_bad.yaml", + ["yamale/tests/command_line_fixtures/yamls/required_keys_bad.yaml"], "required_keys_schema.yaml", 1, parser, @@ -47,13 +47,13 @@ def test_required_keys_yaml(parser): @pytest.mark.parametrize("parser", parsers) def test_good_yaml(parser): - command_line._router("yamale/tests/command_line_fixtures/yamls/good.yaml", "schema.yaml", 1, parser) + command_line._router(["yamale/tests/command_line_fixtures/yamls/good.yaml"], "schema.yaml", 1, parser) @pytest.mark.parametrize("parser", parsers) def test_good_relative_yaml(parser): command_line._router( - "yamale/tests/command_line_fixtures/yamls/good.yaml", + ["yamale/tests/command_line_fixtures/yamls/good.yaml"], "../schema_dir/external.yaml", 1, parser, @@ -63,13 +63,13 @@ def test_good_relative_yaml(parser): @pytest.mark.parametrize("parser", parsers) def test_good_relative_schema_in_subfolder(parser): with scoped_change_dir("yamale/tests/command_line_fixtures/schema_dir"): - command_line._router("../yamls/good.yaml", "external.yaml", 1, parser) + command_line._router(["../yamls/good.yaml"], "external.yaml", 1, parser) @pytest.mark.parametrize("parser", parsers) def test_external_glob_schema(parser): command_line._router( - "yamale/tests/command_line_fixtures/yamls/good.yaml", + ["yamale/tests/command_line_fixtures/yamls/good.yaml"], os.path.join(dir_path, "command_line_fixtures/schema_dir/ex*.yaml"), 1, parser, @@ -79,7 +79,7 @@ def test_external_glob_schema(parser): def test_empty_schema_file(): with pytest.raises(ValueError, match="is an empty file!"): command_line._router( - "yamale/tests/command_line_fixtures/empty_schema/data.yaml", + ["yamale/tests/command_line_fixtures/empty_schema/data.yaml"], "empty_schema.yaml", 1, "PyYAML", @@ -88,7 +88,7 @@ def test_empty_schema_file(): def test_external_schema(): command_line._router( - "yamale/tests/command_line_fixtures/yamls/good.yaml", + ["yamale/tests/command_line_fixtures/yamls/good.yaml"], os.path.join(dir_path, "command_line_fixtures/schema_dir/external.yaml"), 1, "PyYAML", @@ -103,7 +103,7 @@ def test_bad_dir(): def test_bad_strict(): with pytest.raises(ValueError) as e: command_line._router( - "yamale/tests/command_line_fixtures/yamls/required_keys_extra_element.yaml", + ["yamale/tests/command_line_fixtures/yamls/required_keys_extra_element.yaml"], "required_keys_schema.yaml", 4, "PyYAML", @@ -115,7 +115,7 @@ def test_bad_strict(): def test_bad_issue_54(): with pytest.raises(yamale_error.YamaleError) as e: command_line._router( - "yamale/tests/fixtures/nested_issue_54.yaml", + ["yamale/tests/fixtures/nested_issue_54.yaml"], "nested.yaml", 4, "PyYAML", @@ -132,4 +132,4 @@ def test_bad_issue_54(): def test_nested_schema_issue_69(): - command_line._router("yamale/tests/command_line_fixtures/nestedYaml", "schema.yaml", 1, "PyYAML") + command_line._router(["yamale/tests/command_line_fixtures/nestedYaml"], "schema.yaml", 1, "PyYAML") From ef9fe055f11fca959f7c9af9e8a8dcf915f3605e Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Mon, 1 Jul 2024 20:11:57 +0200 Subject: [PATCH 5/7] add test for multiple paths --- yamale/tests/command_line_fixtures/yamls/good2.yaml | 3 +++ yamale/tests/test_command_line.py | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 yamale/tests/command_line_fixtures/yamls/good2.yaml diff --git a/yamale/tests/command_line_fixtures/yamls/good2.yaml b/yamale/tests/command_line_fixtures/yamls/good2.yaml new file mode 100644 index 0000000..5d4e6b5 --- /dev/null +++ b/yamale/tests/command_line_fixtures/yamls/good2.yaml @@ -0,0 +1,3 @@ +map: + good: "world" + yes: 4 diff --git a/yamale/tests/test_command_line.py b/yamale/tests/test_command_line.py index e1cbf70..da80c96 100644 --- a/yamale/tests/test_command_line.py +++ b/yamale/tests/test_command_line.py @@ -50,6 +50,13 @@ def test_good_yaml(parser): command_line._router(["yamale/tests/command_line_fixtures/yamls/good.yaml"], "schema.yaml", 1, parser) +def test_multiple_paths_good_yaml(): + command_line._router([ + "yamale/tests/command_line_fixtures/yamls/good.yaml", + "yamale/tests/command_line_fixtures/yamls/good2.yaml", + ], "schema.yaml", 1, "PyYAML") + + @pytest.mark.parametrize("parser", parsers) def test_good_relative_yaml(parser): command_line._router( From 6e25e326e0b7fb42761b0eca41a712d64b636378 Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Mon, 1 Jul 2024 20:15:35 +0200 Subject: [PATCH 6/7] add test for multiple paths (bad) --- README.md | 4 ++-- yamale/tests/test_command_line.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5671667..5a1cf7e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Yamale (ya·ma·lē) | :warning: Ensure that your schema definitions come from internal or trusted sources. Yamale does not protect against intentionally malicious schemas. | |:------------| -Yamale +Yamale A schema and validator for YAML. @@ -35,7 +35,7 @@ building Python 3 from source; in all three cases, Apple's Command Line Tools (C may be required. See also [developers](#developers), below. ### Manual -1. Download Yamale from: https://github.com/23andMe/Yamale/archive/main.zip +1. Download Yamale from: https://github.com/23andMe/Yamale/archive/master.zip 2. Unzip somewhere temporary 3. Run `python setup.py install` (may have to prepend `sudo`) diff --git a/yamale/tests/test_command_line.py b/yamale/tests/test_command_line.py index da80c96..5f42920 100644 --- a/yamale/tests/test_command_line.py +++ b/yamale/tests/test_command_line.py @@ -57,6 +57,16 @@ def test_multiple_paths_good_yaml(): ], "schema.yaml", 1, "PyYAML") +def test_multiple_paths_bad_yaml(): + with pytest.raises(ValueError) as e: + command_line._router([ + "yamale/tests/command_line_fixtures/yamls/bad.yaml", + "yamale/tests/command_line_fixtures/yamls/required_keys_bad.yaml", + ], "schema.yaml", 1, "PyYAML") + assert "map.bad: '12.5' is not a str." in e.value.message + assert "map.key: Required field missing" in e.value.message + + @pytest.mark.parametrize("parser", parsers) def test_good_relative_yaml(parser): command_line._router( From 420069952cffb85158d6cd21cc659e3db2933e9e Mon Sep 17 00:00:00 2001 From: Cordell Blakkan Date: Sat, 28 Dec 2024 14:16:02 -0500 Subject: [PATCH 7/7] Fix test --- yamale/command_line.py | 6 +++--- yamale/tests/test_command_line.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/yamale/command_line.py b/yamale/command_line.py index c5f20fa..d5cb929 100644 --- a/yamale/command_line.py +++ b/yamale/command_line.py @@ -101,10 +101,10 @@ def _validate_dir(root, schema_name, cpus, parser, strict): def _router(paths, schema_name, cpus, parser, strict=True): for path in paths: path = os.path.abspath(path) - if os.path.isfile(path): - _validate_single(path, schema_name, parser, strict) - else: + if os.path.isdir(path): _validate_dir(path, schema_name, cpus, parser, strict) + else: + _validate_single(path, schema_name, parser, strict) def main(): diff --git a/yamale/tests/test_command_line.py b/yamale/tests/test_command_line.py index 5f42920..e5c4cf9 100644 --- a/yamale/tests/test_command_line.py +++ b/yamale/tests/test_command_line.py @@ -60,11 +60,10 @@ def test_multiple_paths_good_yaml(): def test_multiple_paths_bad_yaml(): with pytest.raises(ValueError) as e: command_line._router([ + "yamale/tests/command_line_fixtures/yamls/good.yaml", "yamale/tests/command_line_fixtures/yamls/bad.yaml", - "yamale/tests/command_line_fixtures/yamls/required_keys_bad.yaml", ], "schema.yaml", 1, "PyYAML") - assert "map.bad: '12.5' is not a str." in e.value.message - assert "map.key: Required field missing" in e.value.message + assert "map.bad: '12.5' is not a int." in e.value.message @pytest.mark.parametrize("parser", parsers)