Skip to content

Commit

Permalink
add a chained test
Browse files Browse the repository at this point in the history
  • Loading branch information
bckohan committed Sep 10, 2024
1 parent 57db314 commit 09be387
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/annotations/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Color(IntEnumProperties):
GREEN = 2, "Verde", (0, 1, 0), "00ff00"
BLUE = 3, "Azul", (0, 0, 1), "0000ff"

self.assertEqual(list(Color), [Color.RED, Color.GREEN, Color.BLUE])

self.assertEqual(Color.RED, Color((1, 0, 0)))
self.assertEqual(Color.RED, Color("ff0000"))
self.assertEqual(Color.RED, Color("FF0000"))
Expand Down Expand Up @@ -148,6 +150,8 @@ class Color(EnumProperties):
GREEN = 2, "Verde", (0, 1, 0), "00ff00"
BLUE = 3, "Azul", (0, 0, 1), "0000ff"

self.assertEqual(list(Color), [Color.RED, Color.GREEN, Color.BLUE])

self.assertEqual(
[prop for prop in Color._properties_ if getattr(prop, "symmetric", False)],
["rgb", "hex"],
Expand Down Expand Up @@ -909,3 +913,27 @@ class MyEnum3(EnumProperties):

with self.assertRaises(AttributeError):
MyEnum3.VALUE1.label

def test_reference_enums(self):
from enum import Enum
from typing_extensions import Annotated
from enum_properties import EnumProperties, Symmetric

class IndependentEnum(Enum):
VALUE0 = 20
VALUE1 = 21
VALUE2 = 22

class DependentEnum(EnumProperties):
indep: Annotated[IndependentEnum, Symmetric()]

VALUE0 = 0, IndependentEnum.VALUE2
VALUE1 = 1, IndependentEnum.VALUE1
VALUE2 = 2, IndependentEnum.VALUE0

self.assertEqual(
list(DependentEnum),
[DependentEnum.VALUE0, DependentEnum.VALUE1, DependentEnum.VALUE2],
)

self.assertTrue(DependentEnum(IndependentEnum.VALUE1) is DependentEnum.VALUE1)

0 comments on commit 09be387

Please sign in to comment.