Coverage for skema/program_analysis/CAST/fortran/tests/test_identifier_cast_fortran.py: 100%
22 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
1from tempfile import TemporaryDirectory
2from pathlib import Path
4from skema.program_analysis.CAST.fortran.ts2cast import TS2CAST
5from skema.program_analysis.CAST2FN.model.cast import (
6 Assignment,
7 Var,
8 Call,
9 Name,
10 CASTLiteralValue,
11 ModelIf,
12 Loop,
13 Operator,
14 ScalarType
15)
17def identifier1():
18 return """
19 program test_identifier
20 integer :: x = 2
21 end program test_identifier
22 """
24def generate_cast(test_file_string):
25 with TemporaryDirectory() as temp:
26 source_path = Path(temp) / "source.f95"
27 source_path.write_text(test_file_string)
28 out_cast = TS2CAST(str(source_path)).out_cast
30 return out_cast[0]
33# Tests to make sure that identifiers are correctly being generated
34def test_identifier1():
35 cast = generate_cast(identifier1())
37 asg_node = cast.nodes[0].body[0]
39 assert isinstance(asg_node, Assignment)
40 assert isinstance(asg_node.left, Var)
41 assert isinstance(asg_node.left.val, Name)
42 assert asg_node.left.val.name == "x"
44 assert isinstance(asg_node.right, CASTLiteralValue)
45 assert asg_node.right.value_type == ScalarType.INTEGER
46 assert asg_node.right.value == '2'