Skip to content

Commit ec6907a

Browse files
committed
test changes for six.py removal
1 parent 893b0d7 commit ec6907a

File tree

6 files changed

+98
-107
lines changed

6 files changed

+98
-107
lines changed

tests/searchcommands/test_builtin_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from unittest import main, TestCase
2424
import pytest
25-
from splunklib.six.moves import cStringIO as StringIO
25+
from io import StringIO
2626

2727

2828
from splunklib.searchcommands import environment

tests/searchcommands/test_configuration_settings.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from unittest import main, TestCase
2929
import pytest
3030
from splunklib.searchcommands.decorators import Configuration
31-
from splunklib import six
3231

3332

3433

@@ -48,7 +47,7 @@ def generate(self):
4847
command._protocol_version = 1
4948

5049
self.assertTrue(
51-
list(six.iteritems(command.configuration)),
50+
list(command.configuration.items()),
5251
[('generating', True)])
5352

5453
self.assertIs(command.configuration.generates_timeorder, None)
@@ -71,15 +70,15 @@ def generate(self):
7170
self.fail('Expected AttributeError')
7271

7372
self.assertEqual(
74-
list(six.iteritems(command.configuration)),
73+
list(command.configuration.items()),
7574
[('generates_timeorder', True), ('generating', True), ('local', True), ('retainsevents', True),
7675
('streaming', True)])
7776

7877
command = TestCommand()
7978
command._protocol_version = 2
8079

8180
self.assertEqual(
82-
list(six.iteritems(command.configuration)),
81+
list(command.configuration.items()),
8382
[('generating', True), ('type', 'stateful')])
8483

8584
self.assertIs(command.configuration.distributed, False)
@@ -98,7 +97,7 @@ def generate(self):
9897
self.fail('Expected AttributeError')
9998

10099
self.assertEqual(
101-
list(six.iteritems(command.configuration)),
100+
list(command.configuration.items()),
102101
[('generating', True), ('type', 'streaming')])
103102

104103
def test_streaming_command(self):
@@ -115,7 +114,7 @@ def stream(self, records):
115114
command._protocol_version = 1
116115

117116
self.assertEqual(
118-
list(six.iteritems(command.configuration)),
117+
list(command.configuration.items()),
119118
[('streaming', True)])
120119

121120
self.assertIs(command.configuration.clear_required_fields, None)
@@ -139,15 +138,15 @@ def stream(self, records):
139138
self.fail('Expected AttributeError')
140139

141140
self.assertEqual(
142-
list(six.iteritems(command.configuration)),
141+
list(command.configuration.items()),
143142
[('clear_required_fields', True), ('local', True), ('overrides_timeorder', True),
144143
('required_fields', ['field_1', 'field_2', 'field_3']), ('streaming', True)])
145144

146145
command = TestCommand()
147146
command._protocol_version = 2
148147

149148
self.assertEqual(
150-
list(six.iteritems(command.configuration)),
149+
list(command.configuration.items()),
151150
[('type', 'streaming')])
152151

153152
self.assertIs(command.configuration.distributed, True)
@@ -166,7 +165,7 @@ def stream(self, records):
166165
self.fail('Expected AttributeError')
167166

168167
self.assertEqual(
169-
list(six.iteritems(command.configuration)),
168+
list(command.configuration.items()),
170169
[('required_fields', ['field_1', 'field_2', 'field_3']), ('type', 'stateful')])
171170

172171

tests/searchcommands/test_decorators.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929

3030
from tests.searchcommands import rebase_environment
3131

32-
from splunklib import six
33-
34-
3532

