File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change 11import pytest
2+ from unittest .mock import patch , PropertyMock
23from pytest_splunk_addon .standard_lib .addon_parser .eventtype_parser import (
34 EventTypeParser ,
45)
@@ -35,8 +36,19 @@ def test_get_eventtypes_calls_app_get_config(parser_instance):
3536
3637def test_no_eventtype_config_file (parser_instance ):
3738 parser_instance .app .eventtypes_conf .side_effect = OSError
38- output = [eventtype for eventtype in parser_instance .get_eventtypes () if eventtype ]
39- assert output == [], "eventtypes created when no config file exists"
39+ assert (
40+ parser_instance .eventtypes is None
41+ ), "eventtypes created when no config file exists"
42+
43+
44+ def test_nothing_returned_when_no_tags_config_file (parser ):
45+ with patch .object (
46+ EventTypeParser , "eventtypes" , new_callable = PropertyMock
47+ ) as eventtypes_mock :
48+ eventtypes_mock .return_value = None
49+ parser_instance = parser (EventTypeParser , "eventtypes_conf" , {})
50+ output = [tag for tag in parser_instance .get_eventtypes () if tag ]
51+ assert output == [], "eventtypes returned when no config file exists"
4052
4153
4254@pytest .fixture (scope = "module" )
Original file line number Diff line number Diff line change 11import pytest
2+ from unittest .mock import patch , PropertyMock
23from pytest_splunk_addon .standard_lib .addon_parser .tags_parser import (
34 TagsParser ,
4- unquote ,
55)
66
77
@@ -61,8 +61,15 @@ def test_get_tags_calls_app_get_config(parser_instance):
6161
6262def test_no_tags_config_file (parser_instance ):
6363 parser_instance .app .get_config .side_effect = OSError
64- output = [tag for tag in parser_instance .get_tags () if tag ]
65- assert output == [], "tags created when no config file exists"
64+ assert parser_instance .tags is None , "tags created when no config file exists"
65+
66+
67+ def test_nothing_returned_when_no_tags_config_file (parser ):
68+ with patch .object (TagsParser , "tags" , new_callable = PropertyMock ) as tags_mock :
69+ tags_mock .return_value = None
70+ parser_instance = parser (TagsParser , "get_config" , {})
71+ output = [tag for tag in parser_instance .get_tags () if tag ]
72+ assert output == [], "tags returned when no config file exists"
6673
6774
6875@pytest .fixture (scope = "module" )
You can’t perform that action at this time.
0 commit comments