Coverage for tests/test_real_delc_has_dp.py: 96%

67 statements  

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

1# pylint: disable=W0621,C0116,C0114 

2from unittest import mock 

3import pytest 

4 

5from castep_linter import tests 

6from castep_linter.fortran.fortran_node import WrongNodeError 

7from castep_linter.fortran.parser import get_fortran_parser 

8from castep_linter.scan_files import run_tests_on_code 

9from castep_linter.tests.real_declaration_has_dp import check_real_dp_declaration 

10 

11 

12@pytest.fixture 

13def test_list(): 

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

15 

16 

17@pytest.fixture 

18def parser(): 

19 return get_fortran_parser() 

20 

21def 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 

27def 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") 

34def 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 

40def 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 

45def 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 

51def 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 

57def 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 

63def 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 

69def 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 

75def 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 

81def 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 

87def 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 

93def 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