Skip to content

Commit f758325

Browse files
committed
new plugin test, and fix to make plugins work
1 parent cba5eab commit f758325

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

sc2reader/plugins/replay.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def APMTracker(replay):
9595
else:
9696
player.avg_apm = 0
9797

98+
return replay
99+
98100

99101
@plugin
100102
def SelectionTracker(replay):
@@ -145,3 +147,5 @@ def SelectionTracker(replay):
145147
person.selection = player_selection
146148
# Not a real lock, so don't change it!
147149
person.selection.locked = True
150+
151+
return replay

test_replays/test_all.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99

1010
import sc2reader
1111
from sc2reader.exceptions import ParseError
12+
from sc2reader.plugins.replay import APMTracker, SelectionTracker
1213

1314
sc2reader.log_utils.log_to_console('INFO')
1415
# Tests for build 17811 replays
1516

17+
class SC2TestFactory(sc2reader.factories.DoubleCachedSC2Factory):
18+
def __init__(self, cache_dir, max_cache_size=0, **options):
19+
"""cache_dir must be an absolute path, max_cache_size=0 => unlimited"""
20+
if not cache_dir:
21+
raise ValueError("cache_dir is now required.")
22+
23+
super(SC2TestFactory, self).__init__(cache_dir, max_cache_size, **options)
24+
25+
self.register_plugin('Replay',APMTracker())
26+
self.register_plugin('Replay',SelectionTracker())
27+
28+
1629
def test_standard_1v1():
1730
replay = sc2reader.load_replay("test_replays/1.2.2.17811/1.SC2Replay")
1831

@@ -251,3 +264,8 @@ def test_cn_replays():
251264
replay = sc2reader.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")
252265
assert replay.gateway == 'cn'
253266
assert replay.expansion == 'WoL'
267+
268+
def test_plugins():
269+
CACHE_DIR = os.environ.get('GGFACTORY_CACHE_DIR',None)
270+
factory = SC2TestFactory(cache_dir=CACHE_DIR)
271+
replay = factory.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")

0 commit comments

Comments
 (0)