38 lines
890 B
Python
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
|