Skip to content

Commit 4cb0f4a

Browse files
committed
code changes
1 parent 6429ae4 commit 4cb0f4a

14 files changed

+76
-106
lines changed

tests/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/modularinput/__init__.py

Whitespace-only changes.

tests/searchcommands/test_builtin_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import sys
2121
import logging
2222

23-
import pytest
2423
from unittest import main, TestCase
24+
import pytest
2525
from splunklib.six.moves import cStringIO as StringIO
2626

2727

tests/searchcommands/test_decorators.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@
2020
import sys
2121

2222
from io import TextIOWrapper
23+
import pytest
2324

2425
from splunklib.searchcommands import Configuration, Option, environment, validators
2526
from splunklib.searchcommands.decorators import ConfigurationSetting
2627
from splunklib.searchcommands.internals import json_encode_string
2728
from splunklib.searchcommands.search_command import SearchCommand
2829

29-
try:
30-
from tests.searchcommands import rebase_environment
31-
except ImportError:
32-
# Skip on Python 2.6
33-
pass
30+
from tests.searchcommands import rebase_environment
3431

3532
from splunklib import six
3633

37-
import pytest
3834

3935

4036
@Configuration()
@@ -302,7 +298,7 @@ def fix_up(cls, command_class):
302298
except Exception as error:
303299
self.assertIsInstance(error, ValueError, 'Expected ValueError, not {}({}) for {}={}'.format(type(error).__name__, error, name, repr(value)))
304300
else:
305-
self.fail('Expected ValueError, not success for {}={}'.format(name, repr(value)))
301+
self.fail(f'Expected ValueError, not success for {name}={repr(value)}')
306302

307303
settings_class = new_configuration_settings_class()
308304
settings_instance = settings_class(command=None)
@@ -451,7 +447,7 @@ def test_option(self):
451447
elif type(x.validator).__name__ == 'RegularExpression':
452448
self.assertEqual(expected[x.name], x.value.pattern)
453449
elif isinstance(x.value, TextIOWrapper):
454-
self.assertEqual(expected[x.name], "'%s'" % x.value.name)
450+
self.assertEqual(expected[x.name], f"'{x.value.name}'" )
455451
elif not isinstance(x.value, (bool,) + (float,) + (six.text_type,) + (six.binary_type,) + tuplewrap(six.integer_types)):
456452
self.assertEqual(expected[x.name], repr(x.value))
457453
else:

tests/searchcommands/test_generator_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def generate(self):
2323
ds = chunky.ChunkedDataStream(out_stream)
2424
is_first_chunk = True
2525
finished_seen = False
26-
expected = set([str(i) for i in range(1, 10)])
26+
expected = set(str(i) for i in range(1, 10))
2727
seen = set()
2828
for chunk in ds:
2929
if is_first_chunk:

tests/searchcommands/test_internals_v1.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,23 @@
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

1823
from splunklib.searchcommands.internals import CommandLineParser, InputHeader, RecordWriterV1
1924
from splunklib.searchcommands.decorators import Configuration, Option
2025
from splunklib.searchcommands.validators import Boolean
2126

2227
from splunklib.searchcommands.search_command import SearchCommand
2328

24-
from contextlib import closing
2529
from 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
3231
from splunklib import six
3332
from splunklib.six.moves import range
34-
from functools import reduce
3533

36-
import pytest
3734

3835
@pytest.mark.smoke
3936
class 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

tests/searchcommands/test_internals_v2.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,31 @@
1515
# License for the specific language governing permissions and limitations
1616
# under the License.
1717

18+
import gzip
19+
import io
20+
import json
21+
import os
22+
import random
1823

19-
from splunklib.searchcommands.internals import MetadataDecoder, MetadataEncoder, Recorder, RecordWriterV2
20-
from splunklib.searchcommands import SearchMetric
21-
from splunklib import six
22-
from splunklib.six.moves import range
23-
from collections import OrderedDict
24-
from collections import namedtuple, deque
25-
from splunklib.six import BytesIO as BytesIO
24+
import pytest
2625
from functools import wraps
27-
from glob import iglob
2826
from itertools import chain
29-
from splunklib.six.moves import filter as ifilter
30-
from splunklib.six.moves import map as imap
31-
from splunklib.six.moves import zip as izip
3227
from sys import float_info
3328
from tempfile import mktemp
3429
from time import time
3530
from types import MethodType
36-
from sys import version_info as python_version
37-
try:
38-
from unittest2 import main, TestCase
39-
except ImportError:
40-
from unittest import main, TestCase
31+
from unittest import main, TestCase
4132

33+
from collections import OrderedDict
34+
from collections import namedtuple, deque
35+
36+
from splunklib.searchcommands.internals import MetadataDecoder, MetadataEncoder, Recorder, RecordWriterV2
37+
from splunklib.searchcommands import SearchMetric
38+
from splunklib import six
39+
from splunklib.six.moves import range
40+
from splunklib.six import BytesIO as BytesIO
4241
import splunklib.six.moves.cPickle as pickle
43-
import gzip
44-
import io
45-
import json
46-
import os
47-
import random
4842

49-
import pytest
5043

5144
# region Functions for producing random apps
5245

