1414# License for the specific language governing permissions and limitations
1515# under the License.
1616
17+ from contextlib import closing
18+ from unittest import main , TestCase
19+ import os
20+ import pytest
21+ from functools import reduce
1722
1823from splunklib .searchcommands .internals import CommandLineParser , InputHeader , RecordWriterV1
1924from splunklib .searchcommands .decorators import Configuration , Option
2025from splunklib .searchcommands .validators import Boolean
2126
2227from splunklib .searchcommands .search_command import SearchCommand
2328
24- from contextlib import closing
2529from splunklib .six import StringIO , BytesIO
2630
27- from splunklib .six .moves import zip as izip
28-
29- from unittest import main , TestCase
30-
31- import os
3231from splunklib import six
3332from splunklib .six .moves import range
34- from functools import reduce
3533
36- import pytest
3734
3835@pytest .mark .smoke
3936class TestInternals (TestCase ):
@@ -93,7 +90,8 @@ def fix_up(cls, command_class): pass
9390 CommandLineParser .parse (command , ['required_option=true' ] + fieldnames )
9491
9592 for option in six .itervalues (command .options ):
96- if option .name in ['unnecessary_option' , 'logging_configuration' , 'logging_level' , 'record' , 'show_configuration' ]:
93+ if option .name in ['unnecessary_option' , 'logging_configuration' , 'logging_level' , 'record' ,
94+ 'show_configuration' ]:
9795 self .assertFalse (option .is_set )
9896 continue
9997 self .assertTrue (option .is_set )
@@ -111,7 +109,8 @@ def fix_up(cls, command_class): pass
111109
112110 # Command line with unrecognized options
113111
114- self .assertRaises (ValueError , CommandLineParser .parse , command , ['unrecognized_option_1=foo' , 'unrecognized_option_2=bar' ])
112+ self .assertRaises (ValueError , CommandLineParser .parse , command ,
113+ ['unrecognized_option_1=foo' , 'unrecognized_option_2=bar' ])
115114
116115 # Command line with a variety of quoted/escaped text options
117116
@@ -175,24 +174,23 @@ def fix_up(cls, command_class): pass
175174 argv = [string ]
176175 self .assertRaises (SyntaxError , CommandLineParser .parse , command , argv )
177176
178-
179177 def test_command_line_parser_unquote (self ):
180178 parser = CommandLineParser
181179
182180 options = [
183- r'foo' , # unquoted string with no escaped characters
184- r'fo\o\ b\"a\\r' , # unquoted string with some escaped characters
185- r'"foo"' , # quoted string with no special characters
186- r'"""foobar1"""' , # quoted string with quotes escaped like this: ""
187- r'"\"foobar2\""' , # quoted string with quotes escaped like this: \"
188- r'"foo ""x"" bar"' , # quoted string with quotes escaped like this: ""
189- r'"foo \"x\" bar"' , # quoted string with quotes escaped like this: \"
190- r'"\\foobar"' , # quoted string with an escaped backslash
191- r'"foo \\ bar"' , # quoted string with an escaped backslash
192- r'"foobar\\"' , # quoted string with an escaped backslash
193- r'foo\\\bar' , # quoted string with an escaped backslash and an escaped 'b'
194- r'""' , # pair of quotes
195- r'' ] # empty string
181+ r'foo' , # unquoted string with no escaped characters
182+ r'fo\o\ b\"a\\r' , # unquoted string with some escaped characters
183+ r'"foo"' , # quoted string with no special characters
184+ r'"""foobar1"""' , # quoted string with quotes escaped like this: ""
185+ r'"\"foobar2\""' , # quoted string with quotes escaped like this: \"
186+ r'"foo ""x"" bar"' , # quoted string with quotes escaped like this: ""
187+ r'"foo \"x\" bar"' , # quoted string with quotes escaped like this: \"
188+ r'"\\foobar"' , # quoted string with an escaped backslash
189+ r'"foo \\ bar"' , # quoted string with an escaped backslash
190+ r'"foobar\\"' , # quoted string with an escaped backslash
191+ r'foo\\\bar' , # quoted string with an escaped backslash and an escaped 'b'
192+ r'""' , # pair of quotes
193+ r'' ] # empty string
196194
197195 expected = [
198196 r'foo' ,
@@ -286,7 +284,7 @@ def test_input_header(self):
286284 'sentence' : 'hello world!' }
287285
288286 input_header = InputHeader ()
289- text = reduce (lambda value , item : value + '{}:{} \n ' . format ( item [0 ], item [1 ]) , six .iteritems (collection ), '' ) + '\n '
287+ text = reduce (lambda value , item : value + f' { item [0 ]} : { item [1 ]} \n ' , six .iteritems (collection ), '' ) + '\n '
290288
291289 with closing (StringIO (text )) as input_file :
292290 input_header .read (input_file )
@@ -310,7 +308,6 @@ def test_messages_header(self):
310308
311309 @Configuration ()
312310 class TestMessagesHeaderCommand (SearchCommand ):
313-
314311 class ConfigurationSettings (SearchCommand .ConfigurationSettings ):
315312
316313 @classmethod
0 commit comments