From 8c9072873dadbaae4f78c64aa86349e2ea57addb Mon Sep 17 00:00:00 2001 From: Gus Foley Date: Fri, 2 Nov 2018 00:18:42 -0700 Subject: [PATCH] Fix Python 2 issues with test_event_print. Logic issue with conditional import. StringIO.StringIO does not support usage of the with keyword. --- test_replays/test_all.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test_replays/test_all.py b/test_replays/test_all.py index 5d1f2c93..1667fe1a 100644 --- a/test_replays/test_all.py +++ b/test_replays/test_all.py @@ -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 @@ -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() + for event in replay.events: + print(event) + self.assertIn("PlayerLeaveEvent", capturedOutput.getvalue()) + sys.stdout = sys.__stdout__ + capturedOutput.close() class TestGameEngine(unittest.TestCase):