@@ -228,8 +221,8 @@ def test_record_writer_with_random_data(self, save_recording=False):
228221
self.assertListEqual(writer._inspector['messages'], messages)
229222

230223
self.assertDictEqual(
231-
dict([k_v for k_v in six.iteritems(writer._inspector) if k_v[0].startswith('metric.')]),
232-
dict([('metric.' + k_v1[0], k_v1[1]) for k_v1 in six.iteritems(metrics)]))
224+
dict(k_v for k_v in six.iteritems(writer._inspector) if k_v[0].startswith('metric.')),
225+
dict(('metric.' + k_v1[0], k_v1[1]) for k_v1 in six.iteritems(metrics)))
233226

234227
writer.flush(finished=True)
235228

tests/searchcommands/test_multibyte_processing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from os import path
66

7-
from splunklib import six
87
from splunklib.searchcommands import StreamingCommand, Configuration
98

109

tests/searchcommands/test_search_command.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@
1515
# License for the specific language governing permissions and limitations
1616
# under the License.
1717

18-
19-
from splunklib import six
20-
from splunklib.searchcommands import Configuration, StreamingCommand
21-
from splunklib.searchcommands.decorators import ConfigurationSetting, Option
22-
from splunklib.searchcommands.search_command import SearchCommand
23-
from splunklib.client import Service
24-
25-
from splunklib.six import StringIO, BytesIO
26-
from splunklib.six.moves import zip as izip
2718
from json.encoder import encode_basestring as encode_string
2819
from unittest import main, TestCase
2920

@@ -36,11 +27,18 @@
3627

3728
import pytest
3829

30+
from splunklib import six
31+
from splunklib.searchcommands import Configuration, StreamingCommand
32+
from splunklib.searchcommands.decorators import ConfigurationSetting, Option
33+
from splunklib.searchcommands.search_command import SearchCommand
34+
from splunklib.client import Service
35+
36+
from splunklib.six import StringIO, BytesIO
37+
3938

4039
def build_command_input(getinfo_metadata, execute_metadata, execute_body):
41-
input = ('chunked 1.0,{},0\n{}'.format(len(six.ensure_binary(getinfo_metadata)), getinfo_metadata) +
42-
'chunked 1.0,{},{}\n{}{}'.format(len(six.ensure_binary(execute_metadata)),
43-
len(six.ensure_binary(execute_body)), execute_metadata, execute_body))
40+
input = (f'chunked 1.0,{len(six.ensure_binary(getinfo_metadata))},0\n{getinfo_metadata}' +
41+
f'chunked 1.0,{len(six.ensure_binary(execute_metadata))},{len(six.ensure_binary(execute_body))}\n{execute_metadata}{execute_body}')
4442

4543
ifile = BytesIO(six.ensure_binary(input))
4644

@@ -311,7 +309,7 @@ def test_process_scpv1(self):
311309
# noinspection PyTypeChecker
312310
command.process(argv, ifile, ofile=result)
313311
except BaseException as error:
314-
self.fail('Expected no exception, but caught {}: {}'.format(type(error).__name__, error))
312+
self.fail(f'Expected no exception, but caught {type(error).__name__}: {error}')
315313
else:
316314
six.assertRegex(
317315
self,

tests/searchcommands/test_searchcommands_app.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@
2525

2626

2727
from collections import namedtuple
28-
from splunklib.six.moves import cStringIO as StringIO
2928
from datetime import datetime
3029

31-
from splunklib.six.moves import filter as ifilter
32-
from splunklib.six.moves import map as imap
33-
from splunklib.six.moves import zip as izip
34-
3530
from subprocess import PIPE, Popen
36-
from splunklib import six
3731

3832
from unittest import main, skipUnless, TestCase
3933

@@ -43,14 +37,12 @@
4337
import io
4438
import os
4539
import sys
40+
import pytest
4641

47-
try:
48-
from tests.searchcommands import project_root
49-
except ImportError:
50-
# Python 2.6
51-
pass
42+
from splunklib.six.moves import cStringIO as StringIO
43+
from splunklib import six
5244

53-
import pytest
45+
from tests.searchcommands import project_root
5446

5547

5648
def pypy():
@@ -287,8 +279,7 @@ def _compare_csv_files_time_insensitive(self, expected, output):
287279
output_row['_time'] = expected_row['_time']
288280

289281
self.assertDictEqual(
290-
expected_row, output_row, 'Error on line {0}: expected {1}, not {2}'.format(
291-
line_number, expected_row, output_row))
282+
expected_row, output_row, f'Error on line {line_number}: expected {expected_row}, not {output_row}')
292283

293284
line_number += 1
294285

@@ -310,8 +301,7 @@ def _compare_csv_files_time_sensitive(self, expected, output):
310301
for expected_row in expected:
311302
output_row = next(output)
312303
self.assertDictEqual(
313-
expected_row, output_row, 'Error on line {0}: expected {1}, not {2}'.format(
314-
line_number, expected_row, output_row))
304+
expected_row, output_row, f'Error on line {line_number}: expected {expected_row}, not {output_row}')
315305
line_number += 1
316306

317307
def _get_search_command_path(self, name):

0 commit comments

Comments
 (0)