Skip to content

Commit f16238d

Browse files
committed
tests(internal[dataclasses]) Add dataclass tests
1 parent ddc6524 commit f16238d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/_internal/test_dataclasses.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Test dataclasses utilities."""
2+
3+
from __future__ import annotations
4+
5+
import dataclasses
6+
7+
from libtmux._internal.dataclasses import SkipDefaultFieldsReprMixin
8+
9+
10+
@dataclasses.dataclass(repr=False)
11+
class TestItem(SkipDefaultFieldsReprMixin):
12+
"""Test class for SkipDefaultFieldsReprMixin."""
13+
14+
name: str
15+
unit_price: float = 1.00
16+
quantity_on_hand: int = 0
17+
18+
19+
def test_skip_default_fields_repr() -> None:
20+
"""Test SkipDefaultFieldsReprMixin repr behavior."""
21+
# Test with only required field
22+
item1 = TestItem("Test")
23+
assert repr(item1) == "TestItem(name=Test)"
24+
25+
# Test with one default field modified
26+
item2 = TestItem("Test", unit_price=2.00)
27+
assert repr(item2) == "TestItem(name=Test, unit_price=2.0)"
28+
29+
# Test with all fields modified
30+
item3 = TestItem("Test", unit_price=2.00, quantity_on_hand=5)
31+
assert repr(item3) == "TestItem(name=Test, unit_price=2.0, quantity_on_hand=5)"
32+
33+
# Test modifying field after creation
34+
item4 = TestItem("Test")
35+
item4.unit_price = 2.05
36+
assert repr(item4) == "TestItem(name=Test, unit_price=2.05)"
37+
38+
# Test with multiple fields modified after creation
39+
item5 = TestItem("Test")
40+
item5.unit_price = 2.05
41+
item5.quantity_on_hand = 3
42+
assert repr(item5) == "TestItem(name=Test, unit_price=2.05, quantity_on_hand=3)"

0 commit comments

Comments
 (0)