@@ -44,6 +44,48 @@ class Test({0}):
4444 'lower, UPPER = field' ,
4545]
4646
47+ custom_enum_base_class = """
48+ class BaseEnum(enum.Enum):
49+ def __init__(self, short: str, long: str) -> None:
50+ self.short = short
51+ self.long = long
52+
53+ class ConcreteEnum(BaseEnum):
54+ HELLO = 'h', 'hello'
55+ WORLD = 'w', 'world'
56+ """
57+
58+
59+ multiple_custom_enum_bases = """
60+ class FirstEnum(enum.Enum):
61+ pass
62+
63+ class SecondEnum(enum.Enum):
64+ pass
65+
66+ class FirstEnumSuccessor(FirstEnum):
67+ HELLO = 'hello'
68+ WORLD = 'world'
69+
70+ class SecondEnumSuccessor(SecondEnum):
71+ PING = 'pong'
72+
73+ class MultiInheritanceEnum(FirstEnum, SecondEnum):
74+ MULTI = 'multi'
75+ """
76+
77+ dotted_names_enum_bases = """
78+ from src import constants
79+
80+ class FirstEnum(constants.MyEnum):
81+ HELLO = 'hello'
82+ WORLD = 'world'
83+
84+ class SecondEnum(constants.MyEnum):
85+ HELLO = 'hello'
86+ WORLD = 'world'
87+ """
88+
4789
4890@pytest .mark .parametrize (
4991 'code' ,
@@ -202,3 +244,56 @@ def test_regression423(
202244 visitor .run ()
203245
204246 assert_errors (visitor , [])
247+
248+
249+ @pytest .mark .parametrize ('with_configuration' , [True , False ])
250+ def test_custom_enum_base_class_with_config (
251+ assert_errors ,
252+ parse_ast_tree ,
253+ options ,
254+ with_configuration ,
255+ ):
256+ """Testing that custom enum base classes work with configuration."""
257+ tree = parse_ast_tree (custom_enum_base_class )
258+
259+ if with_configuration :
260+ options_with_config = options (known_enum_bases = ('BaseEnum' ,))
261+ visitor = WrongNameVisitor (options_with_config , tree = tree )
262+ visitor .run ()
263+ assert_errors (visitor , [])
264+ else :
265+ options_without_config = options ()
266+ visitor = WrongNameVisitor (options_without_config , tree = tree )
267+ visitor .run ()
268+ assert_errors (
269+ visitor ,
270+ [UpperCaseAttributeViolation , UpperCaseAttributeViolation ],
271+ )
272+
273+
274+ def test_multiple_custom_enum_bases_with_config (
275+ assert_errors ,
276+ parse_ast_tree ,
277+ options ,
278+ ):
279+ """Testing that multiple custom enum base classes work with config."""
280+ tree = parse_ast_tree (multiple_custom_enum_bases )
281+
282+ options = options (known_enum_bases = ('FirstEnum' , 'SecondEnum' ))
283+ visitor = WrongNameVisitor (options , tree = tree )
284+ visitor .run ()
285+ assert_errors (visitor , [])
286+
287+
288+ def test_dotted_names_in_enum_bases_config (
289+ assert_errors ,
290+ parse_ast_tree ,
291+ options ,
292+ ):
293+ """Testing that dotted names in enum bases config work correctly."""
294+ tree = parse_ast_tree (dotted_names_enum_bases )
295+
296+ options = options (known_enum_bases = ('constants.MyEnum' ,))
297+ visitor = WrongNameVisitor (options , tree = tree )
298+ visitor .run ()
299+ assert_errors (visitor , [])
0 commit comments