From f945387066e73027963b23390ef2c166c0384ecd Mon Sep 17 00:00:00 2001 From: Olivier Keshavjee Date: Wed, 22 Nov 2017 09:08:54 +0100 Subject: [PATCH] Adds unit test for #225: Manuskript fails to run in Ubuntu 14.04 --- manuskript/tests/conftest.py | 9 +++++++++ manuskript/tests/ui/__init__.py | 4 ++++ manuskript/tests/ui/test_welcome.py | 22 ++++++++++++++++++++++ manuskript/ui/welcome.py | 3 ++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 manuskript/tests/ui/__init__.py create mode 100644 manuskript/tests/ui/test_welcome.py diff --git a/manuskript/tests/conftest.py b/manuskript/tests/conftest.py index 0b5660e0..be2403df 100644 --- a/manuskript/tests/conftest.py +++ b/manuskript/tests/conftest.py @@ -17,6 +17,15 @@ def MW(): return MW +@pytest.fixture +def MWNoProject(MW): + """ + Take the MainWindow and close andy possibly open project. + """ + MW.closeProject() + assert MW.currentProject is None + return MW + @pytest.fixture def MWEmptyProject(MW): """ diff --git a/manuskript/tests/ui/__init__.py b/manuskript/tests/ui/__init__.py new file mode 100644 index 00000000..4d7565a7 --- /dev/null +++ b/manuskript/tests/ui/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python +# --!-- coding: utf8 --!-- + +"""Tests for stuff in ui.""" diff --git a/manuskript/tests/ui/test_welcome.py b/manuskript/tests/ui/test_welcome.py new file mode 100644 index 00000000..0c129e54 --- /dev/null +++ b/manuskript/tests/ui/test_welcome.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# --!-- coding: utf8 --!-- + +"""Tests for the welcome widget.""" + +def test_autoLoad(MWNoProject): + """ + Tests for the welcome widget using MainWindow with no open project. + """ + MW = MWNoProject + from PyQt5.QtCore import QSettings + + # Testing when no autoLoad + QSettings().remove("autoLoad") + autoLoad, path = MW.welcome.getAutoLoadValues() + assert type(autoLoad) == bool + assert autoLoad == False + + for v in [True, False, 42, "42", None, True]: + MW.welcome.setAutoLoad(v) + autoLoad, path = MW.welcome.getAutoLoadValues() + assert type(autoLoad) == bool diff --git a/manuskript/ui/welcome.py b/manuskript/ui/welcome.py index 8467d58b..5c8d1a44 100644 --- a/manuskript/ui/welcome.py +++ b/manuskript/ui/welcome.py @@ -77,7 +77,8 @@ class welcome(QWidget, Ui_welcome): return autoLoad, last def setAutoLoad(self, v): - QSettings().setValue("autoLoad", v) + if type(v) == bool: + QSettings().setValue("autoLoad", v) ############################################################################### # RECENTS