Skip to content

Commit b21d45e

Browse files
authored
Merge pull request #64 from StoicLoofah/63-trackerevent_str_error
#63 cast players in TrackerEvent.__str__
2 parents 7c00c4a + f16dddd commit b21d45e

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

sc2reader/events/tracker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def __init__(self, frames, data, build):
230230
self.ff_vespene_lost_technology = clamp(self.stats[38]) if build >= 26490 else None
231231

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

235235

236236
class UnitBornEvent(TrackerEvent):
@@ -291,7 +291,7 @@ def __init__(self, frames, data, build):
291291
self.location = (self.x, self.y)
292292

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

296296

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

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

366366

367367
class UnitOwnerChangeEvent(TrackerEvent):
@@ -397,7 +397,7 @@ def __init__(self, frames, data, build):
397397
self.unit_controller = None
398398

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

402402

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

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

430430

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

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

453453

454454
class UnitInitEvent(TrackerEvent):
@@ -504,7 +504,7 @@ def __init__(self, frames, data, build):
504504
self.location = (self.x, self.y)
505505

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

509509

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

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

533533

534534
class UnitPositionsEvent(TrackerEvent):

test_replays/test_all.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import unittest2 as unittest
1212
else:
1313
import unittest
14+
# StringIO was changed in python 3
15+
try:
16+
from StringIO import StringIO
17+
except ImportError:
18+
from io import StringIO
1419

1520
import sc2reader
1621
from sc2reader.exceptions import CorruptTrackerFileError
@@ -582,6 +587,15 @@ def test_65895(self):
582587
factory = sc2reader.factories.SC2Factory()
583588
replay = factory.load_replay(replayfilename)
584589

590+
def test_event_print(self):
591+
replay = sc2reader.load_replay("test_replays/lotv/lotv1.SC2Replay")
592+
sys.stdout = capturedOutput = StringIO()
593+
for event in replay.events:
594+
print(event)
595+
self.assertIn("PlayerLeaveEvent", capturedOutput.getvalue())
596+
sys.stdout = sys.__stdout__
597+
capturedOutput.close()
598+
585599

586600
class TestGameEngine(unittest.TestCase):
587601
class TestEvent(object):

0 commit comments

Comments
 (0)