Files
MDHelper/tests/test_startup_revision_058.py
T

30 lines
1.5 KiB
Python

"""Empty and invalid directory history must not resolve to the working folder."""
from unittest.mock import MagicMock
import pytest
from PySide6.QtCore import QSettings
from mdhelper import app
@pytest.mark.parametrize('history', [None, '', ' ', 'missing', 'file', 'directory'])
def test_startup_history_requires_a_nonempty_directory(tmp_path, monkeypatch, history):
settings = QSettings(str(tmp_path/'settings.ini'), QSettings.Format.IniFormat)
folder = tmp_path/'project'; folder.mkdir()
file = folder/'note.md'; file.write_text('Text')
value = {'missing': str(tmp_path/'missing'), 'file': str(file), 'directory': str(folder)}.get(history, history)
if value is not None: settings.setValue('project/last_root', value)
window = MagicMock()
monkeypatch.setattr(app, 'QSettings', lambda *_: settings)
monkeypatch.setattr(app, 'QApplication', MagicMock())
monkeypatch.setattr(app, 'MainWindow', window)
monkeypatch.setattr(app, 'configure_process_runtime', lambda *_: None)
monkeypatch.setattr(app, 'setup_logging', lambda *_: None)
app.main([])
args = window.call_args.kwargs
assert args['project_root'] == (folder if history == 'directory' else None)
assert args['prompt_for_project'] == (history != 'directory')
assert args['initial_path'] is None
# Explicit startup files still take precedence over all history values.
app.main([str(file)])
assert window.call_args.kwargs['project_root'] == folder
assert window.call_args.kwargs['initial_path'] == file