Skip to content

Commit b003be2

Browse files
committed
update string formatting
1 parent 0766ed8 commit b003be2

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

tests/searchcommands/test_decorators.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ def fix_up(cls, command_class):
292292
new_configuration_settings_class(name, value)
293293
except Exception as error:
294294
self.assertIsInstance(error, ValueError,
295-
'Expected ValueError, not {}({}) for {}={}'.format(type(error).__name__,
296-
error, name, repr(value)))
295+
f'Expected ValueError, not {type(error).__name__}({error}) for {name}={repr(value)}')
297296
else:
298297
self.fail(f'Expected ValueError, not success for {name}={repr(value)}')
299298

@@ -352,8 +351,6 @@ def test_option(self):
352351
command = TestSearchCommand()
353352
options = command.options
354353

355-
#itervalues = lambda: options.values()
356-
357354
options.reset()
358355
missing = options.get_missing()
359356
self.assertListEqual(missing, [option.name for option in list(options.values()) if option.is_required])
@@ -452,14 +449,13 @@ def test_option(self):
452449
self.assertEqual(expected[x.name], x.value)
453450

454451
expected = (
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"')
452+
'foo="f" boolean="f" code="foo == \\"bar\\"" duration="24:59:59" fieldname="some.field_name" '
453+
'file=' + json_encode_string(__file__) + ' float="99.9" integer="100" map="foo" match="123-45-6789" '
454+
'optionname="some_option_name" record="f" regularexpression="\\\\s+" required_boolean="f" '
455+
'required_code="foo == \\"bar\\"" required_duration="24:59:59" required_fieldname="some.field_name" '
456+
'required_file=' + json_encode_string(__file__) + ' required_float="99.9" required_integer="100" required_map="foo" '
457+
'required_match="123-45-6789" required_optionname="some_option_name" required_regularexpression="\\\\s+" '
458+
'required_set="bar" set="bar" show_configuration="f"')
463459

464460
observed = str(command.options)
465461

tests/test_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def setUp(self):
3636
self.app_name = testlib.tmpname()
3737
self.app = self.service.apps.create(self.app_name)
3838
logging.debug(f"Creating app {self.app_name}")
39-
logging.debug(f"App {self.app_name} already exists. Skipping creation.")
39+
else:
40+
logging.debug(f"App {self.app_name} already exists. Skipping creation.")
4041
if self.service.restart_required:
4142
self.service.restart(120)
4243

tests/test_binding.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,10 @@ def test_post_with_get_arguments_to_receivers_stream(self):
278278
class TestSocket(BindingTestCase):
279279
def test_socket(self):
280280
socket = self.context.connect()
281-
socket.write(("POST %s HTTP/1.1\r\n" % \
282-
self.context._abspath("some/path/to/post/to")).encode('utf-8'))
283-
socket.write(("Host: %s:%s\r\n" % \
284-
(self.context.host, self.context.port)).encode('utf-8'))
281+
socket.write((f"POST {self.context._abspath('some/path/to/post/to')} HTTP/1.1\r\n").encode('utf-8'))
282+
socket.write((f"Host: {self.context.host}:{self.context.port}\r\n").encode('utf-8'))
285283
socket.write("Accept-Encoding: identity\r\n".encode('utf-8'))
286-
socket.write(("Authorization: %s\r\n" % \
287-
self.context.token).encode('utf-8'))
284+
socket.write((f"Authorization: {self.context.token}\r\n").encode('utf-8'))
288285
socket.write("X-Splunk-Input-Mode: Streaming\r\n".encode('utf-8'))
289286
socket.write("\r\n".encode('utf-8'))
290287
socket.close()
@@ -799,13 +796,10 @@ def test_preexisting_token(self):
799796
self.assertEqual(response.status, 200)
800797

