Skip to content

Commit a67ef41

Browse files
author
Shakeel Mohamed
committed
Fix bugs in search commands decorators, validators & internals tests
1 parent f8107f2 commit a67ef41

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎splunklib/searchcommands/decorators.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def __repr__(self):
222222
return str(self)
223223

224224
def __str__(self):
225-
value = self.validator.format(self.value) if self.validator is not None else str(self.value)
225+
value = str(self.value) if self.validator is None else self.validator.format(self.value)
226226
encoder = Option.Encoder(self)
227227
text = '='.join([self.name, encoder.encode(value)])
228228
return text

‎splunklib/searchcommands/search_command.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self):
5757
u'If you are testing outside of Splunk, consider running under control of the Splunk CLI:\n'
5858
u' splunk cmd %s\n'
5959
u'If you are running inside of Splunk, SPLUNK_HOME should be defined. Consider troubleshooting your '
60-
u'installation.', self)
60+
u'installation.')
6161

6262
# Variables backing option/property values
6363

‎splunklib/searchcommands/validators.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import re
2323
import sys
2424

25-
2625
class Validator(object):
2726
""" Base class for validators that check and format search command options.
2827
@@ -63,7 +62,7 @@ def __call__(self, value):
6362
return value
6463

6564
def format(self, value):
66-
return 't' if value else 'f'
65+
return self.__call__(value)
6766

6867

6968
class Fieldname(Validator):
@@ -123,12 +122,12 @@ def check_range(value):
123122
elif minimum is not None:
124123
def check_range(value):
125124
if value < minimum:
126-
raise ValueError('Expected integer in the range [-∞,%d]: %d' % (maximum, value))
125+
raise ValueError('Expected integer in the range [%d,+∞]: %d' % (minimum, value))
127126
return
128127
elif maximum is not None:
129128
def check_range(value):
130129
if value > maximum:
131-
raise ValueError('Expected integer in the range [%d,+∞]: %d' % (minimum, value))
130+
raise ValueError('Expected integer in the range [-∞,%d]: %d' % (maximum, value))
132131
return
133132
else:
134133
def check_range(value):
@@ -144,7 +143,7 @@ def __call__(self, value):
144143
return value
145144

146145
def format(self, value):
147-
return str(value)
146+
return int(value)
148147

149148

150149
class Duration(Validator):
@@ -226,6 +225,9 @@ def __call__(self, value):
226225
raise ValueError('Illegal characters in option name: %s' % value)
227226
return value
228227

228+
def format(self, value):
229+
return self.__call__(value)
230+
229231

230232
class RegularExpression(Validator):
231233
""" Validates regular expression option values.
@@ -256,3 +258,6 @@ def __call__(self, value):
256258
if value not in self.membership:
257259
raise ValueError('Unrecognized value: %s' % value)
258260
return value
261+
262+
def format(self, value):
263+
return self.__call__(value)

‎tests/searchcommands/test_search_command_internals.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_command_parser(self):
170170
command_line = str(command)
171171

172172
self.assertEqual(
173-
'stubbedstreaming boolean=true duration=10 fieldname="word_count" file=%s integer=10 optionname="foo_bar" regularexpression="\\\\w+" set="foo" field_1 field_2 field_3' % encoder.encode(file_path),
173+
'stubbedstreaming boolean=true duration="00:00:10" fieldname="word_count" file=%s integer=10 optionname="foo_bar" regularexpression="\\\\w+" set="foo" field_1 field_2 field_3' % encoder.encode(file_path),
174174
command_line)
175175

176176
for option in options:

0 commit comments

Comments
 (0)