From 6471a5efd38d72f2b287026fd404630e21ef6898 Mon Sep 17 00:00:00 2001 From: codedawi Date: Sun, 30 Aug 2020 21:00:02 -0400 Subject: [PATCH] :robot: black formatting files before release --- setup.py | 13 ++++++++----- src/pytest_schema/__init__.py | 5 ++--- src/pytest_schema/helpers.py | 2 +- src/pytest_schema/match.py | 13 ++++++++----- src/pytest_schema/schema.py | 19 +++++++++++-------- src/pytest_schema/types.py | 4 +++- tests/conftest.py | 2 +- tests/test_basic.py | 23 ++++++----------------- tests/test_standard_types.py | 11 ++++++----- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/setup.py b/setup.py index 58252bb..dce4840 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,14 @@ -import os import codecs -from setuptools import setup, find_packages +import os + +from setuptools import find_packages, setup + def read(name: str): file_path = os.path.join(os.path.dirname(__file__), name) return codecs.open(file_path, encoding="utf-8").read() + setup( name="pytest-schema", use_scm_version=True, @@ -21,9 +24,9 @@ def read(name: str): "pytest>=3.5.0", "schema>=0.7.0", ], - setup_requires=['setuptools_scm'], - packages=find_packages('src'), - package_dir={'': 'src'}, + setup_requires=["setuptools_scm"], + packages=find_packages("src"), + package_dir={"": "src"}, include_package_data=True, zip_safe=False, classifiers=[ diff --git a/src/pytest_schema/__init__.py b/src/pytest_schema/__init__.py index aec6eee..4e88550 100644 --- a/src/pytest_schema/__init__.py +++ b/src/pytest_schema/__init__.py @@ -1,5 +1,5 @@ +from pytest_schema.helpers import exact_schema, like_schema, schema from pytest_schema.schema import Schema, SchemaError -from pytest_schema.helpers import schema, like_schema, exact_schema from pytest_schema.types import ( And, Enum, @@ -12,7 +12,6 @@ Use, ) - __all__ = [ "Schema", "schema", @@ -27,4 +26,4 @@ "Or", "Regex", "Use", -] \ No newline at end of file +] diff --git a/src/pytest_schema/helpers.py b/src/pytest_schema/helpers.py index 5476c24..9f5c113 100644 --- a/src/pytest_schema/helpers.py +++ b/src/pytest_schema/helpers.py @@ -56,7 +56,7 @@ def like_schema(value: Any) -> Schema: Returns: Schema: initialized and configured class with non exact match requirements - + Example: ✅ assert like\_schema({ "status": int }) == {"status": 404} diff --git a/src/pytest_schema/match.py b/src/pytest_schema/match.py index d44f83a..722b2aa 100644 --- a/src/pytest_schema/match.py +++ b/src/pytest_schema/match.py @@ -11,6 +11,7 @@ def match(exact: bool = True) -> Callable: Args: exact (bool, optional): Whether validated against exact or allow skip keys. """ + def _decorator(f: Callable): @wraps(f) def _wrapper(self, value: Any) -> bool: @@ -25,11 +26,11 @@ def _wrapper(self, value: Any) -> bool: Returns: bool: binary true or false state of returned value """ - # store original configured value + # store original configured value original: bool = self._ignore_extra_keys - # toggle property to opposite of `exact` param - self._ignore_extra_keys = not exact + # toggle property to opposite of `exact` param + self._ignore_extra_keys = not exact try: # call method an store result @@ -38,8 +39,10 @@ def _wrapper(self, value: Any) -> bool: # raise any SchemaErrors after toggling cls # state back to original value self._ignore_extra_keys = original - + # determine binary (true or false state) - return bool(response) + return bool(response) + return _wrapper + return _decorator diff --git a/src/pytest_schema/schema.py b/src/pytest_schema/schema.py index e6743d6..4c90786 100644 --- a/src/pytest_schema/schema.py +++ b/src/pytest_schema/schema.py @@ -1,13 +1,17 @@ from typing import Any, Callable, Optional -from schema import Schema as BaseSchema, SchemaError +from schema import Schema as BaseSchema +from schema import SchemaError + from pytest_schema.match import match + class Schema(BaseSchema): """ Extention of BaseSchema class to implement \ method to help using with `assert` in tests. """ + def __init__( self, schema: Any, @@ -15,7 +19,7 @@ def __init__( ignore_extra_keys: Optional[bool] = True, name: Optional[str] = None, description: Optional[str] = None, - as_reference: Optional[bool] = False + as_reference: Optional[bool] = False, ): super().__init__( schema, @@ -23,7 +27,7 @@ def __init__( ignore_extra_keys=ignore_extra_keys, name=name, description=description, - as_reference=as_reference + as_reference=as_reference, ) def __eq__(self, value: Any) -> bool: @@ -39,7 +43,7 @@ def __eq__(self, value: Any) -> bool: True when `value` is validate against schema. """ return bool(self.validate(value)) - + def __ne__(self, value: Any) -> bool: """ Compares Schema against value provided when using the `!=` comparsion. @@ -64,7 +68,7 @@ def exact(self, value: Any) -> bool: True when `value` is validate against schema exactly. """ return self.validate(value) - + @match(exact=True) def not_exact(self, value: Any) -> bool: """ @@ -96,12 +100,12 @@ def like(self, value: Any) -> bool: True when `value` is validate against schema. """ return self.validate(value) - + @match(exact=False) def not_like(self, value: Any) -> bool: """ Compares Schema against value, does **NOT** require it to be an exact match. - + Args: value (Any): data to validate against schema class @@ -112,4 +116,3 @@ def not_like(self, value: Any) -> bool: True when `value` is **NOT** validate against schema. """ return not self.is_valid(value) - \ No newline at end of file diff --git a/src/pytest_schema/types.py b/src/pytest_schema/types.py index cb0df8c..8f368ea 100644 --- a/src/pytest_schema/types.py +++ b/src/pytest_schema/types.py @@ -1,9 +1,11 @@ -from schema import And, Or, Hook, Use, Optional, Regex, Forbidden, Literal +from schema import And, Forbidden, Hook, Literal, Optional, Or, Regex, Use + from pytest_schema.schema import Schema class Enum(Schema): """Simple interface to create Enum like schema.""" + def __init__(self, *value): """ Initialize schema with list or tuple like values. diff --git a/tests/conftest.py b/tests/conftest.py index 9a7f867..694d7d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1 @@ -pytest_plugins = "pytester" \ No newline at end of file +pytest_plugins = "pytester" diff --git a/tests/test_basic.py b/tests/test_basic.py index 511d149..e1bbeef 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,31 +1,20 @@ import pytest -from pytest_schema import schema, SchemaError + +from pytest_schema import SchemaError, schema @pytest.mark.parametrize( "value, basic_schema", [ ( - { - "id": 1, - "username": "helloworld" - }, + {"id": 1, "username": "helloworld"}, { "id": int, "username": str, - } - ), - ( - { - "hello": { - "hey": "world" - } }, - { - "hello": dict - } - ) - ] + ), + ({"hello": {"hey": "world"}}, {"hello": dict}), + ], ) def test_schema_basic_dicts(value, basic_schema): diff --git a/tests/test_standard_types.py b/tests/test_standard_types.py index 7bfd646..874a819 100644 --- a/tests/test_standard_types.py +++ b/tests/test_standard_types.py @@ -1,5 +1,6 @@ import pytest -from pytest_schema import schema, SchemaError + +from pytest_schema import SchemaError, schema @pytest.mark.parametrize( @@ -13,7 +14,7 @@ (("hello", "world"), tuple), (["hello", "world"], list), (lambda k: True, callable), - ] + ], ) def test_schema_standard_types(value, type_schema): @@ -31,7 +32,7 @@ def test_schema_standard_types(value, type_schema): (("hello", "world"), str), (["hello", "world"], str), (lambda k: True, None), - ] + ], ) def test_schema_notequal_standard_types(value, type_schema): @@ -49,9 +50,9 @@ def test_schema_notequal_standard_types(value, type_schema): (("hello", "world"), list), (["hello", "world"], dict), (lambda k: True, bool), - ] + ], ) def test_schema_notequal_standard_types(value, type_schema): with pytest.raises(SchemaError): - assert schema(type_schema) == value \ No newline at end of file + assert schema(type_schema) == value