Permalink
Browse files

new plugin test, and fix to make plugins work

  • Loading branch information...
1 parent eabd74b commit 455d4c4622e87ac4aecfed2b8e4d062f7af453d0 @dsjoerg dsjoerg committed with Mar 11, 2013
Showing with 22 additions and 0 deletions.
  1. +4 −0 sc2reader/plugins/replay.py
  2. +18 −0 test_replays/test_all.py
View
4 sc2reader/plugins/replay.py
@@ -95,6 +95,8 @@ def APMTracker(replay):
else:
player.avg_apm = 0
+ return replay
+
@plugin
def SelectionTracker(replay):
@@ -145,3 +147,5 @@ def SelectionTracker(replay):
person.selection = player_selection
# Not a real lock, so don't change it!
person.selection.locked = True
+
+ return replay
View
18 test_replays/test_all.py
@@ -9,10 +9,23 @@
import sc2reader
from sc2reader.exceptions import ParseError
+from sc2reader.plugins.replay import APMTracker, SelectionTracker
sc2reader.log_utils.log_to_console('INFO')
# Tests for build 17811 replays
+class SC2TestFactory(sc2reader.factories.DoubleCachedSC2Factory):
+ def __init__(self, cache_dir, max_cache_size=0, **options):
+ """cache_dir must be an absolute path, max_cache_size=0 => unlimited"""
+ if not cache_dir:
+ raise ValueError("cache_dir is now required.")
+
+ super(SC2TestFactory, self).__init__(cache_dir, max_cache_size, **options)
+
+ self.register_plugin('Replay',APMTracker())
+ self.register_plugin('Replay',SelectionTracker())
+
+
def test_standard_1v1():
replay = sc2reader.load_replay("test_replays/1.2.2.17811/1.SC2Replay")
@@ -252,3 +265,8 @@ def test_cn_replays():
assert replay.gateway == 'cn'
assert replay.expansion == 'WoL'
+def test_plugins():
+ CACHE_DIR = os.environ.get('GGFACTORY_CACHE_DIR',None)
+ factory = SC2TestFactory(cache_dir=CACHE_DIR)
+ replay = factory.load_replay("test_replays/2.0.5.25092/cn1.SC2Replay")
+

0 comments on commit 455d4c4

Please sign in to comment.