Decoupled config tests

This commit is contained in:
Veronica K. B. Olsen
2020-08-28 12:56:03 +02:00
parent 8340c0665d
commit b065e4d52b
2 changed files with 94 additions and 89 deletions
+7
View File
@@ -35,6 +35,13 @@ def nwConf(nwRef, nwTemp):
theConf.initConfig(nwRef, nwTemp) theConf.initConfig(nwRef, nwTemp)
return theConf return theConf
@pytest.fixture(scope="session")
def tmpConf(nwRef, nwTemp):
theConf = Config()
theConf.initConfig(nwTemp, nwTemp)
theConf.setLastPath("")
return theConf
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def nwDummy(nwRef, nwTemp, nwConf): def nwDummy(nwRef, nwTemp, nwConf):
theDummy = DummyMain() theDummy = DummyMain()
+87 -89
View File
@@ -5,112 +5,110 @@
import pytest import pytest
from nwtools import cmpFiles from nwtools import cmpFiles
from os import path from os import path
from nw.config import Config
theConf = Config()
@pytest.mark.core @pytest.mark.core
def testConfigInit(nwTemp, nwRef): def testConfigCore(tmpConf, nwTemp, nwRef):
tmpConf = path.join(nwTemp, "novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.initConfig(nwTemp, nwTemp) testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert theConf.setLastPath("")
assert theConf.saveConfig() assert tmpConf.confPath == nwTemp
assert cmpFiles(tmpConf, refConf, [2]) assert tmpConf.saveConfig()
assert not theConf.confChanged assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged
assert tmpConf.loadConfig()
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSave(nwTemp, nwRef): def testConfigSetConfPath(tmpConf, nwTemp):
tmpConf = path.join(nwTemp, "novelwriter.conf") assert tmpConf.setConfPath(None)
assert not tmpConf.setConfPath(path.join("somewhere", "over", "the", "rainbow"))
assert tmpConf.setConfPath(path.join(nwTemp, "novelwriter.conf"))
assert tmpConf.confPath == nwTemp
assert tmpConf.confFile == "novelwriter.conf"
assert not tmpConf.confChanged
@pytest.mark.core
def testConfigSetDataPath(tmpConf, nwTemp):
assert tmpConf.setDataPath(None)
assert not tmpConf.setDataPath(path.join("somewhere", "over", "the", "rainbow"))
assert tmpConf.setDataPath(nwTemp)
assert tmpConf.dataPath == nwTemp
assert not tmpConf.confChanged
@pytest.mark.core
def testConfigSetWinSize(tmpConf, nwTemp, nwRef):
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.confPath == nwTemp testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2]) assert tmpConf.confPath == nwTemp
assert not theConf.confChanged assert tmpConf.setWinSize(1105, 655)
assert not tmpConf.confChanged
assert tmpConf.setWinSize(70, 70)
assert tmpConf.confChanged
assert tmpConf.setWinSize(1100, 650)
assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetConfPath(nwTemp): def testConfigSetTreeColWidths(tmpConf, nwTemp, nwRef):
assert theConf.setConfPath(None)
assert not theConf.setConfPath(path.join("somewhere", "over", "the", "rainbow"))
assert theConf.setConfPath(path.join(nwTemp, "novelwriter.conf"))
assert theConf.confPath == nwTemp
assert theConf.confFile == "novelwriter.conf"
assert not theConf.confChanged
@pytest.mark.core
def testConfigSetDataPath(nwTemp):
assert theConf.setDataPath(None)
assert not theConf.setDataPath(path.join("somewhere", "over", "the", "rainbow"))
assert theConf.setDataPath(nwTemp)
assert theConf.dataPath == nwTemp
assert not theConf.confChanged
@pytest.mark.core
def testConfigLoad():
assert theConf.loadConfig()
assert not theConf.confChanged
@pytest.mark.core
def testConfigSetWinSize(nwTemp, nwRef):
tmpConf = path.join(nwTemp, "novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setWinSize(1105, 655) testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert not theConf.confChanged
assert theConf.setWinSize(70, 70) assert tmpConf.confPath == nwTemp
assert theConf.confChanged assert tmpConf.setTreeColWidths([0, 0, 0])
assert theConf.setWinSize(1100, 650) assert tmpConf.confChanged
assert theConf.saveConfig() assert tmpConf.setTreeColWidths([120, 30, 50])
assert cmpFiles(tmpConf, refConf, [2]) assert tmpConf.setProjColWidths([140, 55, 140])
assert not theConf.confChanged assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetTreeColWidths(nwTemp, nwRef): def testConfigSetPanePos(tmpConf, nwTemp, nwRef):
tmpConf = path.join(nwTemp, "novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setTreeColWidths([0, 0, 0]) testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert theConf.confChanged
assert theConf.setTreeColWidths([120, 30, 50]) assert tmpConf.confPath == nwTemp
assert theConf.setProjColWidths([140, 55, 140]) assert tmpConf.setMainPanePos([0, 0])
assert theConf.saveConfig() assert tmpConf.confChanged
assert cmpFiles(tmpConf, refConf, [2]) assert tmpConf.setMainPanePos([300, 800])
assert not theConf.confChanged assert tmpConf.setDocPanePos([400, 400])
assert tmpConf.setViewPanePos([500, 150])
assert tmpConf.setOutlinePanePos([500, 150])
assert tmpConf.saveConfig()
assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigSetPanePos(nwTemp, nwRef): def testConfigFlags(tmpConf, nwTemp, nwRef):
tmpConf = path.join(nwTemp, "novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf") refConf = path.join(nwRef, "novelwriter.conf")
assert theConf.setMainPanePos([0, 0]) testConf = path.join(tmpConf.confPath, "novelwriter.conf")
assert theConf.confChanged
assert theConf.setMainPanePos([300, 800]) assert tmpConf.confPath == nwTemp
assert theConf.setDocPanePos([400, 400]) assert not tmpConf.setShowRefPanel(False)
assert theConf.setViewPanePos([500, 150]) assert tmpConf.setShowRefPanel(True)
assert theConf.setOutlinePanePos([500, 150]) assert tmpConf.confChanged
assert theConf.saveConfig() assert tmpConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged assert cmpFiles(testConf, refConf, [2])
assert not tmpConf.confChanged
@pytest.mark.core @pytest.mark.core
def testConfigFlags(nwTemp, nwRef): def testConfigErrors(tmpConf):
tmpConf = path.join(nwTemp, "novelwriter.conf")
refConf = path.join(nwRef, "novelwriter.conf")
assert not theConf.setShowRefPanel(False)
assert theConf.setShowRefPanel(True)
assert theConf.confChanged
assert theConf.saveConfig()
assert cmpFiles(tmpConf, refConf, [2])
assert not theConf.confChanged
@pytest.mark.core
def testConfigErrors(nwTemp):
nonPath = path.join("somewhere", "over", "the", "rainbow") nonPath = path.join("somewhere", "over", "the", "rainbow")
assert theConf.initConfig(nonPath, nonPath) assert tmpConf.initConfig(nonPath, nonPath)
assert theConf.hasError assert tmpConf.hasError
assert not theConf.loadConfig() assert not tmpConf.loadConfig()
assert not theConf.saveConfig() assert not tmpConf.saveConfig()
assert not theConf.loadRecentCache() assert not tmpConf.loadRecentCache()
assert len(theConf.getErrData()) > 0 assert len(tmpConf.getErrData()) > 0
@pytest.mark.core @pytest.mark.core
def testConfigInternals(): def testConfigInternals(tmpConf):
assert theConf._checkNone(None) is None assert tmpConf._checkNone(None) is None
assert theConf._checkNone("None") is None assert tmpConf._checkNone("None") is None