Skip to content

Commit 20698e7

Browse files
author
Shakeel Mohamed
committed
search commands tests: fix opening files on Windows
1 parent 1e96699 commit 20698e7

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

‎tests/searchcommands/test_examples.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from json import JSONEncoder
2424
from subprocess import Popen
2525
import os
26+
import io
2627
import shutil
2728
from tests import testlib
2829

@@ -330,7 +331,7 @@ def test_generating_command_as_unit(self):
330331
dispatch(simulate.SimulateCommand, cli_args, instream, outstream,
331332
"__main__")
332333
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_generating_command_in_isolation.getinfo.csv')
333-
self.assertEqual(open(os.path.abspath(expected_info_path)).read(), outstream.getvalue())
334+
self.assertEqual(io.open(os.path.abspath(expected_info_path), newline='').read(), outstream.getvalue())
334335

335336
instream = StringIO()
336337
outstream = StringIO()
@@ -380,7 +381,7 @@ def test_helloworld_generating_command_as_unit(self):
380381
dispatch(helloworld.GenerateHelloCommand, cli_args, instream, outstream,
381382
"__main__")
382383
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_generating_command_in_isolation.getinfo.csv')
383-
self.assertEqual(open(os.path.abspath(expected_info_path)).read(), outstream.getvalue())
384+
self.assertEqual(io.open(os.path.abspath(expected_info_path), newline='').read(), outstream.getvalue())
384385

385386
# Overwrite the existing StringIO objects
386387
instream = StringIO()
@@ -485,7 +486,7 @@ def test_reporting_command_as_unit(self):
485486

486487
# Map tests
487488

488-
instream = StringIO(open(os.path.join(os.path.dirname(__file__), "data", "input", "counts.csv")).read())
489+
instream = StringIO(io.open(os.path.join(os.path.dirname(__file__), "data", "input", "counts.csv"), newline='').read())
489490
outstream = StringIO()
490491
cli_args = [
491492
"sum.py",
@@ -497,7 +498,7 @@ def test_reporting_command_as_unit(self):
497498
# Run the process
498499
dispatch(sum_module.SumCommand, cli_args, instream, outstream, "__main__")
499500
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_reporting_command_in_isolation.map.getinfo.csv')
500-
self.assertEqual(open(expected_info_path).read(), outstream.getvalue())
501+
self.assertEqual(io.open(expected_info_path, newline='').read(), outstream.getvalue())
501502

502503
# Overwrite the existing StringIO objects
503504
instream = StringIO(open(os.path.join(os.path.dirname(__file__), "data", "input",
@@ -515,7 +516,7 @@ def test_reporting_command_as_unit(self):
515516
"__main__")
516517

517518
expected_exec_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_reporting_command_in_isolation.map.execute.csv')
518-
self.assertEqual(open(expected_exec_path).read(), outstream.getvalue())
519+
self.assertEqual(io.open(expected_exec_path, newline='').read(), outstream.getvalue())
519520

520521
# Trim the blank lines at either end of the list
521522
rows = outstream.getvalue().split("\r\n")[1:-1]
@@ -545,7 +546,7 @@ def test_reporting_command_as_unit(self):
545546
dispatch(sum_module.SumCommand, cli_args, instream, outstream, "__main__")
546547
expected_info_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_reporting_command_in_isolation.reduce.getinfo.csv')
547548

548-
self.assertEqual(open(expected_info_path).read(), outstream.getvalue())
549+
self.assertEqual(io.open(expected_info_path, newline='').read(), outstream.getvalue())
549550

550551
# Overwrite the existing StringIO objects
551552
instream = StringIO(open(os.path.join(os.path.dirname(__file__), "data", "input",
@@ -562,7 +563,7 @@ def test_reporting_command_as_unit(self):
562563
dispatch(sum_module.SumCommand, cli_args, instream, outstream,
563564
"__main__")
564565
expected_exec_path = os.path.join(os.path.dirname(__file__), 'data/_expected_results/test_reporting_command_in_isolation.reduce.execute.csv')
565-
self.assertEqual(open(expected_exec_path).read(), outstream.getvalue())
566+
self.assertEqual(io.open(expected_exec_path, newline='').read(), outstream.getvalue())
566567

567568
# Trim the blank lines at either end of the list
568569
rows = outstream.getvalue().split("\r\n")[1:-1]
@@ -665,7 +666,7 @@ def _getOneshotResults(self, query, test_name):
665666
elif isinstance(result, Message):
666667
actual += [u'Message: %s' % result]
667668
actual += [u'is_preview = %s' % reader.is_preview]
668-
actual = u'\n'.join(actual)
669+
actual = (os.linesep).join(actual)
669670
with TestSearchCommandsApp._open_data_file(
670671
'_expected_results/%s.txt' % test_name,
671672
'r') as expected_file:

0 commit comments

Comments
 (0)