Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python scripts to Python3 #204

Merged
merged 3 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions package/scripts/precook_test.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#! /usr/bin/env python3
"""Generate pre-cooked pseudo /proc output for use with tests"""

import os
import time
import random
Expand Down Expand Up @@ -201,17 +204,9 @@ def createTestRand(dir_name, iter):
def main():
parser = argparse.ArgumentParser(description="Precooked test generator")

parser.add_argument(
"--dir",
type=str,
help="Name of the directory to be generated",
)

parser.add_argument(
"--iter",
type=int,
help="Number of iterations to be generated",
)
parser.add_argument("--dir", type=str, help="Name of the directory to be generated")

parser.add_argument("--iter", type=int, help="Number of iterations to be generated")

args = parser.parse_args()

Expand Down
2 changes: 1 addition & 1 deletion package/scripts/prmon_compress_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
import pandas as pd
except ImportError:
print("{0: <8}:: This script needs pandas.".format("ERROR"))
print("ERROR:: This script needs pandas.")
sys.exit(-1)


Expand Down
40 changes: 11 additions & 29 deletions package/scripts/prmon_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

plt.style.use("seaborn-whitegrid")
except ImportError:
print("{0: <8}:: This script needs numpy, pandas and matplotlib.".format("ERROR"))
print(
"{0: <8}:: Looks like at least one of these modules is missing.".format("ERROR")
)
print("{0: <8}:: Please install them first and then retry.".format("ERROR"))
print("ERROR:: This script needs numpy, pandas and matplotlib.")
print("ERROR:: Looks like at least one of these modules is missing.")
print("ERROR:: Please install them first and then retry.")
sys.exit(-1)

# Define the labels/units for beautification
Expand Down Expand Up @@ -197,7 +195,7 @@ def main():

# Check the input file exists
if not os.path.exists(args.input):
print("{0: <8}:: Input file {1} does not exists".format("ERROR", args.input))
print(f"ERROR:: Input file {args.input} does not exists")
sys.exit(-1)

# Load the data
Expand All @@ -206,16 +204,12 @@ def main():

# Check the variables are in data
if args.xvar not in list(data):
print(
"{0: <8}:: Variable {1} is not available in data".format("ERROR", args.xvar)
)
print(f"ERROR:: Variable {args.xvar} is not available in data")
sys.exit(-1)
ylist = args.yvar.split(",")
for carg in ylist:
if carg not in list(data):
print(
"{0: <8}:: Variable {1} is not available in data".format("ERROR", carg)
)
print("ERROR:: Variable {carg} is not available in data")
graeme-a-stewart marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(-1)

# Check the consistency of variables and units
Expand All @@ -225,35 +219,23 @@ def main():
old_xunit = args.xunit
args.xunit = ALLOWEDUNITS[first_x_variable][0].upper()
print(
"{0: <8}:: Changing xunit from {1} to {2} for consistency".format(
"WARNING", old_xunit, args.xunit
)
f"WARNING:: Changing xunit from {old_xunit} to {args.xunit} for consistency"
)
first_y_variable = args.yvar.split(",")[0]
if args.yunit.lower() not in ALLOWEDUNITS[first_y_variable]:
old_yunit = args.yunit
args.yunit = ALLOWEDUNITS[first_y_variable][0].upper()
print(
"{0: <8}:: Changing yunit from {1} to {2} for consistency".format(
"WARNING", old_yunit, args.yunit
)
f"WARNING:: Changing yunit from {old_yunit} to {args.yunit} for consistency"
)

# Check if the user is trying to plot variables with inconsistent units
# If so simply print a message to warn them
if len({ALLOWEDUNITS[i][0] for i in args.xvar.split(",")}) > 1:
print(
"{0: <8}:: Elements in xvar have inconsistent units, beware!".format(
"WARNING"
)
)
print("WARNING:: Elements in xvar have inconsistent units, beware!")

if len({ALLOWEDUNITS[i][0] for i in args.yvar.split(",")}) > 1:
print(
"{0: <8}:: Elements in yvar have inconsistent units, beware!".format(
"WARNING"
)
)
print("WARNING:: Elements in yvar have inconsistent units, beware!")

# Labels and output information
xlabel = args.xvar
Expand Down Expand Up @@ -314,7 +296,7 @@ def main():
plt.tight_layout()
fig.savefig(output)

print("{0: <8}:: Saved output into {1}".format("INFO", output))
print("INFO:: Saved output into {output}")
graeme-a-stewart marked this conversation as resolved.
Show resolved Hide resolved
sys.exit(0)


