pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python-validators/validators/commit/52d51c8315747f5618033bd76d821c01c9f0dd1c

" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-7a1ad343bd40328c.css" /> Added tests for ValidationFailure · python-validators/validators@52d51c8 · GitHub
Skip to content

Commit 52d51c8

Browse files
committed
Added tests for ValidationFailure
1 parent 05671e1 commit 52d51c8

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

tests/test_validation_failure.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import validators
2+
3+
4+
obj_repr = (
5+
"ValidationFailure(func=number_range, "
6+
"args={'max': 5, 'value': 3, 'min': 4})"
7+
)
8+
9+
10+
class TestValidationFailure(object):
11+
def setup_method(self, method):
12+
self.obj = validators.number_range(3, min=4, max=5)
13+
14+
def test_boolean_coerce(self):
15+
assert not bool(self.obj)
16+
assert not self.obj
17+
18+
def test_repr(self):
19+
assert repr(self.obj) == obj_repr
20+
21+
def test_unicode(self):
22+
assert unicode(self.obj) == obj_repr
23+
24+
def test_str(self):
25+
assert str(self.obj) == obj_repr
26+
27+
def test_arguments_as_properties(self):
28+
assert self.obj.value == 3
29+
assert self.obj.min == 4
30+
assert self.obj.max == 5

validators/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .extremes import Min, Max
33
from .ip_address import ipv4, ipv6
44
from .mac_address import mac_address
5-
from .utils import FailedValidation, validator
5+
from .utils import ValidationFailure, validator
66
from .url import url
77
from .uuid import uuid
88

@@ -15,7 +15,7 @@
1515
url,
1616
uuid,
1717
validator,
18-
FailedValidation,
18+
ValidationFailure,
1919
Min,
2020
Max,
2121
)

validators/utils.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@
88
import six
99

1010

11-
class FailedValidation(object):
11+
class ValidationFailure(object):
1212
def __init__(self, func, args):
1313
self.func = func
1414
self.__dict__.update(args)
1515

16+
def __repr__(self):
17+
return u'ValidationFailure(func={func}, args={args})'.format(
18+
func=self.func.__name__,
19+
args=dict(
20+
[(k, v) for (k, v) in self.__dict__.items() if k != 'func']
21+
)
22+
)
23+
24+
def __str__(self):
25+
return repr(self)
26+
27+
def __unicode__(self):
28+
return repr(self)
29+
1630
def __bool__(self):
1731
return False
1832

@@ -39,7 +53,7 @@ def func_args_as_dict(func, args, kwargs):
3953
def validator(func, *args, **kwargs):
4054
value = func(*args, **kwargs)
4155
if not value:
42-
return FailedValidation(
56+
return ValidationFailure(
4357
func, func_args_as_dict(func, args, kwargs)
4458
)
4559
return value

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy