1
- from js_type_converter import js_type_converter
2
- from java_type_converter import java_type_converter
3
1
from model_handler .constant import (
4
2
UNDERSCORE_TO_DOT ,
5
3
JAVA_TYPE_CONVERSION ,
12
10
import time
13
11
import json
14
12
13
+ # We switch to conditional import for the following two imports to avoid unnecessary installations.
14
+ # User doesn't need to setup the tree-sitter packages if they are not running the test for that language.
15
+ # from js_type_converter import js_type_converter
16
+ # from java_type_converter import java_type_converter
17
+
15
18
PYTHON_TYPE_MAPPING = {
16
19
"string" : str ,
17
20
"integer" : int ,
@@ -362,9 +365,19 @@ def simple_function_checker(
362
365
nested_type_converted = None
363
366
364
367
if language == "Java" :
368
+ from java_type_converter import java_type_converter
369
+
365
370
expected_type_converted = JAVA_TYPE_CONVERSION [expected_type_description ]
366
371
367
372
if expected_type_description in JAVA_TYPE_CONVERSION :
373
+ if type (value ) != str :
374
+ result ["valid" ] = False
375
+ result ["error" ].append (
376
+ f"Incorrect type for parameter { repr (param )} . Expected type String, got { type (value ).__name__ } . Parameter value: { repr (value )} ."
377
+ )
378
+ result ["error_type" ] = "type_error:java"
379
+ return result
380
+
368
381
if expected_type_description in NESTED_CONVERSION_TYPE_LIST :
369
382
nested_type = param_details [param ]["items" ]["type" ]
370
383
nested_type_converted = JAVA_TYPE_CONVERSION [nested_type ]
@@ -375,9 +388,19 @@ def simple_function_checker(
375
388
value = java_type_converter (value , expected_type_description )
376
389
377
390
elif language == "JavaScript" :
391
+ from js_type_converter import js_type_converter
392
+
378
393
expected_type_converted = JS_TYPE_CONVERSION [expected_type_description ]
379
394
380
395
if expected_type_description in JS_TYPE_CONVERSION :
396
+ if type (value ) != str :
397
+ result ["valid" ] = False
398
+ result ["error" ].append (
399
+ f"Incorrect type for parameter { repr (param )} . Expected type String, got { type (value ).__name__ } . Parameter value: { repr (value )} ."
400
+ )
401
+ result ["error_type" ] = "type_error:js"
402
+ return result
403
+
381
404
if expected_type_description in NESTED_CONVERSION_TYPE_LIST :
382
405
nested_type = param_details [param ]["items" ]["type" ]
383
406
nested_type_converted = JS_TYPE_CONVERSION [nested_type ]
@@ -945,4 +968,4 @@ def exec_checker(decoded_result: list, func_description: dict, test_category: st
945
968
func_description ["execution_result" ][0 ],
946
969
func_description ["execution_result_type" ][0 ],
947
970
False ,
948
- )
971
+ )
0 commit comments