Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test_replays/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import unittest
# StringIO was changed in python 3
try:
from io import StringIO
except ImportError:
from StringIO import StringIO
except ImportError:
from io import StringIO

import sc2reader
from sc2reader.exceptions import CorruptTrackerFileError
Expand Down Expand Up @@ -589,12 +589,12 @@ def test_65895(self):

def test_event_print(self):
replay = sc2reader.load_replay("test_replays/lotv/lotv1.SC2Replay")
with StringIO() as capturedOutput:
sys.stdout = capturedOutput
for event in replay.events:
print(event)
self.assertIn("PlayerLeaveEvent", capturedOutput.getvalue())
sys.stdout = sys.__stdout__
sys.stdout = capturedOutput = StringIO()
Copy link
Collaborator

@cclauss cclauss Nov 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original with open() as form is safer in the face of exceptions... Was there a reason to move away from that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringIO.StringIO does not implement exit() I believe and can not be used with with() in python2. io.StringIO does and is what is being used in Python3 so could be used with with().

for event in replay.events:
print(event)
self.assertIn("PlayerLeaveEvent", capturedOutput.getvalue())
sys.stdout = sys.__stdout__
capturedOutput.close()


class TestGameEngine(unittest.TestCase):
Expand Down