summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Allgaier <mail@spacegaier.de>2020-09-21 12:24:21 +0200
committerAlec Thomas <alec@swapoff.org>2020-09-21 03:38:41 -0700
commitf8775a70cd10dc56775f74978840e4611900cff8 (patch)
tree7d4da0f80b4e7509bcbcc8b2d9cb75c216c05faa
parent9fa00090a489b3d0c28b513aa9d581a0f559005f (diff)
downloadvoluptuous-f8775a70cd10dc56775f74978840e4611900cff8.tar.gz
Fix most important flake8 errors/warnings
-rw-r--r--voluptuous/schema_builder.py2
-rw-r--r--voluptuous/tests/tests.py37
-rw-r--r--voluptuous/validators.py5
3 files changed, 25 insertions, 19 deletions
diff --git a/voluptuous/schema_builder.py b/voluptuous/schema_builder.py
index 84c1738..64da5b2 100644
--- a/voluptuous/schema_builder.py
+++ b/voluptuous/schema_builder.py
@@ -815,7 +815,7 @@ def _compile_scalar(schema):
def validate_callable(path, data):
try:
return schema(data)
- except ValueError as e:
+ except ValueError:
raise er.ValueInvalid('not a valid value', path)
except er.Invalid as e:
e.prepend(path)
diff --git a/voluptuous/tests/tests.py b/voluptuous/tests/tests.py
index 3bf52b4..6172935 100644
--- a/voluptuous/tests/tests.py
+++ b/voluptuous/tests/tests.py
@@ -631,12 +631,12 @@ def test_clamp_inside():
def test_clamp_above():
s = Schema(Clamp(min=1, max=10))
- assert_equal(10, s(12))
+ assert_equal(10, s(12))
def test_clamp_below():
s = Schema(Clamp(min=1, max=10))
- assert_equal(1, s(-3))
+ assert_equal(1, s(-3))
def test_clamp_invalid():
@@ -667,13 +667,13 @@ def test_length_too_short():
def test_length_too_long():
v = ['a', 'b', 'c']
s = Schema(Length(min=0, max=2))
- assert_raises(MultipleInvalid, s, v)
+ assert_raises(MultipleInvalid, s, v)
def test_length_invalid():
v = None
s = Schema(Length(min=0, max=2))
- assert_raises(MultipleInvalid, s, v)
+ assert_raises(MultipleInvalid, s, v)
def test_equal():
@@ -1443,6 +1443,7 @@ def test_any_required_with_subschema():
else:
assert False, "Did not raise Invalid for MultipleInvalid"
+
def test_inclusive():
schema = Schema({
Inclusive('x', 'stuff'): int,
@@ -1452,17 +1453,18 @@ def test_inclusive():
r = schema({})
assert_equal(r, {})
- r = schema({'x':1, 'y':2})
- assert_equal(r, {'x':1, 'y':2})
+ r = schema({'x': 1, 'y': 2})
+ assert_equal(r, {'x': 1, 'y': 2})
try:
- r = schema({'x':1})
+ r = schema({'x': 1})
except MultipleInvalid as e:
assert_equal(str(e),
"some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]")
else:
assert False, "Did not raise Invalid for incomplete Inclusive group"
+
def test_inclusive_defaults():
schema = Schema({
Inclusive('x', 'stuff', default=3): int,
@@ -1470,16 +1472,17 @@ def test_inclusive_defaults():
})
r = schema({})
- assert_equal(r, {'x':3, 'y':4})
+ assert_equal(r, {'x': 3, 'y': 4})
try:
- r = schema({'x':1})
+ r = schema({'x': 1})
except MultipleInvalid as e:
assert_equal(str(e),
"some but not all values in the same group of inclusion 'stuff' @ data[<stuff>]")
else:
assert False, "Did not raise Invalid for incomplete Inclusive group with defaults"
+
def test_exclusive():
schema = Schema({
Exclusive('x', 'stuff'): int,
@@ -1489,17 +1492,18 @@ def test_exclusive():
r = schema({})
assert_equal(r, {})
- r = schema({'x':1})
- assert_equal(r, {'x':1})
+ r = schema({'x': 1})
+ assert_equal(r, {'x': 1})
try:
- r = schema({'x':1, 'y': 2})
+ r = schema({'x': 1, 'y': 2})
except MultipleInvalid as e:
assert_equal(str(e),
"two or more values in the same group of exclusion 'stuff' @ data[<stuff>]")
else:
assert False, "Did not raise Invalid for multiple values in Exclusive group"
+
def test_any_with_discriminant():
schema = Schema({
'implementation': Union({
@@ -1511,15 +1515,16 @@ def test_any_with_discriminant():
}, {
'type': 'C',
'c-value': bool,
- }, discriminant=lambda value, alternatives: filter(lambda v : v['type'] == value['type'], alternatives))
+ }, discriminant=lambda value, alternatives: filter(lambda v: v['type'] == value['type'], alternatives))
})
try:
schema({
'implementation': {
- 'type': 'C',
- 'c-value': None,}
+ 'type': 'C',
+ 'c-value': None
+ }
})
except MultipleInvalid as e:
- assert_equal(str(e),'expected bool for dictionary value @ data[\'implementation\'][\'c-value\']')
+ assert_equal(str(e), 'expected bool for dictionary value @ data[\'implementation\'][\'c-value\']')
else:
assert False, "Did not raise correct Invalid"
diff --git a/voluptuous/validators.py b/voluptuous/validators.py
index ce1567e..21a3a65 100644
--- a/voluptuous/validators.py
+++ b/voluptuous/validators.py
@@ -272,6 +272,7 @@ class Any(_WithSubValidators):
# Convenience alias
Or = Any
+
class Union(_WithSubValidators):
"""Use the first validated value among those selected by discrminant.
@@ -650,7 +651,7 @@ class Clamp(object):
# Objects that lack a partial ordering, e.g. None or strings will raise TypeError
except TypeError:
raise RangeInvalid(
- self.msg or 'invalid value or type (must have a partial ordering)')
+ self.msg or 'invalid value or type (must have a partial ordering)')
def __repr__(self):
return 'Clamp(min=%s, max=%s)' % (self.min, self.max)
@@ -677,7 +678,7 @@ class Length(object):
# Objects that havbe no length e.g. None or strings will raise TypeError
except TypeError:
raise RangeInvalid(
- self.msg or 'invalid value or type')
+ self.msg or 'invalid value or type')
def __repr__(self):
return 'Length(min=%s, max=%s)' % (self.min, self.max)