Skip to content

Commit f8e3bce

Browse files
author
Sylvain MARIE
committed
Added doctest for validate
1 parent de2b2ad commit f8e3bce

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

valid8/entry_points_inline.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ def validate(name, # type: str
160160
default and can be set to strict by setting `min_strict`, resp. `max_strict`, to `True`
161161
* if `min_len` (resp. `max_len`) is provided, `len(value)` should be greater than it. Comparison is not strict.
162162
163+
Examples:
164+
165+
>>> import sys, pytest
166+
>>> if sys.version_info < (3, 0): pytest.skip('doctest skipped in python 2')
167+
168+
>>> from valid8 import validate
169+
>>> surf = -1
170+
>>> validate('surface', surf, instance_of=int, min_value=0)
171+
Traceback (most recent call last):
172+
...
173+
valid8.entry_points.ValidationError[ValueError]: Error validating [surface=-1]. TooSmall: x >= 0 does not hold
174+
for x=-1. Wrong value: -1.
175+
163176
:param name: the applicative name of the checked value, that will be used in error messages
164177
:param value: the value to check
165178
:param enforce_not_none: boolean, default True. Whether to enforce that `value` is not None.

0 commit comments

Comments
 (0)