Coverage for src/castep_linter/tests/real_declaration_has_dp.py: 100%
23 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
1"""Test that all real values are specified by real(kind=dp)"""
3from castep_linter.error_logging import ErrorLogger
4from castep_linter.fortran import ArgType, FType, VariableDeclaration
5from castep_linter.fortran.fortran_node import Fortran, FortranNode, WrongNodeError
6from castep_linter.fortran.identifier import Identifier
7from castep_linter.tests import castep_identifiers
10def check_real_dp_declaration(node: FortranNode, error_log: ErrorLogger) -> None:
11 """Test that all real values are specified by real(kind=dp)"""
13 if not node.is_type(Fortran.VARIABLE_DECLARATION):
14 err = "Expected variable declaration node"
15 raise WrongNodeError(err)
17 var_decl = VariableDeclaration(node)
19 if var_decl.type not in [FType.REAL, FType.COMPLEX]:
20 return
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
28 if arg_value.ftype == Fortran.NUMBER_LITERAL:
29 error_log.add_msg("Error", arg_value, "Numeric kind specifier")
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")
37 elif arg_type is ArgType.POSITION:
38 error_log.add_msg("Info", arg_value, "Kind specified without keyword")