Coverage for skema/program_analysis/tests/test_import_method.py: 42%
31 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
3import pytest
4from skema.program_analysis.multi_file_ingester import process_file_system
5from skema.gromet.fn import (
6 GrometFNModuleCollection,
7 FunctionType,
8 ImportType
9)
10import ast
12from skema.program_analysis.CAST.pythonAST import py_ast_to_cast
13from skema.program_analysis.CAST2FN.model.cast import SourceRef
14from skema.program_analysis.CAST2FN import cast
15from skema.program_analysis.CAST2FN.cast import CAST
16from skema.program_analysis.run_ann_cast_pipeline import ann_cast_pipeline
18def import_method1():
19 return """
20import plotly.express as px
21x = 10
23ax = plt.subplots(1,1,10)
24ax.plot(x, x)
25"""
27def generate_gromet(test_file_string):
28 # use ast.Parse to get Python AST
29 contents = ast.parse(test_file_string)
31 # use Python to CAST
32 line_count = len(test_file_string.split("\n"))
33 convert = py_ast_to_cast.PyASTToCAST("temp")
34 C = convert.visit(contents, {}, {})
35 C.source_refs = [SourceRef("temp", None, None, 1, line_count)]
36 out_cast = cast.CAST([C], "python")
38 # use AnnCastPipeline to create GroMEt
39 gromet = ann_cast_pipeline(out_cast, gromet=True, to_file=False, from_obj=True)
41 return gromet
43@pytest.mark.skip(reason="Changes to attribute gromet generation requires re-writing of this test")
44def test_import1():
45 exp_gromet = generate_gromet(import_method1())
47 base_fn = exp_gromet.fn
49 assert len(base_fn.b) == 1
50 assert len(base_fn.bf) == 6
52 assert len(base_fn.pif) == 5
53 assert len(base_fn.pof) == 6
54 assert len(base_fn.wff) == 4
56 assert base_fn.bf[1].function_type == FunctionType.IMPORTED_METHOD and base_fn.bf[1].import_type == ImportType.OTHER
57 assert base_fn.bf[5].function_type == FunctionType.IMPORTED_METHOD and base_fn.bf[5].import_type == ImportType.OTHER