Newer
Older

Thomas Holene Løkkeborg
committed
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
"""Test module that looks for differences in SOI modules across resolutions.
This was written as a regression test for #125. Ideally it should also test the
header of the SOI, but this is much more complicated to test for..
## Important
This test can not test across different resolutions by itself, this is up to
the user. Our pipeline will test across a couple of different resolutions.
"""
import unittest
from PySide2.QtWidgets import QApplication
from PySide2 import QtGui
from PySide2.QtCore import QTimer, Qt
from PySide2.QtTest import QTest
from soitool.soi import SOI
from soitool.modules.module_authentication_board import (
AuthenticationBoardModule,
)
from soitool.modules.module_subtractorcodes import SubtractorcodesModule
from soitool.new_module_dialog import MODULE_CHOICES
if isinstance(QtGui.qApp, type(None)):
app = QApplication([])
else:
app = QtGui.qApp
class TestModulesAcrossResolutions(unittest.TestCase):
"""TestCase for modules across resolutions."""
def test_add_all_modules(self):
"""Add all modules, reorganize, and assert result.
Expected result was gotten by simply running reorganize and noting down
the results. We should get the same result across different
resolutions.
NOTE: This test needs to be updated when a new module is added, or when
one is deleted. It will fail until it is updated.
"""
expected_result = [
{"x": 0, "y": 0, "page": 1, "name": "AuthenticationBoardModule"},
{"x": 407.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"},
{"x": 633.0, "y": 0, "page": 1, "name": "FreeTextModule"},
{"x": 733.0, "y": 0, "page": 1, "name": "TableModule"},
]
def press_enter():
active_widget = app.activeModalWidget()
QTest.keyClick(active_widget, Qt.Key_Enter)
soi = SOI()
for module in MODULE_CHOICES:
# If we're adding one of the modules with a popup as part of it's
# constructor we need to singleShot pressing enter to close it
if module in (AuthenticationBoardModule, SubtractorcodesModule):
QTimer.singleShot(0, press_enter)
soi.add_module(module.__name__, module())
soi.reorganize()
self.assertEqual(
expected_result, [module["meta"] for module in soi.modules],
)