From 5692cbef568af1cf2616cc5f7f4311f9a5d81fd3 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 5 Jun 2026 20:14:39 -0400 Subject: [PATCH] test(workspace_profile): add str/bytes TOML serialization contract test --- tests/test_workspace_profile_serialization.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test_workspace_profile_serialization.py diff --git a/tests/test_workspace_profile_serialization.py b/tests/test_workspace_profile_serialization.py new file mode 100644 index 00000000..e9a150cd --- /dev/null +++ b/tests/test_workspace_profile_serialization.py @@ -0,0 +1,55 @@ +import io +import tomllib +import pytest +import tomli_w +from src.models import WorkspaceProfile + + +def test_workspace_profile_empty_ini_content_roundtrips(): + profile = WorkspaceProfile( + name="t", + ini_content="", + show_windows={"A": True, "B": False}, + panel_states={"x": 1, "y": 2.0, "z": True}, + ) + d = profile.to_dict() + buf = io.BytesIO() + tomli_w.dump({"t": d}, buf) + buf.seek(0) + back = tomllib.load(buf) + loaded = WorkspaceProfile.from_dict("t", back["t"]) + assert loaded.ini_content == "" + assert loaded.show_windows == {"A": True, "B": False} + assert loaded.panel_states == {"x": 1, "y": 2.0, "z": True} + + +def test_workspace_profile_with_actual_ini_content_roundtrips(): + profile = WorkspaceProfile( + name="real", + ini_content="[Window][Debug]\nPos=10,20\n", + show_windows={}, + panel_states={}, + ) + d = profile.to_dict() + buf = io.BytesIO() + tomli_w.dump({"real": d}, buf) + buf.seek(0) + back = tomllib.load(buf) + loaded = WorkspaceProfile.from_dict("real", back["real"]) + assert loaded.ini_content == "[Window][Debug]\nPos=10,20\n" + assert loaded.name == "real" + assert loaded.show_windows == {} + assert loaded.panel_states == {} + + +def test_workspace_profile_bytes_ini_content_rejected_by_toml(): + profile = WorkspaceProfile( + name="bad", + ini_content=b"", + show_windows={}, + panel_states={}, + ) + d = profile.to_dict() + buf = io.BytesIO() + with pytest.raises(TypeError, match="bytes"): + tomli_w.dump({"bad": d}, buf)