@@ -90,13 +90,10 @@ def verify(p, filename=None, exit=True):
90
90
click .secho ('Error calling "{0}".' .format (filename ), fg = 'red' )
91
91
click .secho (time_info , fg = 'cyan' )
92
92
93
- # Exit here if appropriate, otherwise return None (for --verify-all)
94
- if exit :
95
- sys .exit (1 )
96
- else :
97
- return None
93
+ # Return None if option is not --verify-all, otherwise exit
94
+ return sys .exit (1 ) if exit else None
98
95
99
- # Python 3 returns bytes; use a valid encoding like ASCII
96
+ # Decode output if returned as bytes (Python 3)
100
97
if isinstance (stdout , bytes ):
101
98
output = stdout .decode ('ascii' )
102
99
@@ -117,15 +114,12 @@ def verify(p, filename=None, exit=True):
117
114
118
115
click .secho (time_info , fg = 'cyan' )
119
116
120
- # Exit here if answer was incorrect
121
- if exit and not is_correct :
122
- sys .exit (1 )
123
- else :
124
- # Remove any suffix from the filename if its solution is correct
125
- if is_correct and filename != p .filename :
126
- rename_file (filename , p .filename )
117
+ # Remove any suffix from the filename if its solution is correct
118
+ if is_correct and filename != p .filename :
119
+ rename_file (filename , p .filename )
127
120
128
- return is_correct
121
+ # Exit here if answer was incorrect, otherwise return is_correct value
122
+ return sys .exit (1 ) if exit and not is_correct else is_correct
129
123
130
124
131
125
# --verify-all
@@ -135,6 +129,15 @@ def verify_all(current_p):
135
129
prints an overview of the status of each problem.
136
130
"""
137
131
132
+ # Define various problem statuses
133
+ status = {
134
+ 'correct' : click .style ('C' , fg = 'green' , bold = True ),
135
+ 'incorrect' : click .style ('I' , fg = 'red' , bold = True ),
136
+ 'error' : click .style ('E' , fg = 'yellow' , bold = True ),
137
+ 'skipped' : click .style ('S' , fg = 'cyan' , bold = True ),
138
+ 'missing' : click .style ('.' , fg = 'white' , bold = True ),
139
+ }
140
+
138
141
overview = {}
139
142
140
143
# Search through problem files using glob module
@@ -146,14 +149,14 @@ def verify_all(current_p):
146
149
try :
147
150
is_correct = verify (p , filename = filename , exit = False )
148
151
except KeyboardInterrupt :
149
- overview [p .num ] = click . style ( 'S' , fg = 'cyan' )
152
+ overview [p .num ] = status [ 'skipped' ]
150
153
else :
151
154
if is_correct is None : # error was returned by problem file
152
- overview [p .num ] = click . style ( 'E' , fg = 'yellow' )
155
+ overview [p .num ] = status [ 'error' ]
153
156
elif is_correct :
154
- overview [p .num ] = click . style ( 'C' , fg = 'green' )
157
+ overview [p .num ] = status [ 'correct' ]
155
158
elif not is_correct :
156
- overview [p .num ] = click . style ( 'I' , fg = 'red' )
159
+ overview [p .num ] = status [ 'incorrect' ]
157
160
158
161
# Attempt to add "skipped" suffix to the filename if the
159
162
# problem file is not the current problem. This is useful
@@ -171,19 +174,11 @@ def verify_all(current_p):
171
174
sys .exit (1 )
172
175
173
176
# Print overview of the status of each problem
174
- click .echo ('-' * 63 )
175
-
176
- legend = ', ' .join (
177
- '{0} = {1}' .format (click .style (symbol , bold = True , fg = colour ), name )
178
- for symbol , name , colour in (
179
- ('C' , 'correct' , 'green' ),
180
- ('I' , 'incorrect' , 'red' ),
181
- ('E' , 'error' , 'yellow' ),
182
- ('S' , 'skipped' , 'cyan' ),
183
- ('.' , 'missing' , 'white' ),
184
- )
177
+ legend = ', ' .join ('{0} = {1}' .format (status [key ], key ) for key in
178
+ ('correct' , 'incorrect' , 'error' , 'skipped' , 'missing' )
185
179
)
186
180
181
+ click .echo ('-' * 63 )
187
182
click .echo (legend + '\n ' )
188
183
189
184
# Rows needed for overview is based on the current problem number
@@ -201,7 +196,7 @@ def verify_all(current_p):
201
196
spacer = ' ' if (problem % 5 == 0 ) else ' '
202
197
203
198
# Start a new line at the end of each row
204
- click .secho (status + spacer , bold = True , nl = (problem % 20 == 0 ))
199
+ click .secho (status + spacer , nl = (problem % 20 == 0 ))
205
200
206
201
click .echo ()
207
202
0 commit comments