Skip to content

Commit 8d1165d

Browse files
author
David Noble
committed
Fixed two bugs:
+ tests/searchcommands are now executable + tests/searchcommands/test_search_command responds to new error handling Signed-off-by: David Noble <dnoble@splunk.com>
1 parent 17c5fdb commit 8d1165d

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

tests/searchcommands/test_decorators.py

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,7 @@ def test_builtin_options(self):
183183

184184
return
185185

186-
_package_directory = os.path.dirname(__file__)
186+
_package_directory = os.path.dirname(__file__)
187+
188+
if __name__ == "__main__":
189+
unittest.main()

tests/searchcommands/test_examples.py

100644100755
File mode changed.

tests/searchcommands/test_search_command.py

100644100755
Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,18 @@ def test_process(self):
5454
# We support dynamic configuration, not static
5555

5656
expected = \
57-
'error_message=Command search appears to be statically configured and static configuration is unsupported by splunklib.searchcommands. Please ensure that default/commands.conf contains this stanza: [search] | filename = foo.py | supports_getinfo = true | supports_rawargs = true | outputheader = true\r\n' \
57+
'\r\n' \
58+
'ERROR,__mv_ERROR' \
59+
'\r\n' \
60+
'Command search appears to be statically configured and static configuration is unsupported by splunklib.searchcommands. Please ensure that default/commands.conf contains this stanza: [search] | filename = foo.py | supports_getinfo = true | supports_rawargs = true | outputheader = true,' \
5861
'\r\n'
5962

6063
command = SearchCommand()
6164
result = StringIO()
62-
command.process(['foo.py'], output_file=result)
65+
66+
self.assertRaises(
67+
SystemExit, command.process, ['foo.py'], output_file=result)
68+
6369
result.reset()
6470
observed = result.read()
6571
self.assertEqual(expected, observed)
@@ -88,7 +94,8 @@ def test_process(self):
8894

8995
command = SearchCommand()
9096
result = StringIO()
91-
command.process(['foo.py', '__GETINFO__', 'undefined_option=value'], output_file=result)
97+
98+
self.assertRaises(SystemExit, command.process, ['foo.py', '__GETINFO__', 'undefined_option=value'], output_file=result)
9299
result.reset()
93100
observed = result.read()
94101
self.assertEqual(expected, observed)
@@ -97,8 +104,9 @@ def test_process(self):
97104
# errors, if invoked to execute
98105

99106
expected = \
100-
'error_message=Unrecognized option: undefined_option = value\r\n' \
101-
'\r\n'
107+
'\r\n' \
108+
'ERROR,__mv_ERROR\r\n' \
109+
'Unrecognized option: undefined_option = value,\r\n'
102110

103111
command = SearchCommand()
104112
result = StringIO()
@@ -118,7 +126,9 @@ def test_process(self):
118126
# Command.process should exit on processing exceptions
119127

120128
expected = \
121-
''
129+
'\r\n' \
130+
'ERROR,__mv_ERROR\r\n' \
131+
'\'NoneType\' object is not iterable,\r\n'
122132

123133
command = SearchCommand()
124134
result = StringIO()
@@ -175,4 +185,7 @@ def test_process(self):
175185

176186
return
177187

178-
_package_directory = os.path.dirname(__file__)
188+
_package_directory = os.path.dirname(__file__)
189+
190+
if __name__ == "__main__":
191+
unittest.main()

tests/searchcommands/test_search_command_internals.py

100644100755
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,7 @@ def test_messages_header(self):
332332

333333
return
334334

335-
_package_path = os.path.dirname(__file__)
335+
_package_path = os.path.dirname(__file__)
336+
337+
if __name__ == "__main__":
338+
unittest.main()

tests/searchcommands/test_validators.py

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ def test_file(self):
9696
self.assertRaises(ValueError, validator, path)
9797

9898
return
99+
100+
if __name__ == "__main__":
101+
unittest.main()

0 commit comments

Comments
 (0)