Skip to content

Commit 67d2e62

Browse files
authored
Merge pull request #219 from even-even/improve_shotcuts_and_add_test
improve logging in shortcuts.py and turn to pytest in test_shortcut.py
2 parents f585459 + 35e7b4a commit 67d2e62

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Installation
2020

2121
.. md-tab-set::
2222

23-
.. md-tab-item:: Pip + PyPI (recommented)
23+
.. md-tab-item:: Pip + PyPI (recommended)
2424

2525
.. code-block:: console
2626

openapi_schema_validator/shortcuts.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def validate(
1515
*args: Any,
1616
**kwargs: Any
1717
) -> None:
18+
"""
19+
Validate an instance against a given schema using the specified validator class.
20+
"""
1821
schema_dict = cast(dict[str, Any], schema)
1922
cls.check_schema(schema_dict)
2023
validator = cls(schema_dict, *args, **kwargs)

tests/unit/test_shortcut.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
from unittest import TestCase
1+
import pytest
22

33
from openapi_schema_validator import validate
44

55

6-
class ValidateTest(TestCase):
7-
def test_validate_does_not_mutate_schema_adding_nullable_key(self):
8-
schema = {
9-
"type": "object",
10-
"properties": {
11-
"email": {"type": "string"},
12-
"enabled": {
13-
"type": "boolean",
14-
},
6+
@pytest.fixture(scope="function")
7+
def schema():
8+
return {
9+
"type": "object",
10+
"properties": {
11+
"email": {"type": "string"},
12+
"enabled": {
13+
"type": "boolean",
1514
},
16-
"example": {"enabled": False, "email": "foo@bar.com"},
17-
}
15+
},
16+
"example": {"enabled": False, "email": "foo@bar.com"},
17+
}
1818

19-
validate({"email": "foo@bar.com"}, schema)
2019

21-
self.assertTrue("nullable" not in schema["properties"]["email"].keys())
20+
def test_validate_does_not_add_nullable_to_schema(schema):
21+
"""
22+
Verify that calling validate does not add the 'nullable' key to the schema
23+
"""
24+
validate({"email": "foo@bar.com"}, schema)
25+
assert "nullable" not in schema["properties"]["email"].keys()
26+
27+
28+
def test_validate_does_not_mutate_schema(schema):
29+
"""
30+
Verify that calling validate does not mutate the schema
31+
"""
32+
original_schema = schema.copy()
33+
validate({"email": "foo@bar.com"}, schema)
34+
assert schema == original_schema

0 commit comments

Comments
 (0)