Skip to content

Commit

Permalink
Flake8 errors resolved; Tox now running successfully
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmakkar08 committed Apr 24, 2016
1 parent eb0b329 commit fdbf8ce
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -22,7 +22,7 @@ commands =

[testenv:flake8]
deps = flake8
commands = flake8 setup.py voluptuous
commands = flake8 --doctests setup.py voluptuous

[testenv:py26]
basepython = python2.6
Expand Down
2 changes: 2 additions & 0 deletions voluptuous/__init__.py
@@ -1,3 +1,5 @@
# flake8: noqa

try:
from schema_builder import *
from validators import *
Expand Down
25 changes: 12 additions & 13 deletions voluptuous/schema_builder.py
Expand Up @@ -15,11 +15,14 @@
unicode = str
basestring = str
ifilter = filter
iteritems = lambda d: d.items()

def iteritems(d):
return d.items()
else:
from itertools import ifilter

iteritems = lambda d: d.iteritems()
def iteritems(d):
return d.iteritems()

"""Schema validation for Python data structures.
Expand Down Expand Up @@ -102,6 +105,7 @@
ALLOW_EXTRA = 1 # extra keys not in schema will be included in output
REMOVE_EXTRA = 2 # extra keys not in schema will be excluded from output


class Undefined(object):
def __nonzero__(self):
return False
Expand All @@ -118,6 +122,7 @@ def default_factory(value):
return value
return lambda: value


@contextmanager
def raises(exc, msg=None, regex=None):
try:
Expand Down Expand Up @@ -216,15 +221,11 @@ def _compile_mapping(self, schema, invalid_msg=None):
invalid_msg = invalid_msg or 'mapping value'

# Keys that may be required
all_required_keys = set(key for key in schema
if key is not Extra
and ((self.required and not isinstance(key, (Optional, Remove)))
or isinstance(key, Required)))
all_required_keys = set(key for key in schema if key is not Extra and (
(self.required and not isinstance(key, (Optional, Remove))) or isinstance(key, Required)))

# Keys that may have defaults
all_default_keys = set(key for key in schema
if isinstance(key, Required)
or isinstance(key, Optional))
all_default_keys = set(key for key in schema if isinstance(key, Required) or isinstance(key, Optional))

_compiled_schema = {}
for skey, svalue in iteritems(schema):
Expand Down Expand Up @@ -344,8 +345,7 @@ def _compile_object(self, schema):
schema, invalid_msg='object value')

def validate_object(path, data):
if (schema.cls is not UNDEFINED
and not isinstance(data, schema.cls)):
if schema.cls is not UNDEFINED and not isinstance(data, schema.cls):
raise er.ObjectInvalid('expected a {0!r}'.format(schema.cls), path)
iterable = _iterate_object(data)
iterable = ifilter(lambda item: item[1] is not None, iterable)
Expand Down Expand Up @@ -778,8 +778,7 @@ def __repr__(self):
return self.__str__()


## Markers.py

# Markers.py


class Marker(object):
Expand Down
4 changes: 2 additions & 2 deletions voluptuous/util.py
@@ -1,10 +1,10 @@
try:
from error import LiteralInvalid, TypeInvalid, Invalid
from schema_builder import *
from schema_builder import Schema, default_factory, raises
import validators
except ImportError:
from .error import LiteralInvalid, TypeInvalid, Invalid
from .schema_builder import *
from .schema_builder import Schema, default_factory, raises
from . import validators

__author__ = 'tusharmakkar08'
Expand Down
12 changes: 9 additions & 3 deletions voluptuous/validators.py
Expand Up @@ -7,10 +7,16 @@

try:
from schema_builder import Schema, raises, message
from error import *
from error import (MultipleInvalid, CoerceInvalid, TrueInvalid, FalseInvalid, BooleanInvalid, Invalid, AnyInvalid,
AllInvalid, MatchInvalid, UrlInvalid, EmailInvalid, FileInvalid, DirInvalid, RangeInvalid,
PathInvalid, ExactSequenceInvalid, LengthInvalid, DatetimeInvalid, InInvalid, TypeInvalid,
NotInInvalid)
except ImportError:
from .schema_builder import Schema, raises, message
from .error import *
from .error import (MultipleInvalid, CoerceInvalid, TrueInvalid, FalseInvalid, BooleanInvalid, Invalid, AnyInvalid,
AllInvalid, MatchInvalid, UrlInvalid, EmailInvalid, FileInvalid, DirInvalid, RangeInvalid,
PathInvalid, ExactSequenceInvalid, LengthInvalid, DatetimeInvalid, InInvalid, TypeInvalid,
NotInInvalid)


if sys.version_info >= (3,):
Expand Down Expand Up @@ -614,7 +620,7 @@ class ExactSequence(object):
:param kwargs: All other keyword arguments are passed to the sub-Schema
constructors.
>>> from voluptuous import *
>>> from voluptuous import Schema, ExactSequence
>>> validate = Schema(ExactSequence([str, int, list, list]))
>>> validate(['hourly_report', 10, [], []])
['hourly_report', 10, [], []]
Expand Down

0 comments on commit fdbf8ce

Please sign in to comment.