Skip to content

Commit 2191721

Browse files
committed
Merge branch 'jsanders'
2 parents 3d83f82 + 8c5bc64 commit 2191721

File tree

7 files changed

+34
-35
lines changed

7 files changed

+34
-35
lines changed

profile.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ def parse_replays():
2121
replay = Replay(file)
2222

2323
# Problem with the profiler is that it adds conciderable amount of overhead
24-
cProfile.run("parse_replays()","replay_profile")
25-
stats = Stats("replay_profile")
26-
stats.strip_dirs().sort_stats("time").print_stats(30)
24+
# cProfile.run("parse_replays()","replay_profile")
25+
# stats = Stats("replay_profile")
26+
# stats.strip_dirs().sort_stats("time").print_stats(30)
2727

28-
# start = time.time()
29-
# for run in range(1,4):
30-
# parse_replays()
31-
# end = time.time() - start
32-
# print end
28+
start = time.time()
29+
parse_replays()
30+
diff = time.time() - start
31+
print diff
3332

3433
# ========================================
3534
# Results for March 1 2011

sc2reader/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class PlayerDict(dict):
22
"""Delete is supported on the pid index only"""
3-
def __init__(self,*args,**kwargs):
3+
def __init__(self, *args, **kwargs):
44
self._key_map = dict()
55

66
if args:
@@ -10,27 +10,27 @@ def __init__(self,*args,**kwargs):
1010

1111
if kwargs:
1212
print kwargs
13-
for key,value in kwargs.iteritems():
13+
for key, value in kwargs.iteritems():
1414
self[key] = value
1515

16-
def __getitem__(self,key):
17-
if isinstance(key,str):
16+
def __getitem__(self, key):
17+
if isinstance(key, str):
1818
key = self._key_map[key]
1919

20-
return super(PlayerDict,self).__getitem__(key)
20+
return super(PlayerDict, self).__getitem__(key)
2121

22-
def __setitem__(self,key,value):
23-
if isinstance(key,str):
22+
def __setitem__(self, key, value):
23+
if isinstance(key, str):
2424
self._key_map[key] = value.pid
2525
key = value.pid
26-
elif isinstance(key,int):
26+
elif isinstance(key, int):
2727
self._key_map[value.name] = key
2828

29-
super(PlayerDict,self).__setitem__(value.pid,value)
29+
super(PlayerDict, self).__setitem__(value.pid, value)
3030

3131

3232
from cStringIO import StringIO
33-
from os import SEEK_CUR,SEEK_END
33+
from os import SEEK_CUR, SEEK_END
3434
from struct import unpack
3535

3636
class ByteStream(object):

test_replays/build17811/info.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1.sc2replay
1+
1.SC2Replay
22
Date played 20 Feb 2011 22:44:48
33
Duration 32:47
44
Region/Realm EU
@@ -27,7 +27,7 @@ Messages (count=12):
2727
Boom [All]: huh?
2828

2929

30-
2.sc2replay
30+
2.SC2Replay
3131
Date played 21 Feb 2011 00:42:13
3232
Duration 9:09
3333
Region/Realm EU
@@ -45,7 +45,7 @@ Messages (count=1):
4545
Laquendi [All]: gg
4646

4747

48-
3.sc2replay
48+
3.SC2Replay
4949
Date played 25 Feb 2011 16:36:28
5050
Duration 10:29
5151
Region/Realm EU
@@ -64,4 +64,4 @@ Players (no observers)
6464
Foco Terran
6565
Messages (count=25):
6666
First msg: loropendejo [Allies]: hi
67-
Last msg: Aspirates [Allies]: all team goo
67+
Last msg: Aspirates [Allies]: all team goo

test_replays/test_all.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def test_empty():
1515
# Maybe a "production" mode would be nice to have, so that it simply returns a status of the parse without
1616
# raising an exception.
1717
with pytest.raises(ValueError):
18-
Replay("test_replays/corrupted/empty.sc2replay")
18+
Replay("test_replays/corrupted/empty.SC2Replay")
1919

2020
# Tests for build 17811 replays
2121

