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

1"""Test that all real values are specified by real(kind=dp)"""

2

3 from castep_linter.error_logging import ErrorLogger

4 from castep_linter.fortran import ArgType, FType, VariableDeclaration

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

6 from castep_linter.fortran.identifier import Identifier

7 from castep_linter.tests import castep_identifiers

8

9

10 def check_real_dp_declaration(node: FortranNode, error_log: ErrorLogger) -> None:

11 """Test that all real values are specified by real(kind=dp)"""

12

13 if not node.is_type(Fortran.VARIABLE_DECLARATION):

14 err = "Expected variable declaration node"

15 raise WrongNodeError(err)

16

17 var_decl = VariableDeclaration(node)

18

19 if var_decl.type not in [FType.REAL, FType.COMPLEX]:

20 return

21

22 try:

23 arg_type, arg_value = var_decl.get_arg(position=1, keyword=Identifier("kind"))

24 except KeyError:

25 error_log.add_msg("Error", node, "No kind specifier")

26 return

27

28 if arg_value.ftype == Fortran.NUMBER_LITERAL:

29 error_log.add_msg("Error", arg_value, "Numeric kind specifier")

30

31 elif (

32 arg_value.ftype == Fortran.IDENTIFIER

33 and Identifier.from_node(arg_value) not in castep_identifiers.DP_ALL

34 ):

35 error_log.add_msg("Warning", arg_value, "Invalid kind specifier")

36

37 elif arg_type is ArgType.POSITION:

38 error_log.add_msg("Info", arg_value, "Kind specified without keyword")