Coverage for skema/program_analysis/tests/test_function_type.py: 100%
28 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1# import json NOTE: json and Path aren't used right now,
2# from pathlib import Path but will be used in the future
3from skema.program_analysis.multi_file_ingester import process_file_system
4from skema.gromet.fn import (
5 GrometFNModuleCollection,
6 FunctionType,
7 ImportType
8)
9import ast
11from skema.program_analysis.CAST.pythonAST import py_ast_to_cast
12from skema.program_analysis.CAST2FN.model.cast import SourceRef
13from skema.program_analysis.CAST2FN import cast
14from skema.program_analysis.CAST2FN.cast import CAST
15from skema.program_analysis.run_ann_cast_pipeline import ann_cast_pipeline
17def function_type_1():
18 return """
19import numpy as np
21x = np.linspace(0, 1, 10)
22"""
24def generate_gromet(test_file_string):
25 # use ast.Parse to get Python AST
26 contents = ast.parse(test_file_string)
28 # use Python to CAST
29 line_count = len(test_file_string.split("\n"))
30 convert = py_ast_to_cast.PyASTToCAST("temp")
31 C = convert.visit(contents, {}, {})
32 C.source_refs = [SourceRef("temp", None, None, 1, line_count)]
33 out_cast = cast.CAST([C], "python")
35 # use AnnCastPipeline to create GroMEt
36 gromet = ann_cast_pipeline(out_cast, gromet=True, to_file=False, from_obj=True)
38 return gromet
40def test_function_type1():
41 exp_gromet = generate_gromet(function_type_1())
43 base_fn = exp_gromet.fn
45 assert len(base_fn.b) == 1
46 assert len(base_fn.bf) == 5
48 assert len(base_fn.pif) == 3
49 assert len(base_fn.pof) == 6
50 assert len(base_fn.wff) == 4
52 assert base_fn.bf[1].function_type == FunctionType.IMPORTED_METHOD and base_fn.bf[1].import_type == ImportType.NATIVE