Skip to content

attr errors hashable fix #143

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 18, 2019
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
6 changes: 3 additions & 3 deletions openapi_core/schema/content/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIContentError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class MimeTypeNotFound(OpenAPIContentError):
mimetype = attr.ib()
availableMimetypes = attr.ib()
Expand Down
2 changes: 1 addition & 1 deletion openapi_core/schema/content/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def __getitem__(self, mimetype):
if fnmatch.fnmatch(mimetype, key):
return value

raise MimeTypeNotFound(mimetype, self.keys())
raise MimeTypeNotFound(mimetype, list(self.keys()))
10 changes: 6 additions & 4 deletions openapi_core/schema/media_types/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIMediaTypeError(OpenAPIMappingError):
pass

@attr.s

@attr.s(hash=True)
class InvalidMediaTypeValue(OpenAPIMediaTypeError):
original_exception = attr.ib()

def __str__(self):
return "Mimetype invalid: {0}".format(self.original_exception)

@attr.s

@attr.s(hash=True)
class InvalidContentType(OpenAPIMediaTypeError):
mimetype = attr.ib()

Expand Down
6 changes: 3 additions & 3 deletions openapi_core/schema/operations/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIOperationError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class InvalidOperation(OpenAPIOperationError):
path_pattern = attr.ib()
http_method = attr.ib()
Expand Down
12 changes: 6 additions & 6 deletions openapi_core/schema/parameters/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIParameterError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class MissingParameter(OpenAPIParameterError):
name = attr.ib()

def __str__(self):
return "Missing parameter (without default value): {0}".format(self.name)


@attr.s
@attr.s(hash=True)
class MissingRequiredParameter(OpenAPIParameterError):
name = attr.ib()

def __str__(self):
return "Missing required parameter: {0}".format(self.name)


@attr.s
@attr.s(hash=True)
class EmptyParameterValue(OpenAPIParameterError):
name = attr.ib()

def __str__(self):
return "Value of parameter cannot be empty: {0}".format(self.name)


@attr.s
@attr.s(hash=True)
class InvalidParameterValue(OpenAPIParameterError):
name = attr.ib()
original_exception = attr.ib()
Expand Down
6 changes: 3 additions & 3 deletions openapi_core/schema/request_bodies/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIRequestBodyError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class MissingRequestBody(OpenAPIRequestBodyError):
request = attr.ib()

Expand Down
8 changes: 4 additions & 4 deletions openapi_core/schema/responses/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIResponseError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class InvalidResponse(OpenAPIResponseError):
http_status = attr.ib()
responses = attr.ib()
Expand All @@ -16,7 +16,7 @@ def __str__(self):
return "Unknown response http status: {0}".format(str(self.http_status))


@attr.s
@attr.s(hash=True)
class MissingResponseContent(OpenAPIResponseError):
response = attr.ib()

Expand Down
28 changes: 15 additions & 13 deletions openapi_core/schema/schemas/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPISchemaError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class NoValidSchema(OpenAPISchemaError):
value = attr.ib()

def __str__(self):
return "No valid schema found for value: {0}".format(self.value)


@attr.s
@attr.s(hash=True)
class UndefinedItemsSchema(OpenAPISchemaError):
type = attr.ib()

def __str__(self):
return "Null value for schema type {0}".format(self.type)


@attr.s
@attr.s(hash=True)
class InvalidSchemaValue(OpenAPISchemaError):
msg = attr.ib()
value = attr.ib()
Expand All @@ -32,58 +32,60 @@ class InvalidSchemaValue(OpenAPISchemaError):
def __str__(self):
return self.msg.format(value=self.value, type=self.type)

@attr.s

@attr.s(hash=True)
class InvalidCustomFormatSchemaValue(InvalidSchemaValue):
original_exception = attr.ib()

def __str__(self):
return self.msg.format(value=self.value, type=self.type, exception=self.original_exception)


@attr.s
@attr.s(hash=True)
class UndefinedSchemaProperty(OpenAPISchemaError):
extra_props = attr.ib()

def __str__(self):
return "Extra unexpected properties found in schema: {0}".format(self.extra_props)

@attr.s

@attr.s(hash=True)
class InvalidSchemaProperty(OpenAPISchemaError):
property_name = attr.ib()
original_exception = attr.ib()

def __str__(self):
return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception)

@attr.s

@attr.s(hash=True)
class MissingSchemaProperty(OpenAPISchemaError):
property_name = attr.ib()

def __str__(self):
return "Missing schema property: {0}".format(self.property_name)


@attr.s
@attr.s(hash=True)
class NoOneOfSchema(OpenAPISchemaError):
type = attr.ib()

def __str__(self):
return "Exactly one valid schema type {0} should be valid, None found.".format(self.type)


@attr.s
@attr.s(hash=True)
class MultipleOneOfSchema(OpenAPISchemaError):
type = attr.ib()

def __str__(self):
return "Exactly one schema type {0} should be valid, more than one found".format(self.type)


class UnmarshallerError(Exception):
class UnmarshallerError(OpenAPIMappingError):
pass


@attr.s
class UnmarshallerStrictTypeError(UnmarshallerError):
value = attr.ib()
types = attr.ib()
Expand Down
6 changes: 3 additions & 3 deletions openapi_core/schema/servers/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from openapi_core.schema.exceptions import OpenAPIMappingError

import attr

from openapi_core.schema.exceptions import OpenAPIMappingError


class OpenAPIServerError(OpenAPIMappingError):
pass


@attr.s
@attr.s(hash=True)
class InvalidServer(OpenAPIServerError):
full_url_pattern = attr.ib()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/schema/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ def link_factory(request_body, server):
@pytest.mark.parametrize("request_body", request_body_list)
def test_iteritems(self, link_factory, request_body, server):
link = link_factory(request_body, server)
for par_name in link.parameters.keys():
for par_name in link.parameters:
assert link[par_name] == link.parameters[par_name]
2 changes: 1 addition & 1 deletion tests/unit/schema/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def operation(self):
return Operation('get', '/path', {}, parameters=parameters)

def test_iteritems(self, operation):
for name in operation.parameters.keys():
for name in operation.parameters:
assert operation[name] == operation.parameters[name]


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/schema/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def path(self):

@property
def test_iteritems(self, path):
for http_method in path.operations.keys():
for http_method in path.operations:
assert path[http_method] ==\
path.operations[http_method]
2 changes: 1 addition & 1 deletion tests/unit/schema/test_request_bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ def request_body(self):

@property
def test_iteritems(self, request_body):
for mimetype in request_body.content.keys():
for mimetype in request_body.content:
assert request_body[mimetype] ==\
request_body.content[mimetype]
2 changes: 1 addition & 1 deletion tests/unit/schema/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def schema(self):

@property
def test_valid(self, schema):
for name in schema.properties.keys():
for name in schema.properties:
assert schema[name] == schema.properties[name]


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/schema/test_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def spec(self, path1, path2):
return Spec(servers, paths)

def test_iteritems(self, spec):
for path_name in spec.paths.keys():
for path_name in spec.paths:
assert spec[path_name] ==\
spec.paths[path_name]

Expand Down