Files
BEdit/tests/unit/test_gui_document.py
Joppe Blondel 4c3b8b4b6d Document handling
New/Open/Save/Save as and Undo/Redo
2026-07-26 13:41:23 +02:00

38 lines
890 B
Python

from __future__ import annotations
from pathlib import Path
import pytest
from PySide6.QtGui import QUndoCommand
from bedit_gui.documents import Document
@pytest.mark.unit
@pytest.mark.parametrize("suffix", [".beb", ".json"])
def test_document_save_and_open(tmp_path: Path, suffix: str) -> None:
path = tmp_path / f"document{suffix}"
document = Document()
original_id = document.model.id
document.save_as(path)
document.new()
assert document.model.id != original_id
document.open(path)
assert document.model.id == original_id
assert document.path == path
assert not document.modified
@pytest.mark.unit
def test_document_modified_state_uses_undo_stack() -> None:
document = Document()
document.undo_stack.push(QUndoCommand("change"))
assert document.modified
document.undo_stack.setClean()
assert not document.modified