Skip to content

Remove use of distutils #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openapi_core/casting/schemas/factories.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from openapi_core.casting.schemas.casters import ArrayCaster
from openapi_core.casting.schemas.casters import CallableSchemaCaster
from openapi_core.casting.schemas.casters import DummyCaster
from openapi_core.casting.schemas.util import forcebool
from openapi_core.util import forcebool


class SchemaCastersFactory:
Expand Down
9 changes: 0 additions & 9 deletions openapi_core/casting/schemas/util.py

This file was deleted.

2 changes: 1 addition & 1 deletion openapi_core/unmarshalling/schemas/unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
from openapi_core.unmarshalling.schemas.exceptions import UnmarshalError
from openapi_core.unmarshalling.schemas.exceptions import ValidateError
from openapi_core.unmarshalling.schemas.formatters import Formatter
from openapi_core.unmarshalling.schemas.util import forcebool
from openapi_core.unmarshalling.schemas.util import format_byte
from openapi_core.unmarshalling.schemas.util import format_date
from openapi_core.unmarshalling.schemas.util import format_number
from openapi_core.unmarshalling.schemas.util import format_uuid
from openapi_core.util import forcebool

log = logging.getLogger(__name__)

Expand Down
8 changes: 0 additions & 8 deletions openapi_core/unmarshalling/schemas/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
import datetime
from base64 import b64decode
from copy import copy
from distutils.util import strtobool
from functools import lru_cache
from uuid import UUID

from openapi_schema_validator import oas30_format_checker


def forcebool(val):
if isinstance(val, str):
val = strtobool(val)

return bool(val)


def format_date(value):
return datetime.datetime.strptime(value, "%Y-%m-%d").date()

Expand Down
14 changes: 14 additions & 0 deletions openapi_core/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""OpenAPI core util module"""


def forcebool(val):
if isinstance(val, str):
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
return True
elif val in ("n", "no", "f", "false", "off", "0"):
return False
else:
raise ValueError(f"invalid truth value {val!r}")

return bool(val)
22 changes: 22 additions & 0 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from openapi_core.util import forcebool


class TestForcebool:
@pytest.mark.parametrize("val", ["y", "yes", "t", "true", "on", "1", True])
def test_true(self, val):
result = forcebool(val)
assert result is True

@pytest.mark.parametrize(
"val", ["n", "no", "f", "false", "off", "0", False]
)
def test_false(self, val):
result = forcebool(val)
assert result is False

@pytest.mark.parametrize("val", ["random", "idontknow", ""])
def test_value_error(self, val):
with pytest.raises(ValueError):
forcebool(val)