From 7f6595b76df39267ff104745184ecc6ec8f408d3 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 24 Sep 2024 11:08:13 -0400 Subject: [PATCH 1/2] Analyzing errors in defs Signed-off-by: Mandana Vaziri --- pdl/pdl_schema_error_analyzer.py | 5 +++++ tests/data/line/hello31.pdl | 11 +++++++++++ tests/test_examples.py | 1 + tests/test_line_table.py | 14 ++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 tests/data/line/hello31.pdl diff --git a/pdl/pdl_schema_error_analyzer.py b/pdl/pdl_schema_error_analyzer.py index f6aed8e64..99795740b 100644 --- a/pdl/pdl_schema_error_analyzer.py +++ b/pdl/pdl_schema_error_analyzer.py @@ -117,6 +117,11 @@ def analyze_errors(defs, schema, data, loc: LocationType) -> list[str]: # noqa: ret += analyze_errors( defs, schema["properties"][field], data[field], newloc ) + if "additionalProperties" in schema.keys() and not isinstance(schema["additionalProperties"], bool): + for key, value in data.items(): + nloc = append(loc, key) + ret += analyze_errors(defs, schema["additionalProperties"], data[key], nloc) + elif is_any_of(schema): if len(schema["anyOf"]) == 2 and nullable(schema): diff --git a/tests/data/line/hello31.pdl b/tests/data/line/hello31.pdl new file mode 100644 index 000000000..a6a20fbfa --- /dev/null +++ b/tests/data/line/hello31.pdl @@ -0,0 +1,11 @@ +defs: + + # ... several other defs, ~85 lines + get_current_weather: + function: + subject: str + return: + api: https + url: https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q= + input: "{{ subject }}" + show_result: false \ No newline at end of file diff --git a/tests/test_examples.py b/tests/test_examples.py index f7fc9cd8c..f857b94cc 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -13,6 +13,7 @@ pathlib.Path("tests") / "data" / "line" / "hello8.pdl", pathlib.Path("tests") / "data" / "line" / "hello10.pdl", pathlib.Path("tests") / "data" / "line" / "hello11.pdl", + pathlib.Path("tests") / "data" / "line" / "hello31.pdl", ] diff --git a/tests/test_line_table.py b/tests/test_line_table.py index 0006b631a..ea6239af2 100644 --- a/tests/test_line_table.py +++ b/tests/test_line_table.py @@ -405,3 +405,17 @@ def test_line29(capsys): def test_line30(capsys): do_test(line30, capsys) + +line31 = { + "file": "tests/data/line/hello31.pdl", + "errors": [ + "", + "tests/data/line/hello31.pdl:0 - Missing required field: function", + "tests/data/line/hello31.pdl:0 - Missing required field: return", + "tests/data/line/hello31.pdl:11 - Field not allowed: show_result", + ], +} + + +def test_line31(capsys): + do_test(line31, capsys) \ No newline at end of file From 3fb38c9d41f3900a5e01169a957ba15fc68ea1fa Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 24 Sep 2024 12:53:09 -0400 Subject: [PATCH 2/2] cleanup Signed-off-by: Mandana Vaziri --- pdl/pdl_schema_error_analyzer.py | 9 ++++++--- tests/test_line_table.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pdl/pdl_schema_error_analyzer.py b/pdl/pdl_schema_error_analyzer.py index 99795740b..be529bbee 100644 --- a/pdl/pdl_schema_error_analyzer.py +++ b/pdl/pdl_schema_error_analyzer.py @@ -117,11 +117,14 @@ def analyze_errors(defs, schema, data, loc: LocationType) -> list[str]: # noqa: ret += analyze_errors( defs, schema["properties"][field], data[field], newloc ) - if "additionalProperties" in schema.keys() and not isinstance(schema["additionalProperties"], bool): + if "additionalProperties" in schema.keys() and not isinstance( + schema["additionalProperties"], bool + ): for key, value in data.items(): nloc = append(loc, key) - ret += analyze_errors(defs, schema["additionalProperties"], data[key], nloc) - + ret += analyze_errors( + defs, schema["additionalProperties"], value, nloc + ) elif is_any_of(schema): if len(schema["anyOf"]) == 2 and nullable(schema): diff --git a/tests/test_line_table.py b/tests/test_line_table.py index ea6239af2..74d55a6ab 100644 --- a/tests/test_line_table.py +++ b/tests/test_line_table.py @@ -406,6 +406,7 @@ def test_line29(capsys): def test_line30(capsys): do_test(line30, capsys) + line31 = { "file": "tests/data/line/hello31.pdl", "errors": [ @@ -418,4 +419,4 @@ def test_line30(capsys): def test_line31(capsys): - do_test(line31, capsys) \ No newline at end of file + do_test(line31, capsys)