Skip to content

Commit 81aca14

Browse files
committed
Added some tests and a few build17811 replays
1 parent d16fead commit 81aca14

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed
70.7 KB
Binary file not shown.
15.8 KB
Binary file not shown.
35 KB
Binary file not shown.

test_replays/build17811/info.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
1.sc2replay
2+
Date played 20 Feb 2011 22:44:48
3+
Duration 32:47
4+
Region/Realm EU
5+
Type 1v1 Melee Quick Match
6+
Map Lost Temple
7+
Gamespeed Faster
8+
Winner Emperor (Team 1) .. reason: Boom quits
9+
Recorder Boom
10+
Players (no observers)
11+
Team 1
12+
Emperor Protoss
13+
Team 2
14+
Boom Terran
15+
Messages (count=12):
16+
Emperor [All]: hf
17+
Boom [All]: HEYA
18+
Boom [All]: gl hf
19+
Boom [All]: sry for caps
20+
Emperor [All]: ^^
21+
Emperor [All]: noppe
22+
Boom [All]: you greedy bastard
23+
Boom [All]: ggg
24+
Emperor [All]: WG
25+
Boom [All]: wg? :)
26+
Emperor [All]: wipe
27+
Boom [All]: huh?
28+
29+
30+
2.sc2replay
31+
Date played 21 Feb 2011 00:42:13
32+
Duration 9:09
33+
Region/Realm EU
34+
Type 1v1 Custom
35+
Map Lost Temple
36+
Gamespeed Faster
37+
Winner Boom (Team 1) .. reason: Laquendi quits
38+
Players (no observers)
39+
Team 1
40+
Laquendi Protoss
41+
Team 2
42+
Boom Terran
43+
44+
Messages (count=1):
45+
Laquendi [All]: gg
46+
47+
48+
3.sc2replay
49+
Date played 25 Feb 2011 16:36:28
50+
Duration 10:29
51+
Region/Realm EU
52+
Type 3v3 Melee Random Quick Match
53+
Map Monsoon
54+
Gamespeed Faster
55+
Winner Team1, reason: all members of other team quit
56+
Players (no observers)
57+
Team 1
58+
Boom Terran
59+
Aspirates Terran
60+
loropendejo Terran
61+
Team 2
62+
SNIPER Terran
63+
Gogeta Random Terran
64+
Foco Terran
65+
Messages (count=25):
66+
First msg: loropendejo [Allies]: hi
67+
Last msg: Aspirates [Allies]: all team goo

test_replays/corrupted/empty.sc2replay

Whitespace-only changes.

test_replays/test_all.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Note: Chose pytest over unittest(2) because of cleaner and more lightweight syntax.
2+
# Run tests with "py.test"
3+
4+
# TODO:
5+
# - Performance tests to measure the effect of optimizations
6+
import os
7+
import pytest
8+
9+
from sc2reader import Replay
10+
from sc2reader.exceptions import ParseError
11+
12+
# Helper functions
13+
def sent_to_all(msg):
14+
return msg.target == 0
15+
16+
def find(f, seq):
17+
for item in seq:
18+
if f(item):
19+
return item
20+
21+
22+
# Parsing should fail for an empty file.
23+
def test_empty():
24+
# Todo: Are we happy with it raising a ValueError? Should it be rather ParseError or something else?
25+
# Maybe a "production" mode would be nice to have, so that it simply returns a status of the parse without
26+
# raising an exception.
27+
with pytest.raises(ValueError):
28+
Replay("test_replays/corrupted/empty.sc2replay")
29+
30+
# Tests for build 17811 replays
31+
32+
# TODO: Realm/region functionality is missing!
33+
def test_1():
34+
replay = Replay("test_replays/build17811/1.sc2replay")
35+
36+
assert replay.date == "20 Feb 2011 22:44:48"
37+
assert replay.length == (32, 47)
38+
assert replay.map == "Lost Temple"
39+
assert replay.build == 17811
40+
assert replay.releaseString == "1.2.2.17811"
41+
assert replay.speed == "Faster"
42+
assert replay.type == "1v1"
43+
44+
assert len(replay.players) == 2
45+
emperor = find(lambda player: player.name == "Emperor", replay.players)
46+
assert emperor.team == 1
47+
assert emperor.race == "Protoss"
48+
assert emperor.recorder == False
49+
50+
boom = find(lambda player: player.name == "Boom", replay.players)
51+
assert boom.team == 2
52+
assert boom.race == "Terran"
53+
assert boom.recorder == True
54+
55+
for player in replay.players:
56+
assert player.type == "Human"
57+
58+
# Because it is a 1v1 and the recording player quit, we should know the winner.
59+
assert emperor.result == "Win"
60+
assert boom.result == "Lost"
61+
62+
assert emperor.url == "http://eu.battle.net/sc2/en/profile/520049/1/Emperor/"
63+
assert boom.url == "http://eu.battle.net/sc2/en/profile/1694745/1/Boom/"
64+
65+
assert len(replay.messages) == 12
66+
assert find(lambda player: player.pid == replay.messages[0].player, replay.players).name == "Emperor"
67+
assert replay.messages[0].text == "hf"
68+
assert replay.messages[1].text == "HEYA"
69+
assert replay.messages[2].text == "gl hf"
70+
assert replay.messages[3].text == "sry for caps"
71+
assert replay.messages[4].text == "^^"
72+
assert replay.messages[5].text == "noppe"
73+
assert replay.messages[6].text == "you greedy bastard"
74+
assert replay.messages[7].text == "ggg"
75+
assert replay.messages[8].text == "WG"
76+
assert replay.messages[9].text == "wg? :)"
77+
assert replay.messages[10].text == "wipe"
78+
assert replay.messages[11].text == "huh?"
79+
assert find(lambda player: player.pid == replay.messages[11].player, replay.players).name == "Boom"
80+
81+
for msg in replay.messages:
82+
assert sent_to_all(msg) == true

0 commit comments

Comments
 (0)