Coverage for test/tests/unit/test_item.py: 52.50%

1"""

2 tests call.py

3"""

4# mypy: ignore-errors

5# pylint: disable=redefined-outer-name

6 from unittest.mock import (

7 Mock,

8 patch,

9)

10

11 import pytest

12

13 from pytest_vulture import VultureError

14 from pytest_vulture.item import VultureItem

15

16

17@pytest.fixture

18 def mocker(monkeypatch):

19 """

20 Create a tmp dir

21 """

22 monkeypatch.setattr(

23 pytest.Item,

24 "__init__",

25 lambda *_, **_1: 1

26 )

27 monkeypatch.setattr(

28 pytest.File,

29 "__init__",

30 lambda *_, **_1: 1

31 ) # pragma: no cover

32 VultureItem.fspath = "path/test.py"

33 item = VultureItem.from_parent(

34 Mock(), fspath=Mock()

35 )

36 item.session = Mock()

37 return item

38

39

40@patch("pytest_vulture.item.pytest.File.__init__")

41@patch("pytest_vulture.item.pytest.Item.__init__")

42 class TestExportLogstashSyslogFactory:

43 """

44 Tests ExportLogstashSyslogFactory

45 """

46 __caller: VultureItem

47

48 @pytest.fixture(autouse=True)

49 def mock_response(self, mocker):

50 """

51 Get the mocked class

52 """

53 self.__caller = mocker

54

55 def test_reportinfo(self, *_):

56 """

57 Tests VultureCall.reportinfo

58 """

59 _, value, _ = self.__caller.reportinfo()

60 assert value == -1

61

62 def test_runtest(self, *_):

63 """

64 Tests VultureCall.runtest

65 """

66 self.__caller.session.vulture.check_error.return_value = "", ""

67 self.__caller.runtest()

68 self.__caller.session.vulture.check_error.return_value = "message", ""

69 with pytest.raises(VultureError):

70 self.__caller.runtest()

71

72 @patch("pytest_vulture.item.pytest.Item.repr_failure")

73 def test_repr_failure(self, repr_failure, *_):

74 """

75 Tests VultureCall.repr_failure

76 """

77 self.__caller.session.vulture.check_error.return_value = "", ""

78 exc_info = Mock()

79 exc_info.value.message = "1"

80 exc_info.errisinstance.return_value = True

81 assert self.__caller.repr_failure(exc_info) == "1"

82 assert repr_failure.called is False

83

84 exc_info.errisinstance.return_value = False

85 self.__caller.repr_failure(exc_info)

86 assert repr_failure.called is True