2017-11-19 12:20:49 +13:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# --!-- coding: utf8 --!--
|
|
|
|
|
|
|
|
"""Fixtures."""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2017-11-21 03:42:30 +13:00
|
|
|
@pytest.fixture
|
|
|
|
def MW():
|
2017-11-19 12:20:49 +13:00
|
|
|
"""
|
2017-11-21 03:42:30 +13:00
|
|
|
Returns the mainWindow
|
2017-11-19 12:20:49 +13:00
|
|
|
"""
|
2017-11-21 03:42:30 +13:00
|
|
|
from manuskript import functions as F
|
|
|
|
MW = F.mainWindow()
|
2021-02-22 11:45:34 +13:00
|
|
|
assert MW != None
|
2017-11-21 03:42:30 +13:00
|
|
|
assert MW == F.MW
|
2017-11-19 12:20:49 +13:00
|
|
|
|
2017-11-21 03:42:30 +13:00
|
|
|
return MW
|
|
|
|
|
2017-11-22 21:08:54 +13:00
|
|
|
@pytest.fixture
|
|
|
|
def MWNoProject(MW):
|
|
|
|
"""
|
|
|
|
Take the MainWindow and close andy possibly open project.
|
|
|
|
"""
|
|
|
|
MW.closeProject()
|
2021-02-22 11:45:34 +13:00
|
|
|
assert MW.currentProject == None
|
2017-11-22 21:08:54 +13:00
|
|
|
return MW
|
|
|
|
|
2017-11-21 03:42:30 +13:00
|
|
|
@pytest.fixture
|
|
|
|
def MWEmptyProject(MW):
|
|
|
|
"""
|
|
|
|
Creates a MainWindow and load an empty project.
|
|
|
|
"""
|
2017-11-20 03:29:38 +13:00
|
|
|
import tempfile
|
|
|
|
tf = tempfile.NamedTemporaryFile(suffix=".msk")
|
2017-11-21 03:42:30 +13:00
|
|
|
|
|
|
|
MW.closeProject()
|
2021-02-22 11:45:34 +13:00
|
|
|
assert MW.currentProject == None
|
2017-11-20 03:29:38 +13:00
|
|
|
MW.welcome.createFile(tf.name, overwrite=True)
|
2021-02-22 11:45:34 +13:00
|
|
|
assert MW.currentProject != None
|
2017-11-20 03:29:38 +13:00
|
|
|
return MW
|
2017-11-20 05:54:04 +13:00
|
|
|
|
2017-11-21 03:42:30 +13:00
|
|
|
# If using with: @pytest.fixture(scope='session', autouse=True)
|
2017-11-20 05:54:04 +13:00
|
|
|
# yield MW
|
|
|
|
# # Properly destructed after. Otherwise: seg fault.
|
|
|
|
# MW.deleteLater()
|
2017-11-21 03:42:30 +13:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def MWSampleProject(MW):
|
|
|
|
"""
|
|
|
|
Creates a MainWindow and load a copy of the Acts sample project.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from manuskript import functions as F
|
|
|
|
import os
|
|
|
|
# Get the path of the first sample project. We assume it is here.
|
|
|
|
spDir = F.appPath("sample-projects")
|
|
|
|
lst = os.listdir(spDir)
|
|
|
|
# We assume it's saved in folder, so there is a `name.msk` file and a
|
|
|
|
# `name` folder.
|
|
|
|
src = [f for f in lst if f[-4:] == ".msk" and f[:-4] in lst][0]
|
|
|
|
src = os.path.join(spDir, src)
|
|
|
|
# Copy to a temp file
|
|
|
|
import tempfile
|
|
|
|
tf = tempfile.NamedTemporaryFile(suffix=".msk")
|
|
|
|
import shutil
|
|
|
|
shutil.copyfile(src, tf.name)
|
|
|
|
shutil.copytree(src[:-4], tf.name[:-4])
|
|
|
|
MW.loadProject(tf.name)
|
2021-02-22 11:45:34 +13:00
|
|
|
assert MW.currentProject != None
|
2017-11-21 03:42:30 +13:00
|
|
|
|
|
|
|
return MW
|