Completed coverage of setProjectPath and made all os imports explicit

This commit is contained in:
Veronica K. B. Olsen
2020-09-29 23:27:51 +02:00
parent 0b7cd71b92
commit e251ddacd2
23 changed files with 565 additions and 486 deletions
+46 -46
View File
@@ -5,13 +5,13 @@
import sys
import pytest
import shutil
import os
from os import path, mkdir
from nwdummy import DummyMain
from PyQt5.QtWidgets import QMessageBox
sys.path.insert(1, path.abspath(path.join(path.dirname(__file__), path.pardir)))
sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from nw.config import Config # noqa: E402
@@ -25,12 +25,12 @@ def nwTemp():
presistent after the test so that the status of generated files can
be checked. The folder is instead cleared before a new test session.
"""
testDir = path.dirname(__file__)
tempDir = path.join(testDir, "temp")
if path.isdir(tempDir):
testDir = os.path.dirname(__file__)
tempDir = os.path.join(testDir, "temp")
if os.path.isdir(tempDir):
shutil.rmtree(tempDir)
if not path.isdir(tempDir):
mkdir(tempDir)
if not os.path.isdir(tempDir):
os.mkdir(tempDir)
return tempDir
@pytest.fixture(scope="session")
@@ -38,8 +38,8 @@ def nwRef():
"""The folder where all the reference files are stored for verifying
the results of tests.
"""
testDir = path.dirname(__file__)
refDir = path.join(testDir, "reference")
testDir = os.path.dirname(__file__)
refDir = os.path.join(testDir, "reference")
return refDir
##
@@ -80,40 +80,40 @@ def nwDummy(nwRef, nwTemp, nwConf):
def nwTempProj(nwTemp):
"""A temporary folder for project tests.
"""
projDir = path.join(nwTemp, "proj")
if not path.isdir(projDir):
mkdir(projDir)
projDir = os.path.join(nwTemp, "proj")
if not os.path.isdir(projDir):
os.mkdir(projDir)
return projDir
@pytest.fixture(scope="session")
def nwTempGUI(nwTemp):
"""A temporary folder for GUI tests.
"""
guiDir = path.join(nwTemp, "gui")
if not path.isdir(guiDir):
mkdir(guiDir)
guiDir = os.path.join(nwTemp, "gui")
if not os.path.isdir(guiDir):
os.mkdir(guiDir)
return guiDir
@pytest.fixture(scope="session")
def nwTempBuild(nwTemp):
"""A temporary folder for build tests.
"""
buildDir = path.join(nwTemp, "build")
if not path.isdir(buildDir):
mkdir(buildDir)
buildDir = os.path.join(nwTemp, "build")
if not os.path.isdir(buildDir):
os.mkdir(buildDir)
return buildDir
@pytest.fixture(scope="function")
def nwFuncTemp(nwTemp):
"""A temporary folder for a single test function.
"""
funcDir = path.join(nwTemp, "ftemp")
if path.isdir(funcDir):
funcDir = os.path.join(nwTemp, "ftemp")
if os.path.isdir(funcDir):
shutil.rmtree(funcDir)
if not path.isdir(funcDir):
mkdir(funcDir)
if not os.path.isdir(funcDir):
os.mkdir(funcDir)
yield funcDir
if path.isdir(funcDir):
if os.path.isdir(funcDir):
shutil.rmtree(funcDir)
return
@@ -125,20 +125,20 @@ def nwFuncTemp(nwTemp):
def nwMinimal(nwTemp):
"""A minimal novelWriter example project.
"""
testDir = path.dirname(__file__)
minimalStore = path.join(testDir, "minimal")
minimalDir = path.join(nwTemp, "minimal")
if path.isdir(minimalDir):
testDir = os.path.dirname(__file__)
minimalStore = os.path.join(testDir, "minimal")
minimalDir = os.path.join(nwTemp, "minimal")
if os.path.isdir(minimalDir):
shutil.rmtree(minimalDir)
shutil.copytree(minimalStore, minimalDir)
cacheDir = path.join(minimalDir, "cache")
if path.isdir(cacheDir):
cacheDir = os.path.join(minimalDir, "cache")
if os.path.isdir(cacheDir):
shutil.rmtree(cacheDir)
metaDir = path.join(minimalDir, "meta")
if path.isdir(metaDir):
metaDir = os.path.join(minimalDir, "meta")
if os.path.isdir(metaDir):
shutil.rmtree(metaDir)
yield minimalDir
if path.isdir(minimalDir):
if os.path.isdir(minimalDir):
shutil.rmtree(minimalDir)
return
@@ -147,20 +147,20 @@ def nwLipsum(nwTemp):
"""A medium sized novelWriter example project with a lot of Lorem
Ipsum dummy text.
"""
testDir = path.dirname(__file__)
lipsumStore = path.join(testDir, "lipsum")
lipsumDir = path.join(nwTemp, "lipsum")
if path.isdir(lipsumDir):
testDir = os.path.dirname(__file__)
lipsumStore = os.path.join(testDir, "lipsum")
lipsumDir = os.path.join(nwTemp, "lipsum")
if os.path.isdir(lipsumDir):
shutil.rmtree(lipsumDir)
shutil.copytree(lipsumStore, lipsumDir)
cacheDir = path.join(lipsumDir, "cache")
if path.isdir(cacheDir):
cacheDir = os.path.join(lipsumDir, "cache")
if os.path.isdir(cacheDir):
shutil.rmtree(cacheDir)
metaDir = path.join(lipsumDir, "meta")
if path.isdir(metaDir):
metaDir = os.path.join(lipsumDir, "meta")
if os.path.isdir(metaDir):
shutil.rmtree(metaDir)
yield lipsumDir
if path.isdir(lipsumDir):
if os.path.isdir(lipsumDir):
shutil.rmtree(lipsumDir)
return
@@ -168,14 +168,14 @@ def nwLipsum(nwTemp):
def nwOldProj(nwTemp):
"""A minimal movelWriter project using the old folder structure.
"""
testDir = path.dirname(__file__)
oldProjStore = path.join(testDir, "oldproj")
oldProjDir = path.join(nwTemp, "oldproj")
if path.isdir(oldProjDir):
testDir = os.path.dirname(__file__)
oldProjStore = os.path.join(testDir, "oldproj")
oldProjDir = os.path.join(nwTemp, "oldproj")
if os.path.isdir(oldProjDir):
shutil.rmtree(oldProjDir)
shutil.copytree(oldProjStore, oldProjDir)
yield oldProjDir
if path.isdir(oldProjDir):
if os.path.isdir(oldProjDir):
shutil.rmtree(oldProjDir)
return