[cad161]: / tests / utils / test_bindings.py

Download this file

41 lines (29 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pytest
from confit import validate_arguments
from confit.errors import ConfitValidationError
from edsnlp.utils.bindings import BINDING_GETTERS, BINDING_SETTERS, AttributesArg
def test_qualifier_validation():
@validate_arguments
def fn(arg: AttributesArg):
return arg
assert fn("_.negated") == {"_.negated": True}
assert fn(["_.negated", "_.event"]) == {"_.negated": True, "_.event": True}
assert fn({"_.negated": True, "_.event": "DATE"}) == {
"_.negated": True,
"_.event": ["DATE"],
}
callback = lambda x: x # noqa: E731
assert fn(callback) is callback
with pytest.raises(ConfitValidationError):
fn(1)
with pytest.raises(ConfitValidationError):
fn({"_.negated": 1})
def test_bindings():
class custom:
def __init__(self, value):
self.value = value
obj = custom([custom(1), custom(2)])
assert BINDING_GETTERS["value[0].value"](obj) == 1
assert BINDING_GETTERS[("value[0].value", 1)](obj) is True
BINDING_SETTERS[("value[1].value", 3)](obj)
assert obj.value[1].value == 3