File: test_internal.py

package info (click to toggle)
unknown-horizons 2019.1-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 347,924 kB
  • sloc: python: 46,805; xml: 3,137; sql: 1,189; sh: 736; makefile: 39; perl: 35
file content (122 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# ###################################################
# Copyright (C) 2008-2017 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
# ###################################################

import functools
import os

import pytest

from horizons.scheduler import Scheduler
from tests.gui import gui_test


@gui_test(use_dev_map=True)
def test_trivial(gui):
	"""Does nothing to see if test setup works."""
	pass


@gui_test(use_dev_map=True, _user_dir=os.path.join("test_settings", ".unknown-horizons"))
def test_update_settings(gui):
	"""Does nothing to see if the settings update works."""
	pass


@gui_test(use_dev_map=True)
def test_run_for_x_seconds(gui):
	"""Test that running the game X seconds works."""

	start_tick = Scheduler().cur_tick
	gui.run(seconds=20)
	difference = Scheduler().cur_tick - start_tick

	expected = Scheduler().get_ticks(20)

	deviation = (difference - expected) / difference
	assert deviation < 0.05, 'Expected max 0.05 deviation, got {}'.format(deviation)


@gui_test(use_fixture='boatbuilder')
def test_trigger(gui):
	"""Test the different ways to trigger an action in a gui."""

	assert not gui.find('captains_log')

	# Specify event name and group name
	gui.trigger('mainhud/logbook', 'action/default')
	assert gui.find('captains_log')
	gui.trigger('captains_log/okButton', 'action/default')
	assert not gui.find('captains_log')

	# Leave out group name
	gui.trigger('mainhud/logbook', 'action')
	assert gui.find('captains_log')
	gui.trigger('captains_log/okButton', 'action')
	assert not gui.find('captains_log')

	# Leave out event name
	gui.trigger('mainhud/logbook')
	assert gui.find('captains_log')
	gui.trigger('captains_log/okButton')
	assert not gui.find('captains_log')

	# Select mainsquare and show production overview to test
	# if mouseClicked and action are handled the same
	assert not gui.find('production_overview')

	gui.cursor_click(53, 12, 'left')
	gui.trigger('tab_account/show_production_overview', 'mouseClicked')
	assert gui.find('production_overview')
	gui.trigger('production_overview/okButton', 'action')
	assert not gui.find('production_overview')

	# Leave out event name, it will try action at first and fallback
	# to mouseClicked
	gui.trigger('tab_account/show_production_overview')
	assert gui.find('production_overview')
	gui.trigger('production_overview/okButton')
	assert not gui.find('production_overview')


@gui_test(timeout=60)
def test_dialog(gui):
	"""Test handling of a dialog."""

	assert not gui.find('popup_window')

	def func():
		assert gui.find('popup_window')
		gui.trigger('popup_window/okButton')

	with gui.handler(func):
		gui.trigger('menu/quit_button')


@pytest.mark.xfail(strict=True)
@gui_test(timeout=60)
def test_failing(gui):
	"""
	Test whether a failure of the test is correctly detected.

	NOTE: We're using XFAIL here, since the failure of the test is expected. If suddenly this
	test passes, the test suite will fail.
	"""
	1 / 0