-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsignature_test.py
32 lines (22 loc) · 1006 Bytes
/
signature_test.py
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
import jsonata
import pytest
class TestSignature:
def test_parameters_are_converted_to_arrays(self):
expr = jsonata.Jsonata("$greet(1,null,3)")
expr.register_function("greet", jsonata.Jsonata.JFunction(TestSignature.JFunctionCallable1(), "<a?a?a?a?:s>"))
assert expr.evaluate(None) == "[[1], [null], [3], [None]]"
class JFunctionCallable1(jsonata.Jsonata.JFunctionCallable):
def call(self, input, args):
return str(args)
def test_error(self):
expr = jsonata.Jsonata("$foo()")
expr.register_function("foo", jsonata.Jsonata.JFunction(TestSignature.JFunctionCallable2(), "(sao)"))
# null not allowed
with pytest.raises(jsonata.JException):
expr.evaluate(None)
# boolean not allowed
with pytest.raises(jsonata.JException):
expr.evaluate(True)
class JFunctionCallable2(jsonata.Jsonata.JFunctionCallable):
def call(self, input, args):
return None