Skip to content

Commit e3e5aeb

Browse files
Move tests from TestConfusingConsecutiveElifChecker to functional tests (#5517)
* Remove some redundant test Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent bf52178 commit e3e5aeb

File tree

3 files changed

+111
-205
lines changed

3 files changed

+111
-205
lines changed

tests/extensions/test_confusing_elif.py

Lines changed: 0 additions & 198 deletions
This file was deleted.

tests/functional/ext/confusing_elif/confusing_elif.py

Lines changed: 108 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# pylint: disable=missing-module-docstring, missing-function-docstring
22

3-
def check_config(machine, old_conf, new_conf):
4-
"""Example code that will trigger the message"""
3+
4+
def triggered_if_if_block_ends_with_elif(machine, old_conf, new_conf):
5+
"""Example code that will trigger the message
6+
7+
Given an if-elif construct
8+
When the body of the if ends with an elif
9+
Then the message confusing-consecutive-elif must be triggered.
10+
"""
511
if old_conf:
612
if not new_conf:
713
machine.disable()
@@ -12,8 +18,13 @@ def check_config(machine, old_conf, new_conf):
1218
machine.enable(new_conf.value)
1319

1420

15-
def check_config_2(machine, old_conf, new_conf):
16-
"""Example code must not trigger the message, because the inner block ends with else."""
21+
def not_triggered_if_indented_block_ends_with_else(machine, old_conf, new_conf):
22+
"""Example code must not trigger the message, because the inner block ends with else.
23+
24+
Given an if-elif construct
25+
When the body of the if ends with an else
26+
Then no message shall be triggered.
27+
"""
1728
if old_conf:
1829
if not new_conf:
1930
machine.disable()
@@ -25,10 +36,18 @@ def check_config_2(machine, old_conf, new_conf):
2536
elif new_conf:
2637
machine.enable(new_conf.value)
2738

28-
def check_config_3(machine, old_conf, new_conf):
39+
40+
def not_triggered_if_indentend_block_ends_with_call(machine, old_conf, new_conf):
2941
"""
3042
Example code must not trigger the message,
31-
because the inner if is not the final node of the body.
43+
44+
Given an if-elif construct
45+
When the body of the if ends with a function call
46+
Then no message shall be triggered.
47+
48+
Note: There is nothing special about the body ending with a function call.
49+
This is just taken as a representative value for the equivalence class of
50+
"every node class unrelated to if/elif/else".
3251
"""
3352
if old_conf:
3453
if not new_conf:
@@ -39,3 +58,86 @@ def check_config_3(machine, old_conf, new_conf):
3958
print("Processed old configuration...")
4059
elif new_conf:
4160
machine.enable(new_conf.value)
61+
62+
63+
def triggered_if_elif_block_ends_with_elif(machine, old_conf, new_conf, new_new_conf):
64+
"""Example code that will trigger the message
65+
66+
Given an if-elif-elif construct
67+
When the body of the first elif ends with an elif
68+
Then the message confusing-consecutive-elif must be triggered.
69+
"""
70+
if old_conf:
71+
machine.disable()
72+
elif not new_conf:
73+
if new_new_conf:
74+
machine.disable()
75+
elif old_conf.value != new_conf.value:
76+
machine.disable()
77+
machine.enable(new_conf.value)
78+
elif new_conf: # [confusing-consecutive-elif]
79+
machine.enable(new_conf.value)
80+
81+
82+
def triggered_if_block_ends_with_if(machine, old_conf, new_conf, new_new_conf):
83+
"""Example code that will trigger the message
84+
85+
Given an if-elif construct
86+
When the body of the if ends with an if
87+
Then the message confusing-consecutive-elif must be triggered.
88+
"""
89+
if old_conf:
90+
if new_new_conf:
91+
machine.disable()
92+
elif new_conf: # [confusing-consecutive-elif]
93+
machine.enable(new_conf.value)
94+
95+
96+
def not_triggered_if_indented_block_ends_with_ifexp(machine, old_conf, new_conf):
97+
"""
98+
Example code must not trigger the message,
99+
100+
Given an if-elif construct
101+
When the body of the if ends with an if expression
102+
Then no message shall be triggered.
103+
"""
104+
if old_conf:
105+
if not new_conf:
106+
machine.disable()
107+
print("Processed old configuration...")
108+
elif new_conf:
109+
machine.enable(new_conf.value)
110+
111+
112+
def not_triggered_if_outer_block_does_not_have_elif(machine, old_conf, new_conf):
113+
"""Example code must not trigger the message
114+
115+
Given an if construct without an elif
116+
When the body of the if ends with an if
117+
Then no message shall be triggered.
118+
"""
119+
if old_conf:
120+
if not new_conf:
121+
machine.disable()
122+
elif old_conf.value != new_conf.value:
123+
machine.disable()
124+
machine.enable(new_conf.value)
125+
else:
126+
pass
127+
128+
129+
def not_triggered_if_outer_block_continues_with_if(machine, old_conf, new_conf, new_new_conf):
130+
"""Example code that will trigger the message
131+
132+
Given an if construct which continues with a new if construct
133+
When the body of the first if ends with an if expression
134+
Then no message shall be triggered.
135+
"""
136+
if old_conf:
137+
if new_new_conf:
138+
machine.disable()
139+
elif old_conf.value != new_conf.value:
140+
machine.disable()
141+
machine.enable(new_conf.value)
142+
if new_conf:
143+
machine.enable(new_conf.value)
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
confusing-consecutive-elif:11:4:12:38:check_config:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
1+
confusing-consecutive-elif:17:4:18:38:triggered_if_if_block_ends_with_elif:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
2+
confusing-consecutive-elif:78:4:79:38:triggered_if_elif_block_ends_with_elif:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED
3+
confusing-consecutive-elif:92:4:93:38:triggered_if_block_ends_with_if:Consecutive elif with differing indentation level, consider creating a function to separate the inner elif:UNDEFINED

0 commit comments

Comments
 (0)