manuskript/manuskript/tests/test_settingsWindow.py

165 lines
5.9 KiB
Python
Raw Permalink Normal View History

2017-11-21 10:24:47 +13:00
#!/usr/bin/env python
# --!-- coding: utf8 --!--
"""Tests for settingsWindow"""
from manuskript import functions as F
def test_general(MWSampleProject):
MW = MWSampleProject
# Loading from mainWindow
MW.actSettings.triggered.emit()
assert MW.sw.isVisible()
MW.sw.close()
MW.actLabels.triggered.emit()
assert MW.sw.isVisible()
MW.sw.close()
MW.actStatus.triggered.emit()
assert MW.sw.isVisible()
MW.sw.hide()
2017-11-21 11:26:22 +13:00
MW.sw.setTab("General")
2017-11-21 10:24:47 +13:00
SW = MW.sw
# Imports
from PyQt5.QtWidgets import qApp, QStyleFactory
from PyQt5.QtCore import QSettings, Qt
qS = QSettings(qApp.organizationName(), qApp.applicationName())
from manuskript import settings as S
# Style
assert SW.cmbStyle.count() == len(list(QStyleFactory.keys()))
2017-11-21 10:35:39 +13:00
if qS.value("applicationStyle"):
assert SW.cmbStyle.currentText() == qS.value("applicationStyle")
2017-11-21 10:24:47 +13:00
## Seg fault when trying to set the style in tests:
# for s in styles:
# SW.cmbStyle.setCurrentText(s)
# assert S.value("applicationStyle") == s
# Translations
2017-11-21 10:35:39 +13:00
if qS.value("applicationTranslation"):
assert (SW.cmbTranslation.currentData()
== qS.value("applicationTranslation"))
2017-11-21 10:24:47 +13:00
for name in SW.translations:
SW.cmbTranslation.setCurrentText(name)
2017-11-21 10:35:39 +13:00
if qS.value("applicationTranslation"):
assert qS.value("applicationTranslation") == SW.translations[name]
2017-11-21 10:24:47 +13:00
def switchCheckBoxAndAssert(chk, settings):
"""
Asserts that the check state is that of settings, change checkstate
and asserts settings has been changed.
Settings is a function that returns the value.
"""
state = settings()
assert chk.isChecked() == state
chk.setChecked(not state)
2021-02-22 11:45:34 +13:00
assert chk.isChecked() != state
2017-11-21 10:24:47 +13:00
# Loading and Saving
2017-11-21 11:26:22 +13:00
SW.txtAutoSave.setText("0")
SW.txtAutoSaveNoChanges.setText("0")
2017-11-21 10:24:47 +13:00
switchCheckBoxAndAssert(SW.chkAutoLoad,
lambda: qS.value("autoLoad", type=bool))
switchCheckBoxAndAssert(SW.chkAutoSave,
lambda: S.autoSave)
switchCheckBoxAndAssert(SW.chkAutoSaveNoChanges,
lambda: S.autoSaveNoChanges)
switchCheckBoxAndAssert(SW.chkSaveOnQuit,
lambda: S.saveOnQuit)
switchCheckBoxAndAssert(SW.chkSaveToZip,
lambda: S.saveToZip)
# Revisions
switchCheckBoxAndAssert(SW.chkRevisionsKeep,
lambda: S.revisions["keep"])
switchCheckBoxAndAssert(SW.chkRevisionRemove,
lambda: S.revisions["smartremove"])
# Views
# Simple way here, we just call the functions.
SW.cmbTreeIcon.currentIndexChanged.emit(0)
SW.cmbOutlineIcon.currentIndexChanged.emit(0)
SW.cmbCorkIcon.currentIndexChanged.emit(0)
2017-11-21 11:26:22 +13:00
SW.chkOutlineTitle.setChecked(Qt.Checked) #outlineColumnsChanged
SW.chkOutlineTitle.setChecked(Qt.Unchecked)
SW.chkOutlineTitle.setChecked(Qt.Checked)
2017-11-21 10:24:47 +13:00
# Can't test because of the dialog
2021-02-22 11:45:34 +13:00
# assert SW.setCorkColor() == None
2017-11-21 11:26:22 +13:00
SW.sldTreeIconSize.setValue(SW.sldTreeIconSize.value() + 1)
2017-11-21 10:24:47 +13:00
SW.rdoCorkNewStyle.toggled.emit(True)
SW.cmbCorkImage.currentIndexChanged.emit(0)
2017-11-21 11:26:22 +13:00
SW.cmbCorkImage.currentIndexChanged.emit(1)
2017-11-21 10:24:47 +13:00
# Test editor: same problem as above
# choseEditorFontColor
# choseEditorMisspelledColor
# choseEditorBackgroundColor
# Test editor
switchCheckBoxAndAssert(SW.chkEditorBackgroundTransparent,
lambda: S.textEditor["backgroundTransparent"])
2021-02-22 11:45:34 +13:00
assert SW.restoreEditorColors() == None
2017-11-21 10:24:47 +13:00
switchCheckBoxAndAssert(SW.chkEditorNoBlinking,
lambda: S.textEditor["cursorNotBlinking"])
2017-11-21 11:26:22 +13:00
# Twice on purpose: set and restore
switchCheckBoxAndAssert(SW.chkEditorNoBlinking,
lambda: S.textEditor["cursorNotBlinking"])
# Manually call updateAllWidgets, because other wise timer of 250ms
SW.updateAllWidgets()
2017-11-21 10:24:47 +13:00
# Labels
2021-02-22 11:45:34 +13:00
assert SW.updateLabelColor(MW.mdlLabels.item(1).index()) == None
2017-11-21 10:24:47 +13:00
rc = MW.mdlLabels.rowCount()
SW.addLabel()
SW.lstLabels.setCurrentIndex(
MW.mdlLabels.item(MW.mdlLabels.rowCount() - 1).index())
SW.removeLabel()
assert MW.mdlLabels.rowCount() == rc
# setLabelColor # Same problem as above
# Status
rc = MW.mdlStatus.rowCount()
SW.addStatus()
SW.lstStatus.setCurrentIndex(
MW.mdlStatus.item(MW.mdlStatus.rowCount() - 1).index())
SW.removeStatus()
assert MW.mdlStatus.rowCount() == rc
# Fullscreen
# self.lstThemes.currentItemChanged.connect(self.themeSelected)
item = SW.lstThemes.item(0)
SW.lstThemes.currentItemChanged.emit(item, None)
assert S.fullScreenTheme in item.data(Qt.UserRole)
SW.lstThemes.currentItemChanged.emit(None, None)
count = SW.lstThemes.count()
SW.newTheme()
assert SW.lstThemes.count() == count + 1
2017-11-21 11:26:22 +13:00
SW.newTheme() # theme with same name
item = SW.lstThemes.item(SW.lstThemes.count() - 1)
SW.lstThemes.setCurrentItem(item)
SW.removeTheme()
2017-11-21 10:24:47 +13:00
item = SW.lstThemes.item(count)
SW.lstThemes.setCurrentItem(item)
SW.editTheme()
switchCheckBoxAndAssert(SW.chkThemeIndent,
lambda: SW._themeData["Spacings/IndentFirstLine"])
SW.updateThemeFont(None)
SW.updateThemeBackground(0)
2017-11-21 11:26:22 +13:00
SW.updateThemeBackground(1)
SW.spnThemeLineSpacing.setValue(123)
2017-11-21 10:24:47 +13:00
for i in range(4):
SW.updateLineSpacing(i)
2017-11-21 11:26:22 +13:00
SW.updateUIFromTheme() # No time to wait on timer
2021-02-22 11:45:34 +13:00
assert SW._editingTheme != None
2017-11-21 10:24:47 +13:00
SW.resize(SW.geometry().size()) # resizeEvent
#TODO: other edit test (see SW.loadTheme
SW.saveTheme()
item = SW.lstThemes.item(count)
SW.lstThemes.setCurrentItem(item)
SW.editTheme()
SW.cancelEdit()
item = SW.lstThemes.item(count)
SW.lstThemes.setCurrentItem(item)
SW.removeTheme()
assert SW.lstThemes.count() == count