Skip to content

Commit f75856b

Browse files
author
Sylvain MARIE
committed
Added test for #53
1 parent af0adfa commit f75856b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

valid8/tests/issues/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
3+
from mini_lambda import x
4+
from valid8 import validate, validate_arg, and_
5+
6+
7+
def test_numpy_bool_is_ok():
8+
""" Tests that numpy booleans can be used as success result by validation functions"""
9+
10+
# a numpy float is not a python float
11+
np_float = np.float_(1.0)
12+
13+
# numpy bools are not python bools
14+
assert np_float > 0 is not True
15+
assert 'numpy' in "%s" % (np_float > 0).__class__
16+
17+
# simple checker
18+
validate('np_float', np_float, min_value=1)
19+
20+
# more complex checker
21+
@validate_arg('a', lambda x: x >= 1)
22+
def foo(a):
23+
return
24+
25+
foo(np_float)
26+
27+
# even more complex checker
28+
@validate_arg('a', and_(x > 0, lambda x: x >= 1))
29+
def foo(a):
30+
return
31+
32+
foo(np_float)

0 commit comments

Comments
 (0)