801798
socket = newContext.connect()
802-
socket.write(("POST %s HTTP/1.1\r\n" % \
803-
self.context._abspath("some/path/to/post/to")).encode('utf-8'))
804-
socket.write(("Host: %s:%s\r\n" % \
805-
(self.context.host, self.context.port)).encode('utf-8'))
799+
socket.write((f"POST {self.context._abspath('some/path/to/post/to')} HTTP/1.1\r\n").encode('utf-8'))
800+
socket.write((f"Host: {self.context.host}:{self.context.port}\r\n").encode('utf-8'))
806801
socket.write("Accept-Encoding: identity\r\n".encode('utf-8'))
807-
socket.write(("Authorization: %s\r\n" % \
808-
self.context.token).encode('utf-8'))
802+
socket.write((f"Authorization: {self.context.token}\r\n").encode('utf-8'))
809803
socket.write("X-Splunk-Input-Mode: Streaming\r\n".encode('utf-8'))
810804
socket.write("\r\n".encode('utf-8'))
811805
socket.close()
@@ -827,13 +821,10 @@ def test_preexisting_token_sans_splunk(self):
827821
self.assertEqual(response.status, 200)
828822

829823
socket = newContext.connect()
830-
socket.write(("POST %s HTTP/1.1\r\n" % \
831-
self.context._abspath("some/path/to/post/to")).encode('utf-8'))
832-
socket.write(("Host: %s:%s\r\n" % \
833-
(self.context.host, self.context.port)).encode('utf-8'))
824+
socket.write((f"POST {self.context._abspath('some/path/to/post/to')} HTTP/1.1\r\n").encode('utf-8'))
825+
socket.write((f"Host: {self.context.host}:{self.context.port}\r\n").encode('utf-8'))
834826
socket.write("Accept-Encoding: identity\r\n".encode('utf-8'))
835-
socket.write(("Authorization: %s\r\n" % \
836-
self.context.token).encode('utf-8'))
827+
socket.write((f"Authorization: {self.context.token}\r\n").encode('utf-8'))
837828
socket.write("X-Splunk-Input-Mode: Streaming\r\n".encode('utf-8'))
838829
socket.write("\r\n".encode('utf-8'))
839830
socket.close()
@@ -850,13 +841,10 @@ def test_connect_with_preexisting_token_sans_user_and_pass(self):
850841
self.assertEqual(response.status, 200)
851842

852843
socket = newContext.connect()
853-
socket.write(("POST %s HTTP/1.1\r\n" % \
854-
self.context._abspath("some/path/to/post/to")).encode('utf-8'))
855-
socket.write(("Host: %s:%s\r\n" % \
856-
(self.context.host, self.context.port)).encode('utf-8'))
844+
socket.write((f"POST {self.context._abspath('some/path/to/post/to')} HTTP/1.1\r\n").encode('utf-8'))
845+
socket.write((f"Host: {self.context.host}:{self.context.port}\r\n").encode('utf-8'))
857846
socket.write("Accept-Encoding: identity\r\n".encode('utf-8'))
858-
socket.write(("Authorization: %s\r\n" % \
859-
self.context.token).encode('utf-8'))
847+
socket.write((f"Authorization: {self.context.token}\r\n").encode('utf-8'))
860848
socket.write("X-Splunk-Input-Mode: Streaming\r\n".encode('utf-8'))
861849
socket.write("\r\n".encode('utf-8'))
862850
socket.close()
@@ -973,7 +961,7 @@ def check_response(handler):
973961
length = int(handler.headers.get('content-length', 0))
974962
body = handler.rfile.read(length)
975963
assert handler.headers['content-type'] == 'application/x-www-form-urlencoded'
976-
assert body.decode('utf-8') == 'baz=baf&hep=cat' or body.decode('utf-8') == 'hep=cat&baz=baf'
964+
assert body.decode('utf-8') in ['baz=baf&hep=cat', 'hep=cat&baz=baf']
977965

978966
with MockServer(POST=check_response):
979967
ctx = binding.connect(port=9093, scheme='http', token="waffle")

0 commit comments

Comments
 (0)