Skip to content

Commit cda6bf6

Browse files
lapack_testing.py: use more idiomatic Python style
Remove C-isms: * remove unnecessary braces in "if" conditions * use booleans instead of 0/1 variables
1 parent 89e8b89 commit cda6bf6

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

lapack_testing.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
print("for help use --help")
1919
sys.exit(2)
2020

21-
short_summary=0
22-
with_file=1
23-
just_errors = 0
21+
short_summary = False
22+
with_file = True
23+
just_errors = False
2424
prec='x'
2525
test='all'
26-
only_numbers=0
26+
only_numbers = False
2727
test_dir='TESTING'
2828
bin_dir='bin/Release'
2929

@@ -64,11 +64,11 @@
6464
sys.exit(0)
6565
else:
6666
if o in ("-s", "--short"):
67-
short_summary = 1
67+
short_summary = True
6868
if o in ("-r", "--run"):
69-
with_file = 0
69+
with_file = False
7070
if o in ("-e", "--error"):
71-
just_errors = 1
71+
just_errors = True
7272
if o in ( '-p', '--prec' ):
7373
prec = a
7474
if o in ( '-b', '--bin' ):
@@ -78,8 +78,8 @@
7878
if o in ( '-t', '--test' ):
7979
test = a
8080
if o in ( '-n', '--number' ):
81-
only_numbers = 1
82-
short_summary = 1
81+
only_numbers = True
82+
short_summary = True
8383

8484
# process options
8585

@@ -105,7 +105,7 @@ def run_summary_test( f, cmdline, short_summary):
105105
nb_test_illegal=0
106106
nb_test_info=0
107107

108-
if (with_file):
108+
if with_file:
109109
if not os.path.exists(cmdline):
110110
error_message=cmdline+" file not found"
111111
r=1
@@ -142,16 +142,16 @@ def run_summary_test( f, cmdline, short_summary):
142142
whereisrun=words_in_line.index("run)")
143143
nb_test_run+=int(words_in_line[whereisrun-2])
144144
if (line.find("out of")!=-1):
145-
if (short_summary==0): print(line, end=' ')
145+
if not short_summary: print(line, end=' ')
146146
whereisout= words_in_line.index("out")
147147
nb_test_fail+=int(words_in_line[whereisout-1])
148148
if ((line.find("illegal")!=-1) or (line.find("Illegal")!=-1)):
149-
if (short_summary==0):print(line, end=' ')
149+
if not short_summary: print(line, end=' ')
150150
nb_test_illegal+=1
151151
if (line.find(" INFO")!=-1):
152-
if (short_summary==0):print(line, end=' ')
152+
if not short_summary: print(line, end=' ')
153153
nb_test_info+=1
154-
if (with_file==1):
154+
if with_file:
155155
pipe.close()
156156

157157
f.flush();
@@ -166,7 +166,7 @@ def run_summary_test( f, cmdline, short_summary):
166166
except IOError:
167167
f = sys.stdout
168168

169-
if (short_summary==0):
169+
if not short_summary:
170170
print(" ")
171171
print("---------------- Testing LAPACK Routines ----------------")
172172
print(" ")
@@ -216,7 +216,7 @@ def run_summary_test( f, cmdline, short_summary):
216216
letter = dtypes[0][dtype]
217217
name = dtypes[1][dtype]
218218

219-
if (short_summary==0):
219+
if not short_summary:
220220
print(" ")
221221
print("------------------------- %s ------------------------" % name)
222222
print(" ")
@@ -249,7 +249,7 @@ def run_summary_test( f, cmdline, short_summary):
249249
# NEED TO SKIP SOME PRECISION (namely s and c) FOR PROTO MIXED PRECISION TESTING
250250
if dtest==17 and (letter=="s" or letter=="c"):
251251
continue
252-
if (with_file==1):
252+
if with_file:
253253
cmdbase=dtests[2][dtest]+".out"
254254
else:
255255
if dtest==16:
@@ -264,7 +264,7 @@ def run_summary_test( f, cmdline, short_summary):
264264
else:
265265
# EIG TESTS
266266
cmdbase="xeigtst"+letter+" < "+dtests[0][dtest]+".in > "+dtests[2][dtest]+".out"
267-
if (not just_errors and not short_summary):
267+
if not just_errors and not short_summary:
268268
print("Testing "+name+" "+dtests[1][dtest]+"-"+cmdbase, end=' ')
269269
# Run the process: either to read the file or run the LAPACK testing
270270
nb_test = run_summary_test(f, cmdbase, short_summary)
@@ -274,19 +274,19 @@ def run_summary_test( f, cmdline, short_summary):
274274
list_results[3][dtype]+=nb_test[3]
275275
got_error=nb_test[1]+nb_test[2]+nb_test[3]
276276

277-
if (not short_summary):
278-
if (nb_test[0]>0 and just_errors==0):
277+
if not short_summary:
278+
if nb_test[0] > 0 and not just_errors:
279279
print("passed: "+str(nb_test[0]))
280-
if (nb_test[1]>0):
280+
if nb_test[1] > 0:
281281
print("failing to pass the threshold: "+str(nb_test[1]))
282-
if (nb_test[2]>0):
282+
if nb_test[2] > 0:
283283
print("Illegal Error: "+str(nb_test[2]))
284-
if (nb_test[3]>0):
284+
if nb_test[3] > 0:
285285
print("Info Error: "+str(nb_test[3]))
286-
if (got_error>0 and just_errors==1):
286+
if got_error > 0 and just_errors:
287287
print("ERROR IS LOCATED IN "+name+" "+dtests[1][dtest]+" [ "+cmdbase+" ]")
288288
print("")
289-
if (just_errors==0):
289+
if not just_errors:
290290
print("")
291291
# elif (got_error>0):
292292
# print dtests[2][dtest]+".out \t"+str(nb_test[1])+"\t"+str(nb_test[2])+"\t"+str(nb_test[3])
@@ -304,7 +304,7 @@ def run_summary_test( f, cmdline, short_summary):
304304
list_results[2][4]+=list_results[2][dtype]
305305
list_results[3][4]+=list_results[3][dtype]
306306

307-
if only_numbers==1:
307+
if only_numbers:
308308
print(str(list_results[1][4])+"\n"+str(list_results[2][4]+list_results[3][4]))
309309
else:
310310
print(summary)

0 commit comments

Comments
 (0)