Skip to content

Commit dba8d99

Browse files
committed
Python 3.x compatibility for test_internals_v1
1 parent 68d2532 commit dba8d99

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tests/searchcommands/test_internals_v1.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from splunklib.searchcommands.search_command import SearchCommand
2424

2525
from contextlib import closing
26-
from splunklib.six.moves import cStringIO as StringIO
26+
from splunklib.six import StringIO, BytesIO
2727

2828
try:
2929
from itertools import izip # python 2
@@ -232,7 +232,10 @@ def test_input_header(self):
232232

233233
input_header = InputHeader()
234234

235-
with closing(StringIO('\r\n'.encode())) as input_file:
235+
print("String: %s" % type('\r\n'))
236+
print("Encode: %s" % type('\r\n'.encode()))
237+
238+
with closing(StringIO('\r\n')) as input_file:
236239
input_header.read(input_file)
237240

238241
self.assertEqual(len(input_header), 0)
@@ -241,14 +244,14 @@ def test_input_header(self):
241244

242245
input_header = InputHeader()
243246

244-
with closing(StringIO('this%20is%20an%20unnamed%20single-line%20item\n\n'.encode())) as input_file:
247+
with closing(StringIO('this%20is%20an%20unnamed%20single-line%20item\n\n')) as input_file:
245248
input_header.read(input_file)
246249

247250
self.assertEqual(len(input_header), 0)
248251

249252
input_header = InputHeader()
250253

251-
with closing(StringIO('this%20is%20an%20unnamed\nmulti-\nline%20item\n\n'.encode())) as input_file:
254+
with closing(StringIO('this%20is%20an%20unnamed\nmulti-\nline%20item\n\n')) as input_file:
252255
input_header.read(input_file)
253256

254257
self.assertEqual(len(input_header), 0)
@@ -257,15 +260,15 @@ def test_input_header(self):
257260

258261
input_header = InputHeader()
259262

260-
with closing(StringIO('Foo:this%20is%20a%20single-line%20item\n\n'.encode())) as input_file:
263+
with closing(StringIO('Foo:this%20is%20a%20single-line%20item\n\n')) as input_file:
261264
input_header.read(input_file)
262265

263266
self.assertEqual(len(input_header), 1)
264267
self.assertEqual(input_header['Foo'], 'this is a single-line item')
265268

266269
input_header = InputHeader()
267270

268-
with closing(StringIO('Bar:this is a\nmulti-\nline item\n\n'.encode())) as input_file:
271+
with closing(StringIO('Bar:this is a\nmulti-\nline item\n\n')) as input_file:
269272
input_header.read(input_file)
270273

271274
self.assertEqual(len(input_header), 1)
@@ -275,7 +278,7 @@ def test_input_header(self):
275278

276279
input_header = InputHeader()
277280

278-
with closing(StringIO('infoPath:non-existent.csv\n\n'.encode())) as input_file:
281+
with closing(StringIO('infoPath:non-existent.csv\n\n')) as input_file:
279282
input_header.read(input_file)
280283

281284
self.assertEqual(len(input_header), 1)
@@ -293,14 +296,14 @@ def test_input_header(self):
293296
input_header = InputHeader()
294297
text = reduce(lambda value, item: value + '{}:{}\n'.format(item[0], item[1]), six.iteritems(collection), '') + '\n'
295298

296-
with closing(StringIO(text.encode())) as input_file:
299+
with closing(StringIO(text)) as input_file:
297300
input_header.read(input_file)
298301

299302
self.assertDictEqual(input_header, collection)
300303

301304
# Set of named items with an unnamed item at the beginning (the only place that an unnamed item can appear)
302305

303-
with closing(StringIO(('unnamed item\n' + text).encode())) as input_file:
306+
with closing(StringIO('unnamed item\n' + text)) as input_file:
304307
input_header.read(input_file)
305308

306309
self.assertDictEqual(input_header, collection)
@@ -325,7 +328,7 @@ def fix_up(cls, command_class): pass
325328

326329
command = TestMessagesHeaderCommand()
327330
command._protocol_version = 1
328-
output_buffer = StringIO()
331+
output_buffer = BytesIO()
329332
command._record_writer = RecordWriterV1(output_buffer)
330333

331334
messages = [
@@ -348,7 +351,7 @@ def fix_up(cls, command_class): pass
348351
'warn_message=warning_message\r\n'
349352
'\r\n')
350353

351-
self.assertEqual(output_buffer.getvalue(), expected)
354+
self.assertEqual(output_buffer.getvalue().decode('utf-8'), expected)
352355
return
353356

354357
_package_path = os.path.dirname(__file__)

0 commit comments

Comments
 (0)