2222
def test_standard_1v1():
23-
replay = Replay("test_replays/build17811/1.sc2replay")
23+
replay = Replay("test_replays/build17811/1.SC2Replay")
2424

2525
# assert replay.date == "20 Feb 2011 22:44:48"
2626
assert replay.length == (32, 47)
@@ -88,28 +88,28 @@ def test_standard_1v1():
8888
assert msg.sent_to_all == True
8989

9090
def test_private_category():
91-
replay = Replay("test_replays/build17811/2.sc2replay")
91+
replay = Replay("test_replays/build17811/2.SC2Replay")
9292
assert replay.is_private == True
9393
assert replay.is_ladder == False
9494

9595
def test_2v2():
96-
replay = Replay("test_replays/build17811/7.sc2replay")
96+
replay = Replay("test_replays/build17811/7.SC2Replay")
9797
assert replay.type == "2v2"
9898

9999
def test_3v3():
100-
replay = Replay("test_replays/build17811/3.sc2replay")
100+
replay = Replay("test_replays/build17811/3.SC2Replay")
101101
assert replay.type == "3v3"
102102

103103
# Because it's a 3v3 and all of the members of Team 2 quit, we should know the winner.
104104
assert replay.results[1] == "Won"
105105
assert replay.results[2] == "Lost"
106106

107107
def test_4v4():
108-
replay = Replay("test_replays/build17811/9.sc2replay")
108+
replay = Replay("test_replays/build17811/9.SC2Replay")
109109
assert replay.type == "4v4"
110110

111111
def test_ffa():
112-
replay = Replay("test_replays/build17811/8.sc2replay")
112+
replay = Replay("test_replays/build17811/8.SC2Replay")
113113
assert replay.type == "FFA"
114114

115115
# TODO: Remove me when done!
@@ -122,37 +122,37 @@ def test_ffa():
122122
assert replay.winner_known == False
123123

124124
def test_unknown_winner():
125-
replay = Replay("test_replays/build17811/10.sc2replay")
125+
replay = Replay("test_replays/build17811/10.SC2Replay")
126126

127127
# Recording player (Boom) left second in a 4v4, so the winner shouldn't be known
128128
assert replay.winner_known == False
129129

130130
def test_random_player():
131-
replay = Replay("test_replays/build17811/3.sc2replay")
131+
replay = Replay("test_replays/build17811/3.SC2Replay")
132132

133133
gogeta = replay.player['Gogeta']
134134
assert gogeta.choosen_race == "Random"
135135
assert gogeta.actual_race == "Terran"
136136

137137
def test_random_player2():
138-
replay = Replay("test_replays/build17811/6.sc2replay")
138+
replay = Replay("test_replays/build17811/6.SC2Replay")
139139
permafrost = replay.player["Permafrost"]
140140
assert permafrost.choosen_race == "Random"
141141
assert permafrost.actual_race == "Protoss"
142142

143143
def test_us_realm():
144-
replay = Replay("test_replays/build17811/5.sc2replay")
144+
replay = Replay("test_replays/build17811/5.SC2Replay")
145145
assert replay.player['ShadesofGray'].url == "http://us.battle.net/sc2/en/profile/2358439/1/ShadesofGray/"
146146
assert replay.player['reddawn'].url == "http://us.battle.net/sc2/en/profile/2198663/1/reddawn/"
147147

148148
# We can be really proud: phpsc2replay fails with the messages!
149149
def test_kr_realm_and_tampered_messages():
150-
replay = Replay("test_replays/build17811/11.sc2replay")
150+
replay = Replay("test_replays/build17811/11.SC2Replay")
151151
assert replay.player['명지대학교'].url == "http://kr.battle.net/sc2/en/profile/258945/1/명지대학교/"
152152
assert replay.player['티에스엘사기수'].url == "http://kr.battle.net/sc2/en/profile/102472/1/티에스엘사기수/"
153153

154154
assert replay.messages[0].text == "sc2.replays.net"
155155
assert replay.messages[5].text == "sc2.replays.net"
156156

157157
def test_encrypted():
158-
replay = Replay("test_replays/build17811/4.sc2replay")
158+
replay = Replay("test_replays/build17811/4.SC2Replay")

0 commit comments

Comments
 (0)