release: prepare 0.4.0 installer and finalize content protection checks
This commit is contained in:
@@ -4,7 +4,7 @@ import zipfile
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from PIL import Image
|
||||
from PySide6.QtCore import QSettings
|
||||
from PySide6.QtCore import QSettings, Qt
|
||||
from mdhelper.batch_documents import BatchDocument, combine_documents, fingerprint, publish_outputs
|
||||
from mdhelper.batch_export_dialog import BatchExportDialog
|
||||
from mdhelper.docx_exporter import export_markdown_to_docx
|
||||
@@ -61,6 +61,26 @@ def test_publication_cancellation_race_and_rollback(tmp_path, monkeypatch):
|
||||
assert all(path.read_bytes() == b'old' for path in destinations)
|
||||
|
||||
|
||||
def test_combined_export_confirms_final_filename_after_extension_change(qt_application, tmp_path, monkeypatch):
|
||||
from mdhelper import batch_export_dialog as ui
|
||||
docs = documents(tmp_path)
|
||||
settings = QSettings(str(tmp_path / 'settings.ini'), QSettings.Format.IniFormat)
|
||||
monkeypatch.setattr(main_window, 'QSettings', lambda *_: settings)
|
||||
window = main_window.MainWindow(tmp_path)
|
||||
panel = BatchExportDialog(window)
|
||||
output = tmp_path / 'chosen.docx'; output.write_bytes(b'existing export')
|
||||
questions = []
|
||||
monkeypatch.setattr(window.exports, '_choose_page_settings', lambda: PageSettings())
|
||||
monkeypatch.setattr(ui.QFileDialog, 'getSaveFileName', lambda *args, **kwargs: (str(tmp_path / 'chosen.txt'), ''))
|
||||
monkeypatch.setattr(ui.QMessageBox, 'question', lambda *args: questions.append(args[2]) or ui.QMessageBox.StandardButton.No)
|
||||
try:
|
||||
panel.files.item(0).setCheckState(Qt.CheckState.Checked)
|
||||
panel.combined.setChecked(True)
|
||||
panel.start()
|
||||
assert str(output) in questions[0] and not panel.running and output.read_bytes() == b'existing export'
|
||||
finally: panel.close(); window.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('kind,combined', [('docx', False), ('pdf', True), ('pdf', False)])
|
||||
def test_queue_generates_complete_outputs(qt_application, tmp_path, monkeypatch, kind, combined):
|
||||
docs = documents(tmp_path)
|
||||
|
||||
@@ -21,7 +21,7 @@ def test_comparison_dialog_uses_selected_disk_chunk(qt_application, tmp_path):
|
||||
assert save_conflict.resolve_save_conflict(None, tmp_path / 'note.md', 'a\nlocal\n', 'a\nremote\n', 'a\nbase\n') == 'a\nremote\n'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('decision', ['cancel', 'merge', 'race', 'deleted'])
|
||||
@pytest.mark.parametrize('decision', ['cancel', 'merge', 'race', 'deleted', 'same_metadata'])
|
||||
def test_editor_conflict_protects_both_versions(qt_application, tmp_path, monkeypatch, decision):
|
||||
settings = QSettings(str(tmp_path / 'settings.ini'), QSettings.Format.IniFormat)
|
||||
monkeypatch.setattr(main_window, 'QSettings', lambda *_: settings)
|
||||
@@ -33,6 +33,11 @@ def test_editor_conflict_protects_both_versions(qt_application, tmp_path, monkey
|
||||
window.open_document(path); window.edit_current_markdown()
|
||||
editor = window.tabs.currentWidget(); editor.replace_source_undoable('local')
|
||||
if decision == 'deleted': path.unlink()
|
||||
elif decision == 'same_metadata':
|
||||
import os
|
||||
stamp = path.stat()
|
||||
path.write_text('disk')
|
||||
os.utime(path, ns=(stamp.st_atime_ns, stamp.st_mtime_ns))
|
||||
else: path.write_text('external modification')
|
||||
def choose(*args, **kwargs):
|
||||
if decision == 'cancel': return None
|
||||
@@ -40,7 +45,7 @@ def test_editor_conflict_protects_both_versions(qt_application, tmp_path, monkey
|
||||
return 'merged result'
|
||||
monkeypatch.setattr(save_conflict, 'resolve_save_conflict', choose)
|
||||
saved = window._save_editor_tab(editor, path, editor.source_text(), editor.session.signature)
|
||||
assert saved == (decision in {'merge', 'deleted'})
|
||||
assert saved == (decision in {'merge', 'deleted', 'same_metadata'})
|
||||
if saved:
|
||||
assert path.read_text() == editor.source_text() == editor.session.saved_source == 'merged result'
|
||||
assert not editor.has_unsaved_changes()
|
||||
|
||||
Reference in New Issue
Block a user