Drop as_dict() method from ChoiceSet

This commit is contained in:
jeremystretch 2021-12-16 10:22:05 -05:00
parent 124302908a
commit 1902ecb8ca
4 changed files with 3 additions and 13 deletions

View File

@ -167,8 +167,8 @@ class Report(object):
"""
Log a message from a test method. Do not call this method directly; use one of the log_* wrappers below.
"""
if level not in LogLevelChoices.as_dict():
raise Exception("Unknown logging level: {}".format(level))
if level not in LogLevelChoices.values():
raise Exception(f"Unknown logging level: {level}")
self._results[self.active_test]['log'].append((
timezone.now().isoformat(),
level,

View File

@ -12,6 +12,6 @@ def log_level(level):
Display a label indicating a syslog severity (e.g. info, warning, etc.).
"""
return {
'name': LogLevelChoices.as_dict()[level],
'name': dict(LogLevelChoices)[level],
'class': LogLevelChoices.colors.get(level)
}

View File

@ -50,11 +50,6 @@ class ChoiceSet(metaclass=ChoiceSetMeta):
def values(cls):
return [c[0] for c in unpack_grouped_choices(cls._choices)]
@classmethod
def as_dict(cls):
# Unpack grouped choices before casting as a dict
return dict(unpack_grouped_choices(cls._choices))
def unpack_grouped_choices(choices):
"""

View File

@ -30,8 +30,3 @@ class ChoiceSetTestCase(TestCase):
def test_values(self):
self.assertListEqual(ExampleChoices.values(), ['a', 'b', 'c', 1, 2, 3])
def test_as_dict(self):
self.assertEqual(ExampleChoices.as_dict(), {
'a': 'A', 'b': 'B', 'c': 'C', 1: 'One', 2: 'Two', 3: 'Three'
})