1
|
|
|
|
2
|
|
|
""" |
3
|
|
|
.. module:: projection_shift_doc_test |
4
|
|
|
:platform: Unix |
5
|
|
|
:synopsis: unittest test for plugin restructured text file documentation |
6
|
|
|
.. moduleauthor: Jessica Verschoyle |
7
|
|
|
|
8
|
|
|
""" |
9
|
|
|
|
10
|
|
|
import os |
11
|
|
|
import sys |
12
|
|
|
import unittest |
13
|
|
|
import logging |
14
|
|
|
import logging.config |
15
|
|
|
|
16
|
|
|
from io import StringIO |
17
|
|
|
|
18
|
|
|
import doc.doc_tests.doc_test_utils as dtu |
19
|
|
|
import scripts.configurator_tests.savu_config_test_utils as sctu |
20
|
|
|
import scripts.configurator_tests.refresh_process_lists_test as refresh |
21
|
|
|
|
22
|
|
|
# Determine Savu base path |
23
|
|
|
main_dir = \ |
24
|
|
|
os.path.dirname(os.path.realpath(__file__)).split("/Savu/")[0] |
25
|
|
|
savu_base_path = f"{main_dir}/Savu/" |
26
|
|
|
|
27
|
|
|
# Reset the args for command line input |
28
|
|
|
dtu.setup_argparser() |
29
|
|
|
|
30
|
|
|
# Start logging |
31
|
|
|
logger, logger_rst = dtu.get_loggers() |
32
|
|
|
fh, ch, fh_rst = dtu.setup_log_files(logger, logger_rst, |
33
|
|
|
"/alignment/projection_shift/") |
34
|
|
|
|
35
|
|
|
class ProjectionShiftDocTest(unittest.TestCase): |
36
|
|
|
|
37
|
|
|
def refresh_process_lists(self): |
38
|
|
|
""" Run through the process list files and refresh them to update |
39
|
|
|
any inconsistent parameter values. |
40
|
|
|
If there is a value which cannot be used, that parameter will |
41
|
|
|
be set to the default value. |
42
|
|
|
""" |
43
|
|
|
process_lists = ["test_data/process_lists/vo_centering_process.nxs", |
44
|
|
|
"test_data/process_lists/vo_centering_test.nxs"] |
45
|
|
|
output_checks = ["Exception","Error","ERROR"] |
46
|
|
|
for process_list_path in process_lists: |
47
|
|
|
file_exists = os.path.exists(savu_base_path + process_list_path) |
48
|
|
|
error_msg = f"The process list at {process_list_path}" \ |
49
|
|
|
f"does not exist." |
50
|
|
|
|
51
|
|
|
self.assertTrue(file_exists, msg=error_msg) |
52
|
|
|
if file_exists: |
53
|
|
|
# Write the process list being tested to the logger |
54
|
|
|
logger.debug(f"REFRESH PROCESS LIST: " \ |
55
|
|
|
f"{savu_base_path}{process_list_path}") |
56
|
|
|
saved_stdout = sys.stdout |
57
|
|
|
try: |
58
|
|
|
out = StringIO() |
59
|
|
|
sys.stdout = out |
60
|
|
|
refresh.generate_test(savu_base_path \ |
61
|
|
|
+ process_list_path) |
62
|
|
|
output_value = out.getvalue().strip() |
63
|
|
|
for check in output_checks: |
64
|
|
|
error_msg = f"Refresh failed: {check} in the output." |
65
|
|
|
assert check not in output_value, error_msg |
66
|
|
|
finally: |
67
|
|
|
sys.stdout = saved_stdout |
68
|
|
|
|
69
|
|
|
def test_projection_shift_doc(self): |
70
|
|
|
""" Run the input commands with savu_config |
71
|
|
|
""" |
72
|
|
|
self.refresh_process_lists() |
73
|
|
|
input_list = ["add NxtomoLoader", |
74
|
|
|
"mod 1.1 []", |
75
|
|
|
"disp -a", |
76
|
|
|
"add ProjectionShift", |
77
|
|
|
"disp 1.3 -vv", |
78
|
|
|
"open /home/glb23482/git_projects/Savu/test_data/process_lists/vo_centering_process.nxs", |
79
|
|
|
"exit", "y"] |
80
|
|
|
output_checks = ["Exception","Error","ERROR"] |
81
|
|
|
sctu.savu_config_runner(input_list, output_checks, |
82
|
|
|
error_str=True) |
83
|
|
|
|
84
|
|
|
def tearDown(self): |
85
|
|
|
# End the logging session |
86
|
|
|
dtu.end_logging(logger, logger_rst, fh, ch, fh_rst) |
87
|
|
|
logging.shutdown() |
88
|
|
|
|
89
|
|
|
if __name__ == "__main__": |
90
|
|
|
unittest.main() |
91
|
|
|
|