15 from skimage.io
import imread
16 from skimage.metrics
import structural_similarity
30 "cut_plane_rotate":
"iyyyy",
31 "cut_plane_rotate_back":
"iyyyyYYYY",
32 "cut_plane_transl":
"izzzz",
33 "cut_plane_transl_back":
"izzzzZZZZ",
38 "orient2d_5":
"RRRRR",
39 "orient2d_6":
"RRRRRR",
44 screenshot_keys =
"Sq"
45 screenshot_file =
"GLVis_s01.png"
51 output_img = imread(output_file)
52 if output_img
is None:
53 print(
"[FAIL] Could not open output image.")
57 baseline_img = imread(baseline_file)
58 if baseline_img
is None:
59 print(
"[IGNORE] No baseline exists to compare against.")
64 ssim = structural_similarity(baseline_img, output_img, multichannel=
True)
65 if ssim < cutoff_ssim:
67 print(
"[PASS] Differences were detected in the control case.")
69 print(
"[FAIL] Output and baseline are different.")
72 print(
"[FAIL] Differences were not detected in the control case.")
74 print(
"[PASS] Images match.")
75 print(
" actual ssim = {}, cutoff = {}".format(ssim, cutoff_ssim))
76 return ssim >= cutoff_ssim
if not expect_fail
else ssim < cutoff_ssim
80 def test_case(exec_path, exec_args, baseline, t_group, t_name, cmd):
81 print(
"Testing {0}:{1}...".format(t_group, t_name))
82 full_screenshot_cmd = cmd + screenshot_keys
83 cmd =
"{0} {1} -k \"{2}\"".format(exec_path, exec_args, full_screenshot_cmd)
84 print(
"Exec: {}".format(cmd))
85 ret = os.system(cmd +
" > /dev/null 2>&1")
87 print(
"[FAIL] GLVis exited with error code {}.".format(ret))
89 if not os.path.exists(t_group):
91 output_name =
"{0}/{1}.png".format(t_group, t_name)
93 ret = os.system(
"mv {0} {1}".format(screenshot_file, output_name))
95 print(
"[FAIL] Could not move output image: exit code {}.".format(ret))
99 baseline_name =
"{0}/test.{1}.png".format(baseline, test_name)
102 print(
"[IGNORE] No baseline exists to compare against.")
106 if exec_args
is None:
108 test_name = os.path.basename(save_file)
109 print(
"Testing {}...".format(save_file))
113 with open(save_file)
as in_f:
114 stream_data = in_f.read()
116 output_name =
"test.{}.png".format(test_name)
117 output_name_fail =
"test.fail.{}.png".format(test_name)
118 tmp_file =
"test.saved"
119 with open(tmp_file,
'w')
as out_f:
120 out_f.write(stream_data)
121 out_f.write(
"\nwindow_size 800 600")
122 out_f.write(
"\nscreenshot {}".format(output_name))
124 out_f.write(
"\nkeys *")
125 out_f.write(
"\nscreenshot {}".format(output_name_fail))
126 out_f.write(
"\nkeys q")
129 cmd =
"{0} {1} -saved {2}".format(exec_path, exec_args, tmp_file)
130 print(
"Exec: {}".format(cmd))
133 print(
"[FAIL] GLVis exited with error code {}.".format(ret))
137 baseline_name =
"{0}/test.{1}.png".format(baseline, test_name)
141 return (test_baseline
and test_control)
143 print(
"[IGNORE] No baseline exists to compare against.")
146 def test_cmd(exec_path, exec_args, tgroup, baseline):
148 os.remove(screenshot_file)
151 all_tests_passed =
True
152 for testname, cmds
in test_cases.items():
153 result =
test_case(exec_path, exec_args, baseline, tgroup, testname, cmds)
154 all_tests_passed = all_tests_passed
and result
157 print(
"All tests passed.")
161 if __name__ ==
"__main__":
162 parser = argparse.ArgumentParser()
163 parser.add_argument(
"-s",
"--save_stream", help=
"Path to a GLVis saved stream file.")
164 parser.add_argument(
"-e",
"--exec_cmd", help=
"Path to the GLVis executable")
165 parser.add_argument(
"-a",
"--exec_args", help=
"Arguments to pass to GLVis.")
166 parser.add_argument(
"-n",
"--group_name", help=
"Name of the test group.")
167 parser.add_argument(
"-b",
"--baseline", help=
"Path to test baseline.")
168 args = parser.parse_args()
169 if args.save_stream
is not None:
170 result =
test_stream(args.exec_cmd, args.exec_args, args.save_stream, args.baseline)
174 test_cmd(args.exec_cmd, args.exec_args, args.group_name, args.baseline)