.beb and .json serialization of the document
This commit is contained in:
37
tests/conftest.py
Normal file
37
tests/conftest.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Shared pytest fixtures for bedit tests.
|
||||
|
||||
Qt-specific fixtures can be added here later when GUI testing starts. Keeping
|
||||
the model fixtures independent from Qt lets the core suite stay lightweight.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from bedit_core.models import (
|
||||
Component,
|
||||
ComponentID,
|
||||
Document,
|
||||
Graph,
|
||||
GraphImplementation,
|
||||
ID,
|
||||
Interface,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def minimal_document() -> Document:
|
||||
"""Return the smallest useful graph document for core tests."""
|
||||
root_id = ComponentID("root")
|
||||
root = Component(
|
||||
name="Root",
|
||||
interface=Interface(),
|
||||
parameters={},
|
||||
implementation=GraphImplementation(Graph()),
|
||||
)
|
||||
return Document(
|
||||
format_version=1,
|
||||
id=ID("document"),
|
||||
name="Test document",
|
||||
root={root_id: root},
|
||||
)
|
||||
14
tests/unit/test_models.py
Normal file
14
tests/unit/test_models.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""Basic smoke tests for the core model."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from bedit_core.models import Document, GraphImplementation
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_minimal_document_has_graph_root(minimal_document: Document) -> None:
|
||||
root = next(iter(minimal_document.root.values()))
|
||||
|
||||
assert isinstance(root.implementation, GraphImplementation)
|
||||
17
tests/unit/test_serialization.py
Normal file
17
tests/unit/test_serialization.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""Basic smoke tests for document serialization."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from bedit_core.models import Document
|
||||
from bedit_core.serialization import load, save
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_json_round_trip(tmp_path, minimal_document: Document) -> None:
|
||||
path = tmp_path / "document.json"
|
||||
|
||||
save(minimal_document, path)
|
||||
|
||||
assert load(path) == minimal_document
|
||||
Reference in New Issue
Block a user