mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-06-15 01:14:34 +12:00
af53102e77
When running pytest on kubuntu 16.04 the following warning was displayed: $ python3 -m pytest -v ... ./manuskript/load_save/version_1.py:319: \ UserWarning: Duplicate name: 'outline/0-Folder/0-Text-3.md' zf.writestr(filename, content, compress_type=compression) The error was tracked down using the following pytest invocation: $ python3 -m pytest -v -W error::UserWarning This invocation showed 4 occurrences similar to the following warning: self = <zipfile.ZipFile filename='/tmp/tmpgs_sjpzr.msk' mode='w'> zinfo = <[AttributeError("compress_size") raised in repr()] \ ZipInfo object at 0x7f3cc0124588> def _writecheck(self, zinfo): """Check for errors before writing a file to the archive.""" if zinfo.filename in self.NameToInfo: import warnings > warnings.warn('Duplicate name: %r' % zinfo.filename, \ stacklevel=3) E UserWarning: Duplicate name: 'outline/0-Folder/0-Text-3.md' These warnings arose in the following 4 tests: - test_references - test_autoLoad - test_loadExportWiget - test_loadImportWiget The cause of the issue is that in manuskript/tests/conftest.py, the mainWindow::closeProject() method is called to close the project, but the project was never loaded. This meant the zip file setting defaulted to True, when in fact the Acts sample project is not stored in a single zip project file. Fix by removing the call to MW.closeProject() before the project is loaded.
73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
# --!-- coding: utf8 --!--
|
|
|
|
"""Fixtures."""
|
|
|
|
import pytest
|
|
|
|
@pytest.fixture
|
|
def MW():
|
|
"""
|
|
Returns the mainWindow
|
|
"""
|
|
from manuskript import functions as F
|
|
MW = F.mainWindow()
|
|
assert MW is not None
|
|
assert MW == F.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):
|
|
"""
|
|
Creates a MainWindow and load an empty project.
|
|
"""
|
|
import tempfile
|
|
tf = tempfile.NamedTemporaryFile(suffix=".msk")
|
|
|
|
MW.closeProject()
|
|
assert MW.currentProject is None
|
|
MW.welcome.createFile(tf.name, overwrite=True)
|
|
assert MW.currentProject is not None
|
|
return MW
|
|
|
|
# If using with: @pytest.fixture(scope='session', autouse=True)
|
|
# yield MW
|
|
# # Properly destructed after. Otherwise: seg fault.
|
|
# MW.deleteLater()
|
|
|
|
@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)
|
|
assert MW.currentProject is not None
|
|
|
|
return MW
|