Coverage for tests/test_complex_delc_has_dp.py: 94%

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

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 

21 

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

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

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

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

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

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

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

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