Skip to content

Commit

Permalink
Added pylint, travis config to run it
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorthu committed May 23, 2018
1 parent 7c3d0aa commit e40a51f
Show file tree
Hide file tree
Showing 7 changed files with 457 additions and 18 deletions.
426 changes: 426 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- "3.3"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install pylint
script:
- pylint openapi
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# that they may be referenced throughout the schema without issue
from . import info, servers, paths, general, schemas, components, security

__all__ = [OpenAPI]
__all__ = ['OpenAPI']
16 changes: 9 additions & 7 deletions openapi/object_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .errors import SpecError
from .errors import SpecError, ReferenceResolutionError

class ObjectBase:
"""
Expand Down Expand Up @@ -46,7 +46,8 @@ def __repr__(self):
"""
Returns a string representation of the parsed object
"""
return str(self.__dict__())
# TODO - why?
return str(self.__dict__()) # pylint: disable=not-callable

def __dict__(self):
"""
Expand Down Expand Up @@ -87,7 +88,7 @@ def _parse_data(self):
are parsed and then an assertion is made that all keys in the
raw_element were accessed - if not, the schema is considered invalid.
"""
raise NotImplemented("You must implement this method in subclasses!")
raise NotImplementedError("You must implement this method in subclasses!")

def _get(self, field, object_types, is_list=False, is_map=False):
"""
Expand Down Expand Up @@ -228,10 +229,11 @@ def get_object_type(cls, typename):
# generate subclass map on first call
setattr(cls, '_subclass_map', {t.__name__: t for t in cls.__subclasses__()})

if typename not in cls._subclass_map:
# TODO - why?
if typename not in cls._subclass_map: # pylint: disable=no-member
raise ValueError('ObjectBase has no subclass {}'.format(typename))

return cls._subclass_map[typename]
return cls._subclass_map[typename] # pylint: disable=no-member

def get_path(self):
"""
Expand Down Expand Up @@ -310,7 +312,7 @@ def _resolve_references(self):
# we found a reference - attempt to resolve it
reference_path = value.ref
if not reference_path.startswith('#/'):
raise ReferenceResolutionError('Invalid reference path {}'.foramt(
raise ReferenceResolutionError('Invalid reference path {}'.format(
reference_path))

reference_path = reference_path.split('/')[1:]
Expand Down Expand Up @@ -406,7 +408,7 @@ def _resolve_references(self):
# we found a reference - attempt to resolve it
reference_path = value.ref
if not reference_path.startswith('#/'):
raise ReferenceResolutionError('Invalid reference path {}'.foramt(
raise ReferenceResolutionError('Invalid reference path {}'.format(
reference_path))

reference_path = reference_path.split('/')[1:]
Expand Down
4 changes: 3 additions & 1 deletion openapi/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def __init__(self, raw_document):
"""
super().__init__([], raw_document, self) # as the document root, we have no path

self._security = {}

# public methods
def authenticte(self, security_scheme, value):
"""
Expand Down Expand Up @@ -51,7 +53,7 @@ def resolve_path(self, path):

for part in path:
if isinstance(node, Map):
if part not in node:
if part not in node: # pylint: disable=unsupported-membership-test
raise ReferenceResolutionError(
'Invalid path {} in Reference'.format(path))
node = node.get(part)
Expand Down
9 changes: 3 additions & 6 deletions openapi/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def request(self, base_url, security={}, data=None, parameters={}):
raise NotImplementedError()
elif security_scheme.type == 'oauth2':
raise NotImplementedError()
elif secutity_scheme.type == 'openIdConnect':
elif security_scheme.type == 'openIdConnect':
raise NotImplementedError()

if self.requestBody:
Expand Down Expand Up @@ -239,7 +239,7 @@ def request(self, base_url, security={}, data=None, parameters={}):
# a generic range should be accepted if one if provided
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#response-object
generic_type = content_type.split('/')[0]+'/*'
expected_media = expected.response.content.get(generic_type, None)
expected_media = expected_response.content.get(generic_type, None)

if expected_media is None:
raise RuntimeError('Unexpected content type {} returned for operation {} '
Expand Down Expand Up @@ -315,12 +315,9 @@ def _parse_data(self):
"""
self.schema = self._get('schema', ['Schema', 'Reference'])
self.example = self._get('example', str)# 'any' type
raw_examples = self._get('examples', list)
self.examples = self._get('examples', ['Reference'], is_map=True)# ['Example','Reference']
self.encoding = self._get('encoding', dict) # Map['Encoding']

if raw_examples is not None:
self.examples = Map(self.path+['examples'], raw_examples, ['Reference'])# ['Example','Reference'])


class Response(ObjectBase):
"""
Expand Down
8 changes: 5 additions & 3 deletions openapi/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def get_type(self):
isinstance(object1, example._schema.get_type()) # true
type(object1) == type(object2) # true
"""
if self._model_type is None:
self._model_type = type(self.path[-1], (Model,), {
if self._model_type is None: # pylint: disable=access-member-before-definition
# this is defined in ObjectBase.__init__ as all slots are
self._model_type = type(self.path[-1], (Model,), { # pylint: disable=attribute-defined-outside-init
'__slots__': self.properties.keys()
})

Expand Down Expand Up @@ -140,7 +141,8 @@ def __repr__(self):
"""
A generic representation of this model
"""
return str(self.__dict__())
# TODO - why?
return str(self.__dict__()) # pylint: disable=not-callable

def __dict__(self):
"""
Expand Down

0 comments on commit e40a51f

Please sign in to comment.