1
1
# pylint: disable=missing-module-docstring, missing-function-docstring
2
2
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
+ """
5
11
if old_conf :
6
12
if not new_conf :
7
13
machine .disable ()
@@ -12,8 +18,13 @@ def check_config(machine, old_conf, new_conf):
12
18
machine .enable (new_conf .value )
13
19
14
20
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
+ """
17
28
if old_conf :
18
29
if not new_conf :
19
30
machine .disable ()
@@ -25,10 +36,18 @@ def check_config_2(machine, old_conf, new_conf):
25
36
elif new_conf :
26
37
machine .enable (new_conf .value )
27
38
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 ):
29
41
"""
30
42
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".
32
51
"""
33
52
if old_conf :
34
53
if not new_conf :
@@ -39,3 +58,86 @@ def check_config_3(machine, old_conf, new_conf):
39
58
print ("Processed old configuration..." )
40
59
elif new_conf :
41
60
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 )
0 commit comments