Coverage for tests/test_real_delc_has_dp.py: 96%

1# pylint: disable=W0621,C0116,C0114

2 from unittest import mock

3 import pytest

4

5 from castep_linter import tests

6 from castep_linter.fortran.fortran_node import WrongNodeError

7 from castep_linter.fortran.parser import get_fortran_parser

8 from castep_linter.scan_files import run_tests_on_code

9 from castep_linter.tests.real_declaration_has_dp import check_real_dp_declaration

10

11

12@pytest.fixture

13 def test_list():

14 return {"variable_declaration": [tests.check_real_dp_declaration]}

15

16

17@pytest.fixture

18 def parser():

19 return get_fortran_parser()

20

21 def test_wrong_node():

22 mock_node = mock.Mock(**{"is_type.return_value": False})

23 err_log = mock.MagicMock()

24 with pytest.raises(WrongNodeError):

25 check_real_dp_declaration(mock_node, err_log)

26

27 def test_real_dp_correct(parser, test_list):

28 code = b"real(kind=dp) :: y"

29 error_log = run_tests_on_code(parser, code, test_list, "filename")

30 assert len(error_log.errors) == 0

31

32

33@pytest.mark.skip(reason="Not current implemented")

34 def test_real_dp_correctb(parser, test_list):

35 code = b"real, kind(dp) :: y"

36 error_log = run_tests_on_code(parser, code, test_list, "filename")

37 assert len(error_log.errors) == 0

38

39

40 def test_real_dp_by_position(parser, test_list):

41 code = b"real(dp) :: y"

42 error_log = run_tests_on_code(parser, code, test_list, "filename")

43 assert len(error_log.errors) == 1

44

45 def test_real_dp_by_d0(parser, test_list):

46 code = b"DOUBLE PRECISION :: y"

47 error_log = run_tests_on_code(parser, code, test_list, "filename")

48 assert len(error_log.errors) == 0

49

50

51 def test_real_dp_no_kind(parser, test_list):

52 code = b"real, intent(in) :: y"

53 error_log = run_tests_on_code(parser, code, test_list, "filename")

54 assert len(error_log.errors) == 1

55

56

57 def test_real_integer_kind_with_keyword(parser, test_list):

58 code = b"real(kind=8) :: y"

59 error_log = run_tests_on_code(parser, code, test_list, "filename")

60 assert len(error_log.errors) == 1

61

62

63 def test_real_integer_kind_without_keyword(parser, test_list):

64 code = b"real(8) :: y"

65 error_log = run_tests_on_code(parser, code, test_list, "filename")

66 assert len(error_log.errors) == 1

67

68

69 def test_real_bad_var_kind_without_keyword(parser, test_list):

70 code = b"real(x) :: y"

71 error_log = run_tests_on_code(parser, code, test_list, "filename")

72 assert len(error_log.errors) == 1

73

74

75 def test_real_bad_var_kind_with_keyword(parser, test_list):

76 code = b"real(kind=x) :: y"

77 error_log = run_tests_on_code(parser, code, test_list, "filename")

78 assert len(error_log.errors) == 1

79

80

81 def test_real_with_other_keyword(parser, test_list):

82 code = b"real(lemon=x) :: y"

83 error_log = run_tests_on_code(parser, code, test_list, "filename")

84 assert len(error_log.errors) == 1

85

86

87 def test_integer_declaration(parser, test_list):

88 code = b"integer :: y"

89 error_log = run_tests_on_code(parser, code, test_list, "filename")

90 assert len(error_log.errors) == 0

91

92

93 def test_derived_type_declaration(parser, test_list):

94 code = b"type(z) :: y"

95 error_log = run_tests_on_code(parser, code, test_list, "filename")

96 assert len(error_log.errors) == 0