Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 sc2reader/events/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __init__(self, frames, data, build):
self.ff_vespene_lost_technology = clamp(self.stats[38]) if build >= 26490 else None

def __str__(self):
return self._str_prefix() + "{0: >15} - Stats Update".format(self.player)
return self._str_prefix() + "{0: >15} - Stats Update".format(str(self.player))


class UnitBornEvent(TrackerEvent):
Expand Down Expand Up @@ -291,7 +291,7 @@ def __init__(self, frames, data, build):
self.location = (self.x, self.y)

def __str__(self):
return self._str_prefix() + "{0: >15} - Unit born {1}".format(self.unit_upkeeper, self.unit)
return self._str_prefix() + "{0: >15} - Unit born {1}".format(str(self.unit_upkeeper), self.unit)


class UnitDiedEvent(TrackerEvent):
Expand Down Expand Up @@ -361,7 +361,7 @@ def __init__(self, frames, data, build):
self.killing_unit_id = self.killing_unit_index << 18 | self.killing_unit_recycle

def __str__(self):
return self._str_prefix() + "{0: >15} - Unit died {1}.".format(self.unit.owner, self.unit)
return self._str_prefix() + "{0: >15} - Unit died {1}.".format(str(self.unit.owner), self.unit)


class UnitOwnerChangeEvent(TrackerEvent):
Expand Down Expand Up @@ -397,7 +397,7 @@ def __init__(self, frames, data, build):
self.unit_controller = None

def __str__(self):
return self._str_prefix() + "{0: >15} took {1}".format(self.unit_upkeeper, self.unit)
return self._str_prefix() + "{0: >15} took {1}".format(str(self.unit_upkeeper), self.unit)


class UnitTypeChangeEvent(TrackerEvent):
Expand Down Expand Up @@ -425,7 +425,7 @@ def __init__(self, frames, data, build):
self.unit_type_name = data[2].decode('utf8')

def __str__(self):
return self._str_prefix() + "{0: >15} - Unit {0} type changed to {1}".format(self.unit.owner, self.unit, self.unit_type_name)
return self._str_prefix() + "{0: >15} - Unit {0} type changed to {1}".format(str(self.unit.owner), self.unit, self.unit_type_name)


class UpgradeCompleteEvent(TrackerEvent):
Expand All @@ -448,7 +448,7 @@ def __init__(self, frames, data, build):
self.count = data[2]

def __str__(self):
return self._str_prefix() + "{0: >15} - {1}upgrade completed".format(self.player, self.upgrade_type_name)
return self._str_prefix() + "{0: >15} - {1} upgrade completed".format(str(self.player), self.upgrade_type_name)


class UnitInitEvent(TrackerEvent):
Expand Down Expand Up @@ -504,7 +504,7 @@ def __init__(self, frames, data, build):
self.location = (self.x, self.y)

def __str__(self):
return self._str_prefix() + "{0: >15} - Unit initiated {1}".format(self.unit_upkeeper, self.unit)
return self._str_prefix() + "{0: >15} - Unit initiated {1}".format(str(self.unit_upkeeper), self.unit)


class UnitDoneEvent(TrackerEvent):
Expand All @@ -528,7 +528,7 @@ def __init__(self, frames, data, build):
self.unit = None

def __str__(self):
return self._str_prefix() + "{0: >15} - Unit {1} done".format(self.unit.owner, self.unit)
return self._str_prefix() + "{0: >15} - Unit {1} done".format(str(self.unit.owner), self.unit)


class UnitPositionsEvent(TrackerEvent):
Expand Down
14 changes: 14 additions & 0 deletions test_replays/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import unittest2 as unittest
else:
import unittest
# StringIO was changed in python 3
try:
from StringIO import StringIO
except ImportError:
from io import StringIO

import sc2reader
from sc2reader.exceptions import CorruptTrackerFileError
Expand Down Expand Up @@ -582,6 +587,15 @@ def test_65895(self):
factory = sc2reader.factories.SC2Factory()
replay = factory.load_replay(replayfilename)

def test_event_print(self):
replay = sc2reader.load_replay("test_replays/lotv/lotv1.SC2Replay")
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):
class TestEvent(object):
Expand Down