1
1
import pytest
2
+ from typing import Any
2
3
from neo4j_graphrag .tool import (
3
4
StringParameter ,
4
5
IntegerParameter ,
12
13
)
13
14
14
15
15
- def test_string_parameter ():
16
+ def test_string_parameter () -> None :
16
17
param = StringParameter (description = "A string" , required = True , enum = ["a" , "b" ])
17
18
assert param .description == "A string"
18
19
assert param .required is True
@@ -22,30 +23,30 @@ def test_string_parameter():
22
23
assert d ["enum" ] == ["a" , "b" ]
23
24
24
25
25
- def test_integer_parameter ():
26
+ def test_integer_parameter () -> None :
26
27
param = IntegerParameter (description = "An int" , minimum = 0 , maximum = 10 )
27
28
d = param .model_dump_tool ()
28
29
assert d ["type" ] == ParameterType .INTEGER
29
30
assert d ["minimum" ] == 0
30
31
assert d ["maximum" ] == 10
31
32
32
33
33
- def test_number_parameter ():
34
+ def test_number_parameter () -> None :
34
35
param = NumberParameter (description = "A number" , minimum = 1.5 , maximum = 3.5 )
35
36
d = param .model_dump_tool ()
36
37
assert d ["type" ] == ParameterType .NUMBER
37
38
assert d ["minimum" ] == 1.5
38
39
assert d ["maximum" ] == 3.5
39
40
40
41
41
- def test_boolean_parameter ():
42
+ def test_boolean_parameter () -> None :
42
43
param = BooleanParameter (description = "A bool" )
43
44
d = param .model_dump_tool ()
44
45
assert d ["type" ] == ParameterType .BOOLEAN
45
46
assert d ["description" ] == "A bool"
46
47
47
48
48
- def test_array_parameter_and_validation ():
49
+ def test_array_parameter_and_validation () -> None :
49
50
arr_param = ArrayParameter (
50
51
description = "An array" ,
51
52
items = StringParameter (description = "str" ),
@@ -61,17 +62,17 @@ def test_array_parameter_and_validation():
61
62
# Test items as dict
62
63
arr_param2 = ArrayParameter (
63
64
description = "Arr with dict" ,
64
- items = {"type" : "string" , "description" : "str" },
65
+ items = {"type" : "string" , "description" : "str" }, # type: ignore
65
66
)
66
- arr_param2 = arr_param2 .validate_items ()
67
67
assert isinstance (arr_param2 .items , StringParameter )
68
68
69
69
# Test error on invalid items
70
70
with pytest .raises (ValueError ):
71
- ArrayParameter (description = "bad" , items = 123 ).validate_items ()
71
+ # Use type: ignore to bypass type checking for this intentional error case
72
+ ArrayParameter (description = "bad" , items = 123 ).validate_items () # type: ignore
72
73
73
74
74
- def test_object_parameter_and_validation ():
75
+ def test_object_parameter_and_validation () -> None :
75
76
obj_param = ObjectParameter (
76
77
description = "Obj" ,
77
78
properties = {
@@ -91,20 +92,21 @@ def test_object_parameter_and_validation():
91
92
obj_param2 = ObjectParameter (
92
93
description = "Obj2" ,
93
94
properties = {
94
- "foo" : {"type" : "string" , "description" : "foo" },
95
+ "foo" : {"type" : "string" , "description" : "foo" }, # type: ignore
95
96
},
96
97
)
97
- obj_param2 = obj_param2 .validate_properties ()
98
98
assert isinstance (obj_param2 .properties ["foo" ], StringParameter )
99
99
100
100
# Test error on invalid property
101
101
with pytest .raises (ValueError ):
102
+ # Use type: ignore to bypass type checking for this intentional error case
102
103
ObjectParameter (
103
- description = "bad" , properties = {"foo" : 123 }
104
+ description = "bad" ,
105
+ properties = {"foo" : 123 }, # type: ignore
104
106
).validate_properties ()
105
107
106
108
107
- def test_from_dict ():
109
+ def test_from_dict () -> None :
108
110
d = {"type" : ParameterType .STRING , "description" : "desc" }
109
111
param = ToolParameter .from_dict (d )
110
112
assert isinstance (param , StringParameter )
@@ -137,8 +139,8 @@ def test_from_dict():
137
139
ToolParameter .from_dict ({"description" : "no type" })
138
140
139
141
140
- def test_tool_class ():
141
- def dummy_func (query , ** kwargs ) :
142
+ def test_tool_class () -> None :
143
+ def dummy_func (query : str , ** kwargs : Any ) -> dict [ str , Any ] :
142
144
return kwargs
143
145
144
146
params = ObjectParameter (
0 commit comments