enumerific 1.0.5__tar.gz → 1.0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {enumerific-1.0.5/source/enumerific.egg-info → enumerific-1.0.7}/PKG-INFO +32 -1
- {enumerific-1.0.5 → enumerific-1.0.7}/README.md +31 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific/extensible.py +40 -1
- enumerific-1.0.7/source/enumerific/version.txt +1 -0
- {enumerific-1.0.5 → enumerific-1.0.7/source/enumerific.egg-info}/PKG-INFO +32 -1
- {enumerific-1.0.5 → enumerific-1.0.7}/tests/test_extensible_enums.py +68 -6
- enumerific-1.0.5/source/enumerific/version.txt +0 -1
- {enumerific-1.0.5 → enumerific-1.0.7}/LICENSE.md +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/pyproject.toml +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/requirements.development.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/requirements.distribution.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/requirements.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/setup.cfg +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific/__init__.py +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific/exceptions.py +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific/logging.py +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific/standard.py +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific.egg-info/SOURCES.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific.egg-info/dependency_links.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific.egg-info/requires.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific.egg-info/top_level.txt +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/source/enumerific.egg-info/zip-safe +0 -0
- {enumerific-1.0.5 → enumerific-1.0.7}/tests/test_enumerific_library.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enumerific
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.7
|
|
4
4
|
Summary: Simplifies working with Python enums.
|
|
5
5
|
Author: Daniel Sissman
|
|
6
6
|
License-Expression: MIT
|
|
@@ -468,6 +468,11 @@ assert Colors.BLUE.aliased is False
|
|
|
468
468
|
assert Colors.RED.aliases == [Colors.ROUGE]
|
|
469
469
|
assert Colors.GREEN.aliases == [Colors.VERTE]
|
|
470
470
|
assert Colors.BLUE.aliases == [] # BLUE has not been aliased
|
|
471
|
+
|
|
472
|
+
# The names including any aliases for an option can be obtained via the .named property
|
|
473
|
+
assert Colors.RED.named == ["RED", "ROUGE"]
|
|
474
|
+
assert Colors.GREEN.named == ["GREEN", "VERTE"]
|
|
475
|
+
assert Colors.BLUE.named == ["BLUE"]
|
|
471
476
|
```
|
|
472
477
|
|
|
473
478
|
#### Example 15: Non-Unique Options
|
|
@@ -670,6 +675,32 @@ assert Colors.PURPLE.rgb == (255, 0, 255)
|
|
|
670
675
|
assert Colors.PURPLE.primary is False
|
|
671
676
|
```
|
|
672
677
|
|
|
678
|
+
#### Example 19: Reconciling Enumeration Options via Annotations
|
|
679
|
+
|
|
680
|
+
```python
|
|
681
|
+
from enumerific import Enumeration, auto
|
|
682
|
+
|
|
683
|
+
class Colors(Enumeration):
|
|
684
|
+
"""Create a test Color enumeration based on the Enumeration class"""
|
|
685
|
+
|
|
686
|
+
RED = auto(RGB=(255, 0, 0))
|
|
687
|
+
GREEN = auto(RGB=(0, 255, 0))
|
|
688
|
+
BLUE = auto(RGB=(0, 0, 255))
|
|
689
|
+
|
|
690
|
+
# Ensure that the Colors enumeration subclass is of the expected types
|
|
691
|
+
assert issubclass(Colors, Enumeration)
|
|
692
|
+
|
|
693
|
+
# Attempt to reconcile a Color against one of its annotations
|
|
694
|
+
color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
|
|
695
|
+
|
|
696
|
+
assert isinstance(color, Colors)
|
|
697
|
+
assert isinstance(color, Enumeration)
|
|
698
|
+
|
|
699
|
+
assert color.name == "RED"
|
|
700
|
+
assert color.value == 1
|
|
701
|
+
assert color.RGB == (255, 0, 0)
|
|
702
|
+
```
|
|
703
|
+
|
|
673
704
|
# Enumerific Library Enumerations: Classes & Methods
|
|
674
705
|
|
|
675
706
|
The Enumerific library's `Enumeration` class is a greenfield implementation of enumerations
|
|
@@ -438,6 +438,11 @@ assert Colors.BLUE.aliased is False
|
|
|
438
438
|
assert Colors.RED.aliases == [Colors.ROUGE]
|
|
439
439
|
assert Colors.GREEN.aliases == [Colors.VERTE]
|
|
440
440
|
assert Colors.BLUE.aliases == [] # BLUE has not been aliased
|
|
441
|
+
|
|
442
|
+
# The names including any aliases for an option can be obtained via the .named property
|
|
443
|
+
assert Colors.RED.named == ["RED", "ROUGE"]
|
|
444
|
+
assert Colors.GREEN.named == ["GREEN", "VERTE"]
|
|
445
|
+
assert Colors.BLUE.named == ["BLUE"]
|
|
441
446
|
```
|
|
442
447
|
|
|
443
448
|
#### Example 15: Non-Unique Options
|
|
@@ -640,6 +645,32 @@ assert Colors.PURPLE.rgb == (255, 0, 255)
|
|
|
640
645
|
assert Colors.PURPLE.primary is False
|
|
641
646
|
```
|
|
642
647
|
|
|
648
|
+
#### Example 19: Reconciling Enumeration Options via Annotations
|
|
649
|
+
|
|
650
|
+
```python
|
|
651
|
+
from enumerific import Enumeration, auto
|
|
652
|
+
|
|
653
|
+
class Colors(Enumeration):
|
|
654
|
+
"""Create a test Color enumeration based on the Enumeration class"""
|
|
655
|
+
|
|
656
|
+
RED = auto(RGB=(255, 0, 0))
|
|
657
|
+
GREEN = auto(RGB=(0, 255, 0))
|
|
658
|
+
BLUE = auto(RGB=(0, 0, 255))
|
|
659
|
+
|
|
660
|
+
# Ensure that the Colors enumeration subclass is of the expected types
|
|
661
|
+
assert issubclass(Colors, Enumeration)
|
|
662
|
+
|
|
663
|
+
# Attempt to reconcile a Color against one of its annotations
|
|
664
|
+
color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
|
|
665
|
+
|
|
666
|
+
assert isinstance(color, Colors)
|
|
667
|
+
assert isinstance(color, Enumeration)
|
|
668
|
+
|
|
669
|
+
assert color.name == "RED"
|
|
670
|
+
assert color.value == 1
|
|
671
|
+
assert color.RGB == (255, 0, 0)
|
|
672
|
+
```
|
|
673
|
+
|
|
643
674
|
# Enumerific Library Enumerations: Classes & Methods
|
|
644
675
|
|
|
645
676
|
The Enumerific library's `Enumeration` class is a greenfield implementation of enumerations
|
|
@@ -1458,6 +1458,7 @@ class EnumerationMetaClass(type):
|
|
|
1458
1458
|
value: Enumeration | object = None,
|
|
1459
1459
|
name: str = None,
|
|
1460
1460
|
caselessly: bool = False,
|
|
1461
|
+
annotation: str = None,
|
|
1461
1462
|
) -> Enumeration | None:
|
|
1462
1463
|
"""The 'reconcile' method can be used to reconcile Enumeration type, enumeration
|
|
1463
1464
|
values, or enumeration names to their matching Enumeration type instances. If a
|
|
@@ -1480,7 +1481,23 @@ class EnumerationMetaClass(type):
|
|
|
1480
1481
|
reconciled: Enumeration = None
|
|
1481
1482
|
|
|
1482
1483
|
for attribute, enumeration in self._enumerations.items():
|
|
1483
|
-
if isinstance(
|
|
1484
|
+
if isinstance(annotation, str):
|
|
1485
|
+
if annotation in enumeration._annotations:
|
|
1486
|
+
if enumeration._annotations[annotation] is value:
|
|
1487
|
+
reconciled = enumeration
|
|
1488
|
+
break
|
|
1489
|
+
elif enumeration._annotations[annotation] == value:
|
|
1490
|
+
reconciled = enumeration
|
|
1491
|
+
break
|
|
1492
|
+
else:
|
|
1493
|
+
raise EnumerationOptionError(
|
|
1494
|
+
"The enumeration option, %s, has no '%s' annotation!"
|
|
1495
|
+
% (
|
|
1496
|
+
enumeration,
|
|
1497
|
+
annotation,
|
|
1498
|
+
)
|
|
1499
|
+
)
|
|
1500
|
+
elif isinstance(value, Enumeration):
|
|
1484
1501
|
if enumeration is value:
|
|
1485
1502
|
reconciled = enumeration
|
|
1486
1503
|
break
|
|
@@ -1797,6 +1814,28 @@ class Enumeration(metaclass=EnumerationMetaClass):
|
|
|
1797
1814
|
|
|
1798
1815
|
return aliases
|
|
1799
1816
|
|
|
1817
|
+
@property
|
|
1818
|
+
def named(self) -> list[str]:
|
|
1819
|
+
logger.debug(
|
|
1820
|
+
"%s.names() >>> id(%s) => %s (%s)",
|
|
1821
|
+
self.__class__.__name__,
|
|
1822
|
+
self,
|
|
1823
|
+
id(self._enumerations),
|
|
1824
|
+
type(self._enumerations),
|
|
1825
|
+
)
|
|
1826
|
+
|
|
1827
|
+
names: list[Enumeration] = [self.name]
|
|
1828
|
+
|
|
1829
|
+
for name, enumeration in self._enumerations.items():
|
|
1830
|
+
logger.debug(" >>> checking for alias: %s => %s", name, enumeration)
|
|
1831
|
+
|
|
1832
|
+
if isinstance(enumeration, Enumeration):
|
|
1833
|
+
if self is enumeration and enumeration.name != name:
|
|
1834
|
+
if not name in names:
|
|
1835
|
+
names.append(name)
|
|
1836
|
+
|
|
1837
|
+
return names
|
|
1838
|
+
|
|
1800
1839
|
|
|
1801
1840
|
class EnumerationType(Enumeration, typecast=False):
|
|
1802
1841
|
"""The EnumerationType class represents the type of value held by an enumeration."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.7
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: enumerific
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.7
|
|
4
4
|
Summary: Simplifies working with Python enums.
|
|
5
5
|
Author: Daniel Sissman
|
|
6
6
|
License-Expression: MIT
|
|
@@ -468,6 +468,11 @@ assert Colors.BLUE.aliased is False
|
|
|
468
468
|
assert Colors.RED.aliases == [Colors.ROUGE]
|
|
469
469
|
assert Colors.GREEN.aliases == [Colors.VERTE]
|
|
470
470
|
assert Colors.BLUE.aliases == [] # BLUE has not been aliased
|
|
471
|
+
|
|
472
|
+
# The names including any aliases for an option can be obtained via the .named property
|
|
473
|
+
assert Colors.RED.named == ["RED", "ROUGE"]
|
|
474
|
+
assert Colors.GREEN.named == ["GREEN", "VERTE"]
|
|
475
|
+
assert Colors.BLUE.named == ["BLUE"]
|
|
471
476
|
```
|
|
472
477
|
|
|
473
478
|
#### Example 15: Non-Unique Options
|
|
@@ -670,6 +675,32 @@ assert Colors.PURPLE.rgb == (255, 0, 255)
|
|
|
670
675
|
assert Colors.PURPLE.primary is False
|
|
671
676
|
```
|
|
672
677
|
|
|
678
|
+
#### Example 19: Reconciling Enumeration Options via Annotations
|
|
679
|
+
|
|
680
|
+
```python
|
|
681
|
+
from enumerific import Enumeration, auto
|
|
682
|
+
|
|
683
|
+
class Colors(Enumeration):
|
|
684
|
+
"""Create a test Color enumeration based on the Enumeration class"""
|
|
685
|
+
|
|
686
|
+
RED = auto(RGB=(255, 0, 0))
|
|
687
|
+
GREEN = auto(RGB=(0, 255, 0))
|
|
688
|
+
BLUE = auto(RGB=(0, 0, 255))
|
|
689
|
+
|
|
690
|
+
# Ensure that the Colors enumeration subclass is of the expected types
|
|
691
|
+
assert issubclass(Colors, Enumeration)
|
|
692
|
+
|
|
693
|
+
# Attempt to reconcile a Color against one of its annotations
|
|
694
|
+
color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
|
|
695
|
+
|
|
696
|
+
assert isinstance(color, Colors)
|
|
697
|
+
assert isinstance(color, Enumeration)
|
|
698
|
+
|
|
699
|
+
assert color.name == "RED"
|
|
700
|
+
assert color.value == 1
|
|
701
|
+
assert color.RGB == (255, 0, 0)
|
|
702
|
+
```
|
|
703
|
+
|
|
673
704
|
# Enumerific Library Enumerations: Classes & Methods
|
|
674
705
|
|
|
675
706
|
The Enumerific library's `Enumeration` class is a greenfield implementation of enumerations
|
|
@@ -380,24 +380,57 @@ def test_extensible_enumeration_integer_non_unique():
|
|
|
380
380
|
BLUE = 3
|
|
381
381
|
ROUGE = 1
|
|
382
382
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
) # while there are only 3 distinct values, there are 4 options
|
|
383
|
+
# While there are only 3 distinct values, there are 4 options, due the alias for RED
|
|
384
|
+
assert len(Colors) == 4
|
|
386
385
|
|
|
387
|
-
|
|
386
|
+
# Ensure that the keys, names, values, items and options methods return as expected
|
|
387
|
+
assert Colors.keys() == ["RED", "GREEN", "BLUE", "ROUGE"]
|
|
388
|
+
assert Colors.names() == ["RED", "GREEN", "BLUE", "ROUGE"]
|
|
389
|
+
assert Colors.values() == [1, 2, 3, 1]
|
|
390
|
+
assert Colors.items() == [("RED", 1), ("GREEN", 2), ("BLUE", 3), ("ROUGE", 1)]
|
|
391
|
+
assert Colors.options() == {"RED": 1, "GREEN": 2, "BLUE": 3, "ROUGE": 1}
|
|
388
392
|
|
|
393
|
+
# Ensure that the aliased option has the expected identity and equality
|
|
394
|
+
assert Colors.RED is Colors.ROUGE # As ROUGE is an alias of RED, identity matches
|
|
395
|
+
assert Colors.RED == Colors.ROUGE # As ROUGE is an alias of RED, equality matches
|
|
396
|
+
|
|
397
|
+
# Ensure that the property values of RED are as expected
|
|
389
398
|
assert Colors.RED.name == "RED"
|
|
390
399
|
assert Colors.RED.value == 1
|
|
400
|
+
assert Colors.RED.aliased is True
|
|
401
|
+
assert Colors.RED.aliases == [Colors.ROUGE]
|
|
402
|
+
assert Colors.RED.named == ["RED", "ROUGE"]
|
|
391
403
|
|
|
404
|
+
# Ensure that the property values of ROUGE are as expected (as an alias of RED)
|
|
392
405
|
assert Colors.ROUGE.name == "RED"
|
|
393
406
|
assert Colors.ROUGE.value == 1
|
|
407
|
+
assert Colors.ROUGE.aliased is True
|
|
408
|
+
assert Colors.ROUGE.aliases == [Colors.RED]
|
|
409
|
+
assert Colors.ROUGE.named == ["RED", "ROUGE"]
|
|
410
|
+
|
|
411
|
+
# Ensure that the property values of GREEN are as expected
|
|
412
|
+
assert Colors.GREEN.name == "GREEN"
|
|
413
|
+
assert Colors.GREEN.value == 2
|
|
414
|
+
assert Colors.GREEN.aliased is False
|
|
415
|
+
assert Colors.GREEN.aliases == []
|
|
416
|
+
assert Colors.GREEN.named == ["GREEN"]
|
|
417
|
+
|
|
418
|
+
# Ensure that the property values of BLUE are as expected
|
|
419
|
+
assert Colors.BLUE.name == "BLUE"
|
|
420
|
+
assert Colors.BLUE.value == 3
|
|
421
|
+
assert Colors.BLUE.aliased is False
|
|
422
|
+
assert Colors.BLUE.aliases == []
|
|
423
|
+
assert Colors.BLUE.named == ["BLUE"]
|
|
394
424
|
|
|
425
|
+
# We can find the aliases for the Colors enumeration by finding the options with
|
|
426
|
+
# names that do no match their associated enumeration option name:
|
|
395
427
|
assert [
|
|
396
428
|
name for name, option in Colors.__options__.items() if option.name != name
|
|
397
429
|
] == [
|
|
398
430
|
"ROUGE"
|
|
399
431
|
] # ROUGE is an alias, so its name does not match the option it maps to
|
|
400
432
|
|
|
433
|
+
# Ensure that the aliases map is as expected
|
|
401
434
|
assert len(Colors.__aliases__) == 1
|
|
402
435
|
assert Colors.__aliases__ == {"ROUGE": Colors.RED}
|
|
403
436
|
assert list(Colors.__aliases__.items()) == [("ROUGE", Colors.RED)]
|
|
@@ -1580,8 +1613,8 @@ def test_membership_in_tuple():
|
|
|
1580
1613
|
assert Colors.VIOLET not in colors
|
|
1581
1614
|
|
|
1582
1615
|
|
|
1583
|
-
def
|
|
1584
|
-
"""Test access to
|
|
1616
|
+
def test_annotation_access():
|
|
1617
|
+
"""Test access to annotations (methods, properties, etc) on an Enumeration subclass"""
|
|
1585
1618
|
|
|
1586
1619
|
class Colors(Enumeration, backfill=True):
|
|
1587
1620
|
"""Create a test Color enumeration based on the Enumeration class"""
|
|
@@ -1779,3 +1812,32 @@ def test_attribute_access():
|
|
|
1779
1812
|
assert color.isMetallic() is False # isMetallic() is defined on the Colors subclass
|
|
1780
1813
|
assert color.HEX == "FF0000" # HEX is a property defined on the Colors subclass
|
|
1781
1814
|
assert color.count() == 8 # count() is a classmethod defined on the Colors subclass
|
|
1815
|
+
|
|
1816
|
+
|
|
1817
|
+
def test_annotation_reconciliation():
|
|
1818
|
+
"""Test reconciliation of enumeration options via their annotations."""
|
|
1819
|
+
|
|
1820
|
+
class Colors(Enumeration):
|
|
1821
|
+
"""Create a test Color enumeration based on the Enumeration class"""
|
|
1822
|
+
|
|
1823
|
+
RED = auto(RGB=(255, 0, 0))
|
|
1824
|
+
ORANGE = auto(RGB=(255, 165, 0))
|
|
1825
|
+
YELLOW = auto(RGB=(255, 255, 0))
|
|
1826
|
+
GREEN = auto(RGB=(0, 255, 0))
|
|
1827
|
+
BLUE = auto(RGB=(0, 0, 255))
|
|
1828
|
+
VIOLET = auto(RGB=(255, 0, 255))
|
|
1829
|
+
|
|
1830
|
+
# Ensure that the Colors enumeration subclass is of the expected types
|
|
1831
|
+
assert issubclass(Colors, Enumeration)
|
|
1832
|
+
assert issubclass(Colors, EnumerationInteger)
|
|
1833
|
+
|
|
1834
|
+
# Attempt to reconcile a Color against one of its annotations
|
|
1835
|
+
color = Colors.reconcile(value=(255, 0, 0), annotation="RGB")
|
|
1836
|
+
|
|
1837
|
+
assert isinstance(color, Colors)
|
|
1838
|
+
assert isinstance(color, Enumeration)
|
|
1839
|
+
assert isinstance(color, EnumerationInteger)
|
|
1840
|
+
|
|
1841
|
+
assert color.name == "RED"
|
|
1842
|
+
assert color.value == 1
|
|
1843
|
+
assert color.RGB == (255, 0, 0)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1.0.5
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|