Expand Down
4 changes: 2 additions & 2 deletions package/tests/test_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def test_run_test_with_params(self):
total_proc,
expect_proc,
msg="Inconsistent value for number of processes "
"(expected {0}, got {1})".format(expect_proc, total_proc),
f"(expected {expect_proc}, got {total_proc})",
)
self.assertAlmostEqual(
total_thread,
expect_thread,
msg="Inconsistent value for number of total threads "
"(expected {0}, got {1}".format(expect_thread, total_thread),
f"(expected {expect_thread}, got {total_thread}",
)

return ConfigurableProcessMonitor
Expand Down
20 changes: 8 additions & 12 deletions package/tests/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,27 @@ def test_run_test_with_params(self):
total_cpu,
expect_cpu,
"Too high value for CPU time "
"(expected maximum of {0}, got {1})".format(expect_cpu, total_cpu),
f"(expected maximum of {expect_cpu}, got {total_cpu})",
)
self.assertGreaterEqual(
total_cpu,
expect_cpu * slack,
"Too low value for CPU time "
"(expected minimum of {0}, got {1}".format(
expect_cpu * slack, total_cpu
),
f"(expected minimum of {expect_cpu*slack}, got {total_cpu}",
)
# Wall time tests
total_wall = prmon_json["Max"]["wtime"]
self.assertLessEqual(
total_wall,
time,
"Too high value for wall time "
"(expected maximum of {0}, got {1})".format(time, total_wall),
f"(expected maximum of {time}, got {total_wall})",
)
self.assertGreaterEqual(
total_wall,
time * slack,
"Too low value for wall time "
"(expected minimum of {0}, got {1}".format(
time * slack, total_wall
),
f"(expected minimum of {time * slack}, got {total_wall}",
)

# Unit test
Expand All @@ -103,15 +99,15 @@ def test_run_test_with_params(self):
self.assertEqual(
len(missing),
0,
"Wrong number of unit values for '{0}'".format(group)
+ " - missing parameters are {0}".format(missing),
f"Wrong number of unit values for '{group}' - "
f"missing parameters are {missing}",
)
extras = unit_params - value_params
self.assertEqual(
len(extras),
0,
"Wrong number of unit values for '{0}'".format(group)
+ " - extra parameters are {0}".format(extras),
f"Wrong number of unit values for '{group}' - "
f"extra parameters are {extras}",
)

return ConfigurableProcessMonitor
Expand Down
2 changes: 1 addition & 1 deletion package/tests/test_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_run_test_with_params(self):
self.assertEqual(
prmon_rc,
exit_code,
"Wrong return code from prmon (expected {0}".format(exit_code),
f"Wrong return code from prmon (expected {exit_code}",
)

return ConfigurableProcessMonitor
Expand Down
10 changes: 4 additions & 6 deletions package/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ def test_run_test_with_params(self):
prmon_json["Max"]["wchar"],
expected_bytes,
"Too low value for IO bytes written "
"(expected minimum of {0}, got {1})".format(
expected_bytes, prmon_json["Max"]["wchar"]
),
f"(expected minimum of {expected_bytes}, "
f"got {prmon_json['Max']['wchar']})",
)
self.assertGreaterEqual(
prmon_json["Max"]["rchar"],
expected_bytes,
"Too low value for IO bytes read "
"(expected minimum of {0}, got {1})".format(
expected_bytes, prmon_json["Max"]["rchar"]
),
f"(expected minimum of {expected_bytes}, "
f"got {prmon_json['Max']['rchar']})",
)

return ConfigurableProcessMonitor
Expand Down
8 changes: 4 additions & 4 deletions package/tests/test_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def check_memory_limits(self, name, value, expected, slack):
self.assertLess(
value,
max_value,
"Too high a value for {0} "
"(expected maximum of {1}, got {2})".format(name, max_value, value),
f"Too high a value for {name} "
f"(expected maximum of {max_value}, got {value})",
)
self.assertGreater(
value,
min_value,
"Too low a value for {0} "
"(expected maximum of {1}, got {2})".format(name, min_value, value),
f"Too low a value for {name} "
f"(expected maximum of {min_value}, got {value})",
)

def test_run_test_with_params(self):
Expand Down
10 changes: 4 additions & 6 deletions package/tests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,15 @@ def test_run_test_with_params(self):
prmon_json["Max"]["rx_bytes"],
expected_bytes,
"Too low value for rx bytes "
"(expected minimum of {0}, got {1})".format(
expected_bytes, prmon_json["Max"]["rx_bytes"]
),
f"(expected minimum of {expected_bytes}, "
f"got {prmon_json['Max']['rx_bytes']})",
)
self.assertGreaterEqual(
prmon_json["Max"]["tx_bytes"],
expected_bytes,
"Too low value for tx bytes "
"(expected minimum of {0}, got {1})".format(
expected_bytes, prmon_json["Max"]["tx_bytes"]
),
f"(expected minimum of {expected_bytes}, "
f"got {prmon_json['Max']['tx_bytes']})",
)

return ConfigurableProcessMonitor
Expand Down