Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests: helper functions for scenario tests

  • Loading branch information...
commit 38fff05df6b9517f0855b430d1867a698a8f1a98 1 parent a4f7c73
Reiner Gerecke squiddy authored
35 tests/gui/scenarios/helper.py
View
@@ -0,0 +1,35 @@
+# ###################################################
+# Copyright (C) 2012 The Unknown Horizons Team
+# team@unknown-horizons.org
+# This file is part of Unknown Horizons.
+#
+# Unknown Horizons is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# ###################################################
+
+def assert_win(gui):
+ """Returns once the scenario was won."""
+ while True:
+ if getattr(gui.session, '_scenariotest_won', False):
+ break
+ yield
+
+
+def assert_defeat(gui):
+ """Returns once the scenario was lost."""
+ while True:
+ if getattr(gui.session, '_scenariotest_lose', False):
+ break
+ yield
11 tests/gui/scenarios/test_simple.py
View
@@ -22,6 +22,7 @@
from horizons.scenario import ACTIONS
from tests.gui import gui_test, TestFinished
+from tests.gui.scenarios.helper import assert_win, assert_defeat
# Patch scenario actions for easier detection
@@ -41,20 +42,14 @@ def do_lose(session):
@gui_test(use_scenario='tests/gui/scenarios/win', timeout=10)
def test_win(gui):
"""Simple test that detects a win in a game."""
- while True:
- if getattr(gui.session, '_scenariotest_won', False):
- break
- yield
+ for _ in assert_win(gui): yield
yield TestFinished
@gui_test(use_scenario='tests/gui/scenarios/defeat', timeout=10)
def test_defeat(gui):
"""Simple test that detects a defeat in a game."""
- while True:
- if getattr(gui.session, '_scenariotest_lose', False):
- break
- yield
+ for _ in assert_defeat(gui): yield
yield TestFinished
Please sign in to comment.
Something went wrong with that request. Please try again.