Coverage for tests/test_complex_delc_has_dp.py: 94%

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.complex_has_dp import check_complex_has_dp

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

22 def test_wrong_node():

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

24 err_log = mock.MagicMock()

25 with pytest.raises(WrongNodeError):

26 check_complex_has_dp(mock_node, err_log)

27

28

29 def test_complex_dp_correct(parser, test_list):

30 code = b"complex(kind=dp) :: y"

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

32 assert len(error_log.errors) == 0

33

34

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

36 def test_complex_dp_correctb(parser, test_list):

37 code = b"complex, kind(dp) :: y"

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

39 assert len(error_log.errors) == 0

40

41

42 def test_complex_dp_no_kind(parser, test_list):

43 code = b"complex, intent(in) :: y"

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

45 assert len(error_log.errors) == 1

46

47

48 def test_complex_integer_kind_with_keyword(parser, test_list):

49 code = b"complex(kind=8) :: y"

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

51 assert len(error_log.errors) == 1

52

53

54 def test_complex_integer_kind_without_keyword(parser, test_list):

55 code = b"complex(8) :: y"

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

57 assert len(error_log.errors) == 1

58

59

60 def test_complex_bad_var_kind_without_keyword(parser, test_list):

61 code = b"complex(x) :: y"

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

63 assert len(error_log.errors) == 1

64

65

66 def test_complex_bad_var_kind_with_keyword(parser, test_list):

67 code = b"complex(kind=x) :: y"

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

69 assert len(error_log.errors) == 1