Coverage for src/castep_linter/tests/complex_has_dp.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-23 18:07 +0000

1"""Test that a call of complex(x) has a dp""" 

2from castep_linter.error_logging import ErrorLogger 

3from castep_linter.fortran import CallExpression 

4from castep_linter.fortran.fortran_node import Fortran, FortranNode, WrongNodeError 

5from castep_linter.tests import castep_identifiers 

6 

7 

8def check_complex_has_dp(node: FortranNode, error_log: ErrorLogger) -> None: 

9 """Test that a call of complex(x) has a dp""" 

10 

11 if not node.is_type(Fortran.CALL_EXPRESSION): 

12 err = "Expected variable declaration node" 

13 raise WrongNodeError(err) 

14 

15 call_expr = CallExpression(node) 

16 

17 if call_expr.name == castep_identifiers.CMPLX: 

18 try: 

19 _, arg_value = call_expr.get_arg(position=3, keyword=castep_identifiers.KIND) 

20 except KeyError: 

21 error_log.add_msg("Error", node, "No kind specifier in complex intrinsic") 

22 return 

23 

24 if arg_value.raw.lower() not in castep_identifiers.DP_ALL: 

25 error_log.add_msg("Error", node, "Invalid kind specifier in complex intrinsic")