From 9543ebb05a6662b81499f5a3c2c0a526ebf6ffad Mon Sep 17 00:00:00 2001 From: Shreyas G Gowda Date: Thu, 12 Mar 2026 16:24:35 +0530 Subject: [PATCH 1/2] test: add tests for non-dict JSON validation in JsonSchema --- tests/validation/test_json_schema.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/validation/test_json_schema.py b/tests/validation/test_json_schema.py index d63dc0a..7249790 100644 --- a/tests/validation/test_json_schema.py +++ b/tests/validation/test_json_schema.py @@ -1,3 +1,4 @@ +from promptum.validation.validators import JsonSchema from promptum.validation import JsonSchema @@ -48,3 +49,39 @@ def test_json_schema_describe_without_required_keys() -> None: description = validator.describe() assert description == "Valid JSON object" + + + + +class TestJsonSchema: + def test_valid_dict(self): + validator = JsonSchema() + passed, details = validator.validate('{"name": "Shreyas"}') + assert passed is True + + def test_array_returns_false(self): + validator = JsonSchema() + passed, details = validator.validate("[1, 2, 3]") + assert passed is False + assert "error" in details + + + def test_number_returns_false(self): + validator = JsonSchema() + passed, details = validator.validate("42") + assert passed is False + assert "error" in details + + + + def test_invalid_json_returns_false(self): + validator = JsonSchema() + passed, details = validator.validate("Shreyas") + assert passed is False + assert "error" in details + + def test_missing_required_keys(self): + validator = JsonSchema(required_keys=("name", "age")) + passed, details = validator.validate('{"name": "Shreyas"}') + assert passed is False + assert "age" in details["missing_keys"] \ No newline at end of file From 5ce5cb46ec9318647a928044b8d77395e32dbe8c Mon Sep 17 00:00:00 2001 From: Shreyas G Gowda Date: Sun, 15 Mar 2026 01:37:49 +0530 Subject: [PATCH 2/2] fix: fix ruff style issues in test_json_schema.py --- tests/validation/test_json_schema.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/validation/test_json_schema.py b/tests/validation/test_json_schema.py index 7249790..fcdaf95 100644 --- a/tests/validation/test_json_schema.py +++ b/tests/validation/test_json_schema.py @@ -1,5 +1,4 @@ from promptum.validation.validators import JsonSchema -from promptum.validation import JsonSchema def test_json_schema_valid(json_schema_validator: JsonSchema) -> None: @@ -51,8 +50,6 @@ def test_json_schema_describe_without_required_keys() -> None: assert description == "Valid JSON object" - - class TestJsonSchema: def test_valid_dict(self): validator = JsonSchema() @@ -64,24 +61,21 @@ def test_array_returns_false(self): passed, details = validator.validate("[1, 2, 3]") assert passed is False assert "error" in details - def test_number_returns_false(self): validator = JsonSchema() passed, details = validator.validate("42") assert passed is False assert "error" in details - - def test_invalid_json_returns_false(self): validator = JsonSchema() passed, details = validator.validate("Shreyas") assert passed is False assert "error" in details - + def test_missing_required_keys(self): validator = JsonSchema(required_keys=("name", "age")) passed, details = validator.validate('{"name": "Shreyas"}') assert passed is False - assert "age" in details["missing_keys"] \ No newline at end of file + assert "age" in details["missing_keys"]