Skip to content

Commit 7215284

Browse files
committed
added a couple of tests, trying to bypass the listfile
1 parent d240ef3 commit 7215284

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

sc2reader/replay.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ def __init__(self, replay, partial_parse=True, full_parse=True):
5555

5656
#Always parse the header first, the extract the files
5757
self._parse_header()
58-
#Extract the available file from the MPQArchive
59-
self._files = MPQArchive(replay).extract()
60-
58+
59+
#Manually extract the contents of SC2Replay file (bypass the listfile)
60+
archive = MPQArchive(replay, False)
61+
self._files['replay.initData'] = archive.read('replay.initData')
62+
self._files['replay.details'] = archive.read('replay.details')
63+
self._files['replay.attributes.events'] = archive.read('replay.attributes.events')
64+
self._files['replay.message.events'] = archive.read('replay.message.events')
65+
self._files['replay.game.events'] = archive.read('replay.game.events')
66+
6167
#These are quickly parsed files that contain most of the game information
6268
#The order is important, I need some way to reinforce it in the future
6369
if partial_parse or full_parse:
111 KB
Binary file not shown.
259 KB
Binary file not shown.

test_replays/test_all.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_empty():
1818

1919
# Tests for build 17811 replays
2020

21-
def test_1():
21+
def test_standard_1v1():
2222
replay = Replay("test_replays/build17811/1.sc2replay")
2323

2424
# assert replay.date == "20 Feb 2011 22:44:48"
@@ -106,16 +106,24 @@ def test_3v3():
106106
assert replay.results[1] == "Won"
107107
assert replay.results[2] == "Lost"
108108

109+
def test_4v4():
110+
# Source: http://drop.sc/32
111+
replay = Replay("test_replays/build17811/9.sc2replay")
112+
assert replay.type == "4v4"
113+
114+
def test_ffa():
115+
# Source: http://drop.sc/83
116+
replay = Replay("test_replays/build17811/8.sc2replay")
117+
assert replay.type == "FFA"
118+
assert replay.player['Boom'].result = "Won"
109119

110120
def test_random_player():
111121
replay = Replay("test_replays/build17811/3.sc2replay")
112122

113123
gogeta = replay.player['Gogeta']
114124
assert gogeta.choosen_race == "Random"
115125
assert gogeta.actual_race == "Terran"
116-
117-
# Ha! This was actually failing with phpsc2replay! (Didn't produce the right Random race)
118-
# Hooray, major milestone as phpsc2replay isn't a superset of sc2readera anymore!
126+
119127
def test_random_player2():
120128
replay = Replay("test_replays/build17811/6.sc2replay")
121129
permafrost = replay.player["Permafrost"]
@@ -132,4 +140,4 @@ def test_us_realm():
132140
def test_encrypted():
133141
replay = Replay("test_replays/build17811/4.sc2replay")
134142

135-
#TODO: Test 2v2, 4v4 and FFA
143+
# TODO: Test with a 2v2, 3v3 or 4v4 replay, where the recording player quits first (should be marked as unknown)

0 commit comments

Comments
 (0)