diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 57d6080022ebdfdbfb9318a354ece9b97dc6eafe..7f2787cacbd7a99ec91555209b7401d6b005c8d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,28 +8,28 @@ 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 image: morkolai/soitool-ci script: - bandit --version - - bandit -r soitool + - bandit -r soitool test job_lint_pydocstyle: stage: lint image: morkolai/soitool-ci script: - pydocstyle --version - - pydocstyle --convention=numpy soitool + - pydocstyle --match '.*.py' --convention=numpy soitool test job_test_gui_ubuntu_vnc: stage: test @@ -37,7 +37,7 @@ job_test_gui_ubuntu_vnc: script: # -platform because running with a screen is not supported # https://stackoverflow.com/questions/17106315/failed-to-load-platform-plugin-xcb-while-launching-qt5-app-on-linux-without - - QT_QPA_PLATFORM=vnc python3 -m unittest test.test_main + - QT_QPA_PLATFORM=vnc python3.7 -m unittest test.test_main job_test_gui_windows: stage: test diff --git a/Dockerfile b/Dockerfile index e1cd2b012ede6a78fc06c7a1fc7e2889368f5ce6..0ba5c5605dc81669c396b2cc9f78f6538410168d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:18.04 # This Dockerfile describes the container used in .gitlab-ci.yml @@ -24,4 +24,20 @@ RUN apt-get install -y libegl1-mesa-dev \ WORKDIR /code COPY requirements.txt requirements.txt -RUN pip3 install -r requirements.txt +RUN python3.7 -m pip install setuptools +RUN python3.7 -m pip install -r requirements.txt + + +# Set the locale +# Necessary for container to properly handle æøå +# See issue #10 +RUN apt-get install -y locales +RUN locale-gen en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + + +# From https://it.i88.ca/2016/03/how-to-fix-importerror-libgssapikrb5so2.html +# python3.7 -m unittest fails without this +RUN apt-get -y install libgssapi-krb5-2 diff --git a/scripts/.flake8 b/scripts/.flake8 new file mode 100644 index 0000000000000000000000000000000000000000..de75a936c7acec77595ab58ce170803ae7205cd2 --- /dev/null +++ b/scripts/.flake8 @@ -0,0 +1,5 @@ +[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 diff --git a/scripts/.pylintrc b/scripts/.pylintrc index 7e9ef2c59e6d2485745e4bb9538672918024a7cb..43b2b9bbb126b33d46a4ce3faab76ffb6c1b2b72 100644 --- a/scripts/.pylintrc +++ b/scripts/.pylintrc @@ -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 diff --git a/scripts/CodeQualityCheck.ps1 b/scripts/CodeQualityCheck.ps1 index 694ce41b0394318721df3417e0be2e9136a59178..7e5021fa42af906c9517997851afcde34e009cd4 100644 --- a/scripts/CodeQualityCheck.ps1 +++ b/scripts/CodeQualityCheck.ps1 @@ -1,7 +1,9 @@ if ($args.Count -eq 0){ - $files=Get-ChildItem -recurse| Where-Object {$_.name -match "[A-Za-z0-9_]+\.py" -And $_.Name -notmatch "pyc"} | % { $_.FullName } + $files=Get-ChildItem -recurse | + Where-Object {$_.name -match "[A-Za-z0-9_]+\.py" -And $_.Name -notmatch "pyc"} | + % { $_.FullName } Write-Output "`nChecking all .py-files" } else{ @@ -9,11 +11,11 @@ else{ } for ($i=0; $i -lt $files.Length; $i++){ - Write-Output "`n==============================$(Split-Path $files[$i] -leaf)==============================" + Write-Output "`n============================$(Split-Path $files[$i] -leaf)============================" Write-Output "===PYLINT===`n" pylint --rcfile=./scripts/.pylintrc $files[$i] Write-Output "`n===FLAKE8===`n" - flake8 $files[$i] + flake8 --config ./scripts/.flake8 $files[$i] Write-Output "`n===BANDIT===`n" bandit $files[$i] Write-Output "`n===PYDOCSTYLE===`n" diff --git a/scripts/CodeQualityCheck.sh b/scripts/CodeQualityCheck.sh index 5f24a08c6035c6416cca02cea2a8f70b26b348fa..965530d50304173c177533c918d537ed4e3120d4 100644 --- a/scripts/CodeQualityCheck.sh +++ b/scripts/CodeQualityCheck.sh @@ -6,14 +6,14 @@ else files=$@ fi - for filnavn in $files; do - printf "==============================$filnavn==============================\n" + for fileName in $files; do + printf "============================$fileName============================\n" printf "\n===PYLINT===\n" - pylint --rcfile=./scripts/.pylintrc $filnavn + pylint --rcfile=./scripts/.pylintrc $fileName printf "===FLAKE8===\n" - flake8 $filnavn + flake8 --config ./scripts/.flake8 $fileName printf "\n===BANDIT===\n" - bandit $filnavn + bandit $fileName printf "\n===PYDOCSTYLE===\n" - pydocstyle --convention=numpy $filnavn + pydocstyle --convention=numpy $fileName done diff --git a/test/__init__.py b/test/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..5f1ae119d6f959cc9e9b1a127e305d5145dc620e 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1 @@ +"""Tester koden vår.""" diff --git a/test/test_main.py b/test/test_main.py index df0dbd7bb419d6c23d5592ed8f02d857e6874430..beadccfe5991936ceba67b155d69db315ddf1414 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -1,7 +1,10 @@ +"""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,68 @@ 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 +93,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()