Skip to content

Commit 0d4a50e

Browse files
authored
Merge pull request #168 from bckohan/v3.x.x
fix tests for django-enum >= 2.0
2 parents 20633c5 + 7526304 commit 0d4a50e

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

doc/source/templatetags.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,18 @@ we might define a simple color enumeration like so:
527527

528528
.. code:: python
529529
530+
import typing as t
530531
from django.db import models
531-
from django_enum import EnumField, TextChoices
532-
from enum_properties import p, s
532+
from django_enum import EnumField
533+
from django_enum.choices import TextChoices
534+
from enum_properties import Symmetric, s
533535
534536
class ExampleModel(models.Model):
535537
536-
class Color(TextChoices, s('rgb'), s('hex', case_fold=True)):
538+
class Color(TextChoices):
539+
540+
rgb: t.Annotated[t.Tuple[int, int, int], Symmetric()]
541+
hex: t.Annotated[str, Symmetric(case_fold=True)]
537542
538543
# name value label rgb hex
539544
RED = 'R', 'Red', (1, 0, 0), 'ff0000'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PyYAML = { version = ">=5.1,<7.0", optional = true }
5252
django-typer = "^2.1.1"
5353

5454
[tool.poetry.group.dev.dependencies]
55-
django-enum = ">=1.1.0"
55+
django-enum = ">=2.0.0"
5656
enum-properties = ">=1.1.1"
5757
pytest = "^8.0"
5858
pytest-django = ">=4.8.0"

tests/enum_app/enums.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
2-
3-
from enum_properties import EnumProperties, s
2+
from typing_extensions import Annotated
3+
from enum_properties import EnumProperties, Symmetric
44

55

66
class IndependentEnum(Enum):
@@ -9,7 +9,9 @@ class IndependentEnum(Enum):
99
VALUE2 = 22
1010

1111

12-
class DependentEnum(EnumProperties, s("indep")):
12+
class DependentEnum(EnumProperties):
13+
indep: Annotated[IndependentEnum, Symmetric()]
14+
1315
VALUE0 = 0, IndependentEnum.VALUE2
1416
VALUE1 = 1, IndependentEnum.VALUE1
1517
VALUE2 = 2, IndependentEnum.VALUE0

tests/enum_app/models.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import typing as t
2+
from typing_extensions import Annotated
13
from django.db import models
2-
from django_enum import EnumField, IntegerChoices, TextChoices
3-
from enum_properties import p, s
4+
from django_enum import EnumField
5+
from django_enum.choices import IntegerChoices, TextChoices
6+
from enum_properties import Symmetric, s
47

58
try:
69
from django.utils.decorators import classproperty
@@ -12,7 +15,10 @@ class EnumTester(models.Model):
1215
class NotAnEnum:
1316
pass
1417

15-
class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
18+
class Color(TextChoices):
19+
rgb: Annotated[t.Tuple[int, int, int], Symmetric()]
20+
hex: Annotated[str, Symmetric(case_fold=True)]
21+
1622
# name value label rgb hex
1723
RED = "R", "Red", (1, 0, 0), "ff0000"
1824
GREEN = "G", "Green", (0, 1, 0), "00ff00"
@@ -22,13 +28,16 @@ class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
2228
def class_name(cls):
2329
return cls.__name__
2430

25-
class MapBoxStyle(IntegerChoices, s("slug", case_fold=True), p("version")):
31+
class MapBoxStyle(IntegerChoices):
2632
"""
2733
https://docs.mapbox.com/api/maps/styles/
2834
"""
2935

3036
_symmetric_builtins_ = ["name", "uri", "label"]
3137

38+
slug: Annotated[str, Symmetric(case_fold=True)]
39+
version: int
40+
3241
# name value label slug version
3342
STREETS = 1, "Streets", "streets", 11
3443
OUTDOORS = 2, "Outdoors", "outdoors", 11
@@ -54,9 +63,12 @@ def docs(cls):
5463
# def __str__(self):
5564
# return self.uri
5665

57-
class AddressRoute(TextChoices, s("alt", case_fold=True), p("str")):
66+
class AddressRoute(TextChoices):
5867
_symmetric_builtins_ = [s("name", case_fold=True)]
5968

69+
alt: Annotated[t.List[str], Symmetric(case_fold=True)]
70+
str: str
71+
6072
# name value alt
6173
ALLEY = (
6274
"ALY",

tests/examples/models.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import typing as t
12
from django.db import models
2-
from django_enum import EnumField, IntegerChoices, TextChoices
3-
from enum_properties import p, s
3+
from django_enum import EnumField
4+
from django_enum.choices import IntegerChoices, TextChoices
5+
from enum_properties import Symmetric, s
6+
from typing_extensions import Annotated
47

58
try:
69
from django.utils.decorators import classproperty
@@ -16,19 +19,26 @@ class ExampleModel(models.Model):
1619

1720
define_field = models.CharField(choices=DEFINES, max_length=2)
1821

19-
class Color(TextChoices, s("rgb"), s("hex", case_fold=True)):
22+
class Color(TextChoices):
23+
24+
rgb: Annotated[t.Tuple[int, int, int], Symmetric()]
25+
hex: Annotated[str, Symmetric(case_fold=True)]
26+
2027
# name value label rgb hex
2128
RED = "R", "Red", (1, 0, 0), "ff0000"
2229
GREEN = "G", "Green", (0, 1, 0), "00ff00"
2330
BLUE = "B", "Blue", (0, 0, 1), "0000ff"
2431

25-
class MapBoxStyle(IntegerChoices, s("slug", case_fold=True), p("version")):
32+
class MapBoxStyle(IntegerChoices):
2633
"""
2734
https://docs.mapbox.com/api/maps/styles/
2835
"""
2936

3037
_symmetric_builtins_ = ["name", "uri", "label"]
3138

39+
slug: Annotated[str, Symmetric(case_fold=True)]
40+
version: int
41+
3242
# name value label slug version
3343
STREETS = 1, "Streets", "streets", 11
3444
OUTDOORS = 2, "Outdoors", "outdoors", 11

tests/traverse/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django_enum import IntegerChoices, TextChoices
1+
from django_enum.choices import IntegerChoices, TextChoices
22
from enum_properties import p, s
33

44

0 commit comments

Comments
 (0)