3633
@Configuration()
3734
class TestSearchCommand(SearchCommand):
38-
3935
boolean = Option(
4036
doc='''
4137
**Syntax:** **boolean=***<value>*
@@ -226,49 +222,48 @@ def fix_up(cls, command_class):
226222
return ConfiguredSearchCommand.ConfigurationSettings
227223

228224
for name, values, error_values in (
229-
('clear_required_fields',
230-
(True, False),
231-
(None, 'anything other than a bool')),
232-
('distributed',
233-
(True, False),
234-
(None, 'anything other than a bool')),
235-
('generates_timeorder',
236-
(True, False),
237-
(None, 'anything other than a bool')),
238-
('generating',
239-
(True, False),
240-
(None, 'anything other than a bool')),
241-
('maxinputs',
242-
(0, 50000, sys.maxsize),
243-
(None, -1, sys.maxsize + 1, 'anything other than an int')),
244-
('overrides_timeorder',
245-
(True, False),
246-
(None, 'anything other than a bool')),
247-
('required_fields',
248-
(['field_1', 'field_2'], set(['field_1', 'field_2']), ('field_1', 'field_2')),
249-
(None, 0xdead, {'foo': 1, 'bar': 2})),
250-
('requires_preop',
251-
(True, False),
252-
(None, 'anything other than a bool')),
253-
('retainsevents',
254-
(True, False),
255-
(None, 'anything other than a bool')),
256-
('run_in_preview',
257-
(True, False),
258-
(None, 'anything other than a bool')),
259-
('streaming',
260-
(True, False),
261-
(None, 'anything other than a bool')),
262-
('streaming_preop',
263-
('some unicode string', b'some byte string'),
264-
(None, 0xdead)),
265-
('type',
266-
# TODO: Do we need to validate byte versions of these strings?
267-
('events', 'reporting', 'streaming'),
268-
('eventing', 0xdead))):
225+
('clear_required_fields',
226+
(True, False),
227+
(None, 'anything other than a bool')),
228+
('distributed',
229+
(True, False),
230+
(None, 'anything other than a bool')),
231+
('generates_timeorder',
232+
(True, False),
233+
(None, 'anything other than a bool')),
234+
('generating',
235+
(True, False),
236+
(None, 'anything other than a bool')),
237+
('maxinputs',
238+
(0, 50000, sys.maxsize),
239+
(None, -1, sys.maxsize + 1, 'anything other than an int')),
240+
('overrides_timeorder',
241+
(True, False),
242+
(None, 'anything other than a bool')),
243+
('required_fields',
244+
(['field_1', 'field_2'], set(['field_1', 'field_2']), ('field_1', 'field_2')),
245+
(None, 0xdead, {'foo': 1, 'bar': 2})),
246+
('requires_preop',
247+
(True, False),
248+
(None, 'anything other than a bool')),
249+
('retainsevents',
250+
(True, False),
251+
(None, 'anything other than a bool')),
252+
('run_in_preview',
253+
(True, False),
254+
(None, 'anything other than a bool')),
255+
('streaming',
256+
(True, False),
257+
(None, 'anything other than a bool')),
258+
('streaming_preop',
259+
('some unicode string', b'some byte string'),
260+
(None, 0xdead)),
261+
('type',
262+
# TODO: Do we need to validate byte versions of these strings?
263+
('events', 'reporting', 'streaming'),
264+
('eventing', 0xdead))):
269265

270266
for value in values:
271-
272267
settings_class = new_configuration_settings_class(name, value)
273268

274269
# Setting property exists
@@ -296,7 +291,9 @@ def fix_up(cls, command_class):
296291
try:
297292
new_configuration_settings_class(name, value)
298293
except Exception as error:
299-
self.assertIsInstance(error, ValueError, 'Expected ValueError, not {}({}) for {}={}'.format(type(error).__name__, error, name, repr(value)))
294+
self.assertIsInstance(error, ValueError,
295+
'Expected ValueError, not {}({}) for {}={}'.format(type(error).__name__,
296+
error, name, repr(value)))
300297
else:
301298
self.fail(f'Expected ValueError, not success for {name}={repr(value)}')
302299

@@ -355,13 +352,13 @@ def test_option(self):
355352
command = TestSearchCommand()
356353
options = command.options
357354

358-
itervalues = lambda: six.itervalues(options)
355+
#itervalues = lambda: options.values()
359356

360357
options.reset()
361358
missing = options.get_missing()
362-
self.assertListEqual(missing, [option.name for option in itervalues() if option.is_required])
363-
self.assertListEqual(presets, [six.text_type(option) for option in itervalues() if option.value is not None])
364-
self.assertListEqual(presets, [six.text_type(option) for option in itervalues() if six.text_type(option) != option.name + '=None'])
359+
self.assertListEqual(missing, [option.name for option in options.values() if option.is_required])
360+
self.assertListEqual(presets, [str(option) for option in options.values() if option.value is not None])
361+
self.assertListEqual(presets, [str(option) for option in options.values() if str(option) != option.name + '=None'])
365362

366363
test_option_values = {
367364
validators.Boolean: ('0', 'non-boolean value'),
@@ -378,7 +375,7 @@ def test_option(self):
378375
validators.RegularExpression: ('\\s+', '(poorly formed regular expression'),
379376
validators.Set: ('bar', 'non-existent set entry')}
380377

381-
for option in itervalues():
378+
for option in options.values():
382379
validator = option.validator
383380

384381
if validator is None:
@@ -397,7 +394,8 @@ def test_option(self):
397394
except ValueError:
398395
pass
399396
except BaseException as error:
400-
self.assertFalse(f'Expected ValueError for {option.name}={illegal_value}, not this {type(error).__name__}: {error}')
397+
self.assertFalse(
398+
f'Expected ValueError for {option.name}={illegal_value}, not this {type(error).__name__}: {error}')
401399
else:
402400
self.assertFalse(f'Expected ValueError for {option.name}={illegal_value}, not a pass.')
403401

@@ -407,7 +405,7 @@ def test_option(self):
407405
'code': 'foo == \"bar\"',
408406
'duration': 89999,
409407
'fieldname': 'some.field_name',
410-
'file': six.text_type(repr(__file__)),
408+
'file': str(repr(__file__)),
411409
'integer': 100,
412410
'float': 99.9,
413411
'logging_configuration': environment.logging_configuration,
@@ -421,7 +419,7 @@ def test_option(self):
421419
'required_code': 'foo == \"bar\"',
422420
'required_duration': 89999,
423421
'required_fieldname': 'some.field_name',
424-
'required_file': six.text_type(repr(__file__)),
422+
'required_file': str(repr(__file__)),
425423
'required_integer': 100,
426424
'required_float': 99.9,
427425
'required_map': 'foo',
@@ -436,36 +434,38 @@ def test_option(self):
436434
self.maxDiff = None
437435

438436
tuplewrap = lambda x: x if isinstance(x, tuple) else (x,)
439-
invert = lambda x: {v: k for k, v in six.iteritems(x)}
437+
invert = lambda x: {v: k for k, v in x.items()}
440438

441-
for x in six.itervalues(command.options):
442-
# isinstance doesn't work for some reason
439+
for x in command.options.values():
440+
# isinstance doesn't work for some reason
443441
if type(x.value).__name__ == 'Code':
444442
self.assertEqual(expected[x.name], x.value.source)
445443
elif type(x.validator).__name__ == 'Map':
446444
self.assertEqual(expected[x.name], invert(x.validator.membership)[x.value])
447445
elif type(x.validator).__name__ == 'RegularExpression':
448446
self.assertEqual(expected[x.name], x.value.pattern)
449447
elif isinstance(x.value, TextIOWrapper):
450-
self.assertEqual(expected[x.name], f"'{x.value.name}'" )
451-
elif not isinstance(x.value, (bool,) + (float,) + (six.text_type,) + (six.binary_type,) + tuplewrap(six.integer_types)):
448+
self.assertEqual(expected[x.name], f"'{x.value.name}'")
449+
elif not isinstance(x.value, (bool,) + (float,) + (str,) + (bytes,) + tuplewrap(int)):
452450
self.assertEqual(expected[x.name], repr(x.value))
453451
else:
454452
self.assertEqual(expected[x.name], x.value)
455453

456454
expected = (
457-
'foo="f" boolean="f" code="foo == \\"bar\\"" duration="24:59:59" fieldname="some.field_name" '
458-
'file=' + json_encode_string(__file__) + ' float="99.9" integer="100" map="foo" match="123-45-6789" '
459-
'optionname="some_option_name" record="f" regularexpression="\\\\s+" required_boolean="f" '
460-
'required_code="foo == \\"bar\\"" required_duration="24:59:59" required_fieldname="some.field_name" '
461-
'required_file=' + json_encode_string(__file__) + ' required_float="99.9" required_integer="100" required_map="foo" '
462-
'required_match="123-45-6789" required_optionname="some_option_name" required_regularexpression="\\\\s+" '
463-
'required_set="bar" set="bar" show_configuration="f"')
455+
'foo="f" boolean="f" code="foo == \\"bar\\"" duration="24:59:59" fieldname="some.field_name" '
456+
'file=' + json_encode_string(__file__) + ' float="99.9" integer="100" map="foo" match="123-45-6789" '
457+
'optionname="some_option_name" record="f" regularexpression="\\\\s+" required_boolean="f" '
458+
'required_code="foo == \\"bar\\"" required_duration="24:59:59" required_fieldname="some.field_name" '
459+
'required_file=' + json_encode_string(
460+
__file__) + ' required_float="99.9" required_integer="100" required_map="foo" '
461+
'required_match="123-45-6789" required_optionname="some_option_name" required_regularexpression="\\\\s+" '
462+
'required_set="bar" set="bar" show_configuration="f"')
464463

465-
observed = six.text_type(command.options)
464+
observed = str(command.options)
466465

467466
self.assertEqual(observed, expected)
468467

468+
469469
TestSearchCommand.__test__ = False
470470

471471
if __name__ == "__main__":

tests/searchcommands/test_internals_v1.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
from splunklib.searchcommands.search_command import SearchCommand
2828

29-
from splunklib.six import StringIO, BytesIO
29+
from io import StringIO, BytesIO
3030

31-
from splunklib import six
32-
from splunklib.six.moves import range
3331

3432

3533
@pytest.mark.smoke
@@ -57,7 +55,7 @@ def fix_up(cls, command_class): pass
5755
command = TestCommandLineParserCommand()
5856
CommandLineParser.parse(command, options)
5957

60-
for option in six.itervalues(command.options):
58+
for option in command.options.values():
6159
if option.name in ['logging_configuration', 'logging_level', 'record', 'show_configuration']:
6260
self.assertFalse(option.is_set)
6361
continue
@@ -74,7 +72,7 @@ def fix_up(cls, command_class): pass
7472
command = TestCommandLineParserCommand()
7573
CommandLineParser.parse(command, options + fieldnames)
7674

77-
for option in six.itervalues(command.options):
75+
for option in command.options.values():
7876
if option.name in ['logging_configuration', 'logging_level', 'record', 'show_configuration']:
7977
self.assertFalse(option.is_set)
8078
continue
@@ -89,7 +87,7 @@ def fix_up(cls, command_class): pass
8987
command = TestCommandLineParserCommand()
9088
CommandLineParser.parse(command, ['required_option=true'] + fieldnames)
9189

92-
for option in six.itervalues(command.options):
90+
for option in command.options.values():
9391
if option.name in ['unnecessary_option', 'logging_configuration', 'logging_level', 'record',
9492
'show_configuration']:
9593
self.assertFalse(option.is_set)
@@ -284,7 +282,7 @@ def test_input_header(self):
284282
'sentence': 'hello world!'}
285283

286284
input_header = InputHeader()
287-
text = reduce(lambda value, item: value + f'{item[0]}:{item[1]}\n', six.iteritems(collection), '') + '\n'
285+
text = reduce(lambda value, item: value + f'{item[0]}:{item[1]}\n', collection.items(), '') + '\n'
288286

289287
with closing(StringIO(text)) as input_file:
290288
input_header.read(input_file)

0 commit comments

Comments
 (0)