Skip to content

Commit 4d9836e

Browse files
committed
test: add unit test for get_placeholders to exclude non-placeholder fields
1 parent e528787 commit 4d9836e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_slide_layout.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Annotated, Any
1+
from typing import Annotated, Any, ClassVar
22

33
from tppt.slide_layout import (
44
DefaultTitleSlide,
@@ -80,3 +80,34 @@ class DerivedLayout(BaseLayout):
8080
assert "derived_field" in derived_placeholders
8181
assert derived_placeholders["base_field"] is str
8282
assert derived_placeholders["derived_field"] is int
83+
84+
def test_non_placeholder_fields(self):
85+
"""Test that non-placeholder fields are not included in the result."""
86+
87+
class MixedLayout(SlideLayout):
88+
# Placeholder fields
89+
title: Placeholder[str]
90+
subtitle: Placeholder[str | None] = None
91+
92+
# Regular fields (not placeholders)
93+
regular_str: str = "default"
94+
regular_int: int = 42
95+
regular_list: list[str] = []
96+
97+
# Class variable (should also be ignored)
98+
class_var: ClassVar[bool] = True
99+
100+
placeholders = get_placeholders(MixedLayout)
101+
102+
# Only placeholder fields should be included
103+
assert len(placeholders) == 2
104+
assert "title" in placeholders
105+
assert "subtitle" in placeholders
106+
107+
# Regular fields should not be included
108+
assert "regular_str" not in placeholders
109+
assert "regular_int" not in placeholders
110+
assert "regular_list" not in placeholders
111+
112+
# Class variables should not be included
113+
assert "class_var" not in placeholders

0 commit comments

Comments
 (0)