Coverage for skema/program_analysis/tests/test_identifier.py: 100%

17 statements  

« 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.CAST.python.ts2cast import TS2CAST 

4from skema.program_analysis.CAST2FN.model.cast import ( 

5 Assignment, 

6 Var, 

7 Call, 

8 Name, 

9 CASTLiteralValue, 

10 ModelIf, 

11 Loop, 

12 Operator 

13) 

14 

15def identifier1(): 

16 return """x = 2""" 

17 

18def generate_cast(test_file_string): 

19 # use Python to CAST 

20 out_cast = TS2CAST(test_file_string, from_file=False).out_cast 

21 

22 return out_cast 

23 

24 

25# Tests to make sure that identifiers are correctly being generated 

26def test_identifier1(): 

27 cast = generate_cast(identifier1()) 

28 

29 asg_node = cast.nodes[0].body[0] 

30 

31 assert isinstance(asg_node, Assignment) 

32 assert isinstance(asg_node.left, Var) 

33 assert isinstance(asg_node.left.val, Name) 

34 assert asg_node.left.val.name == "x" 

35 

36 assert isinstance(asg_node.right, CASTLiteralValue) 

37 assert asg_node.right.value_type == "Integer" 

38 assert asg_node.right.value == '2' 

39