Skip to content

Commit 8c3517b

Browse files
author
David Noble
committed
Improved TestSearchCommandsApp.test_command_parser
1 parent 37237d4 commit 8c3517b

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

examples/saved_searches.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
raise Exception("Add the SDK repository to your PYTHONPATH to run the examples "
2828
"(e.g., export PYTHONPATH=~/splunk-sdk-python.")
2929

30+
3031
def main():
3132
opts = parse(sys.argv[1:], {}, ".splunkrc")
3233
service = connect(**opts.kwargs)

tests/test_searchcommands_app.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ def test_command_parser(self):
217217
encoder = JSONEncoder()
218218
file_path = TestSearchCommandsApp._data_file(os.path.join('input', 'counts.csv'))
219219

220-
command = StubbedStreamingCommand() # All options are required
221-
222220
options = [
223221
'boolean=true',
224222
'duration=00:00:10',
@@ -228,9 +226,9 @@ def test_command_parser(self):
228226
'optionname=foo_bar',
229227
'regularexpression="\\\\w+"',
230228
'set=foo']
231-
232229
fields = ['field_1', 'field_2', 'field_3']
233230

231+
command = StubbedStreamingCommand() # All options are required
234232
parser.parse(options + fields, command)
235233
command_line = str(command)
236234

@@ -239,8 +237,36 @@ def test_command_parser(self):
239237
command_line)
240238

241239
for option in options:
242-
self.assertRaises(ValueError, parser.parse([x for x in options if x != option] + ['field_1', 'field_2', 'field_3'], command))
240+
self.assertRaises(ValueError, parser.parse, [x for x in options if x != option] + ['field_1', 'field_2', 'field_3'], command)
241+
242+
command = StubbedReportingCommand() # No options are required
243+
parser.parse(options + fields, command)
244+
245+
for option in options:
246+
try:
247+
parser.parse([x for x in options if x != option] + ['field_1', 'field_2', 'field_3'], command)
248+
except Exception as e:
249+
self.assertFalse("Unexpected exception: %s" % e)
250+
251+
try:
252+
parser.parse(options, command)
253+
except Exception as e:
254+
self.assertFalse("Unexpected exception: %s" % e)
255+
256+
for option in command.options.itervalues():
257+
self.assertTrue(option.is_set)
258+
259+
self.assertEqual(len(command.fieldnames), 0)
260+
261+
try:
262+
parser.parse(fields, command)
263+
except Exception as e:
264+
self.assertFalse("Unexpected exception: %s" % e)
265+
266+
for option in command.options.itervalues():
267+
self.assertFalse(option.is_set)
243268

269+
self.assertListEqual(fields, command.fieldnames)
244270
return
245271

246272
def disable_test_option_logging_configuration(self):

0 commit comments

Comments
 (0)