Skip to content
Snippets Groups Projects
Commit 487f0782 authored by tholok97's avatar tholok97
Browse files

#4 test passerer lint, tillater lang URL

parent 9e85d46b
No related branches found
No related tags found
No related merge requests found
Pipeline #70176 canceled
......@@ -8,14 +8,14 @@ job_lint_flake8:
image: morkolai/soitool-ci
script:
- flake8 --version
- flake8 soitool
- flake8 --config scripts/.flake8 soitool test
job_lint_pylint:
stage: lint
image: morkolai/soitool-ci
script:
- pylint --version
- pylint --rcfile=scripts/.pylintrc soitool
- pylint --rcfile=scripts/.pylintrc soitool test
job_lint_bandit:
stage: lint
......
[flake8]
# ignorerer sjekk for lange linjer, ettersom dette gjøres i pylint
# vi vil tillate lange linjer som avsluttes med link, og dette er mulig i
# pylint, men såvidt vi vet ikke mulig i flake8
ignore = E501
......@@ -275,7 +275,7 @@ redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
expected-line-ending-format=
# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
ignore-long-lines=^.*<?https?://\S+>?$
# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren=4
......
"""Test CoolWidget"""
import unittest
import sys
from datetime import datetime as datetime_, timedelta
from PySide2 import QtWidgets, QtTest, QtCore
from soitool import main
from PySide2 import QtGui, QtWidgets, QtTest, QtCore
# references:
# * findChild: https://srinikom.github.io/pyside-docs/PySide/QtCore/QObject.html#PySide.QtCore.PySide.QtCore.QObject.findChild
......@@ -18,48 +21,69 @@ from PySide2 import QtGui, QtWidgets, QtTest, QtCore
# moved here from setUp to avoid annoying startup messages
app = QtWidgets.QApplication(sys.argv)
def wait(msec):
QtTest.QTest.qWait(msec)
"""Venter msec millisekunder
Bruker https://stackoverflow.com/a/34745326/3545896
Parameter
-----
msec : number
msec to wait
"""
end = datetime_.now() + timedelta(milliseconds=msec)
while datetime_.now() < end:
app.processEvents()
class TestMain(unittest.TestCase):
"""TestCase for main"""
def setUp(self):
"""Forbereder widget for testing"""
self.test_text1 = "A bad boy"
self.test_text2 = "Hei Anders!"
self.widget = main.CoolWidget(self.test_text1)
self.widget.show()
def test_starts_up(self):
"""Test at widget kan starte opp"""
self.assertEqual(
self.widget.qlabel.text(),
self.test_text1,
self.widget.qlabel.text(),
self.test_text1,
)
self.assertTrue(self.widget.isVisible())
def test_change_text_ok(self):
"""Test at endring av tekst funker"""
def change_text_and_ok():
active_widget = app.activeModalWidget()
child_line_edit = active_widget.findChild(QtWidgets.QLineEdit)
while self.widget.dlg_input is None:
app.processEvents()
child_line_edit = self.widget.dlg_input.findChild(QtWidgets.QLineEdit)
QtTest.QTest.keyClicks(child_line_edit, self.test_text2)
QtTest.QTest.keyClick(child_line_edit, QtCore.Qt.Key_Enter)
QtCore.QTimer.singleShot(0, change_text_and_ok)
QtCore.QTimer.singleShot(100, change_text_and_ok)
QtTest.QTest.mouseClick(self.widget.button, QtCore.Qt.LeftButton)
self.assertEqual(
self.widget.qlabel.text(),
self.test_text2,
)
def test_change_text_not_ok(self):
"""Test at avbrytelse av endring av tekster ikke endrer tekst"""
def accept_popup():
QtTest.QTest.keyClick(app.activeModalWidget(), QtCore.Qt.Key_Enter)
def change_text_and_not_ok():
# in PySide2 we need to store a reference to this. If we don't the widget is garbage collected somehow before we get to use child_line_edit (a child of the active widget)
# in PySide2 we need to store a reference to this. If we don't the
# widget is garbage collected somehow before we get to use
# child_line_edit (a child of the active widget)
active_widget = app.activeModalWidget()
child_line_edit = active_widget.findChild(QtWidgets.QLineEdit)
......@@ -70,11 +94,12 @@ class TestMain(unittest.TestCase):
QtCore.QTimer.singleShot(0, change_text_and_not_ok)
QtTest.QTest.mouseClick(self.widget.button, QtCore.Qt.LeftButton)
self.assertNotEqual(
self.widget.qlabel.text(),
self.test_text2,
)
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment