Skip to content
Snippets Groups Projects
Commit 99cf2ed7 authored by Sam Jenkins's avatar Sam Jenkins
Browse files

Re #22638 updated unit tests

Updated unit tests to reflect changes to `run_details.py` and fixed minor error
that tests caught after updating.
parent 251e790c
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ def create_run_details_object(run_number_string, inst_settings, is_vanadium_run, ...@@ -31,7 +31,7 @@ def create_run_details_object(run_number_string, inst_settings, is_vanadium_run,
offset_file_name = common.cal_map_dictionary_key_helper(dictionary=cal_map_dict, key="offset_file_name") offset_file_name = common.cal_map_dictionary_key_helper(dictionary=cal_map_dict, key="offset_file_name")
# Prepend the properties used for creating a van spline so we can fingerprint the file # Prepend the properties used for creating a van spline so we can fingerprint the file
new_splined_list = [splined_name_list] if splined_name_list else [] new_splined_list = splined_name_list if splined_name_list else []
new_splined_list.append(os.path.basename(offset_file_name)) new_splined_list.append(os.path.basename(offset_file_name))
splined_van_name = common.generate_splined_name(vanadium_string, new_splined_list) splined_van_name = common.generate_splined_name(vanadium_string, new_splined_list)
......
...@@ -9,6 +9,7 @@ import unittest ...@@ -9,6 +9,7 @@ import unittest
import warnings import warnings
from isis_powder.routines import run_details from isis_powder.routines import run_details
from isis_powder.routines import common, yaml_parser
class ISISPowderInstrumentRunDetailsTest(unittest.TestCase): class ISISPowderInstrumentRunDetailsTest(unittest.TestCase):
...@@ -39,9 +40,17 @@ class ISISPowderInstrumentRunDetailsTest(unittest.TestCase): ...@@ -39,9 +40,17 @@ class ISISPowderInstrumentRunDetailsTest(unittest.TestCase):
expected_offset_file_name = "offset_file_name" expected_offset_file_name = "offset_file_name"
run_number_string = "17-18" run_number_string = "17-18"
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml") mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml")
run_number2 = common.get_first_run_number(run_number_string=run_number_string)
cal_mapping_dict = yaml_parser.get_run_dictionary(run_number_string=run_number2,
file_path=mock_inst.cal_mapping_path)
grouping_filename = mock_inst.grouping_file_name
empty_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="empty_run_numbers")
vanadium_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="vanadium_run_numbers")
output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst, output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst,
is_vanadium_run=False) is_vanadium_run=False, grouping_file_name=grouping_filename,
empty_run_number=empty_runs, vanadium_string=vanadium_runs)
self.assertEqual(output_obj.empty_runs, expected_empty_runs) self.assertEqual(output_obj.empty_runs, expected_empty_runs)
self.assertEqual(output_obj.grouping_file_path, self.assertEqual(output_obj.grouping_file_path,
...@@ -62,72 +71,104 @@ class ISISPowderInstrumentRunDetailsTest(unittest.TestCase): ...@@ -62,72 +71,104 @@ class ISISPowderInstrumentRunDetailsTest(unittest.TestCase):
run_number_string = "17-18" run_number_string = "17-18"
expected_vanadium_runs = "11-12" expected_vanadium_runs = "11-12"
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml") mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml")
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml")
run_number2 = common.get_first_run_number(run_number_string=run_number_string)
cal_mapping_dict = yaml_parser.get_run_dictionary(run_number_string=run_number2,
file_path=mock_inst.cal_mapping_path)
grouping_filename = mock_inst.grouping_file_name
empty_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="empty_run_numbers")
vanadium_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="vanadium_run_numbers")
output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst, output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst,
is_vanadium_run=True) is_vanadium_run=True, grouping_file_name=grouping_filename,
empty_run_number=empty_runs, vanadium_string=vanadium_runs)
self.assertEqual(expected_vanadium_runs, output_obj.run_number) self.assertEqual(expected_vanadium_runs, output_obj.run_number)
self.assertEqual(output_obj.vanadium_run_numbers, output_obj.run_number) self.assertEqual(output_obj.vanadium_run_numbers, output_obj.run_number)
self.assertEqual(expected_vanadium_runs, output_obj.output_run_string) self.assertEqual(expected_vanadium_runs, output_obj.output_run_string)
def test_callable_params_are_used(self): # Callable params no longer in function
# These attributes are based on a custom YAML file at the specified path # def test_callable_params_are_used(self):
expected_label = "16_4" # # These attributes are based on a custom YAML file at the specified path
expected_vanadium_runs = "11-12" # expected_label = "16_4"
expected_empty_runs = "13-14" # expected_vanadium_runs = "11-12"
expected_grouping_file_name = "grouping_file" # expected_empty_runs = "13-14"
run_number_string = "17-18" # expected_grouping_file_name = "grouping_file"
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTestCallable.yaml") # run_number_string = "17-18"
# mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTestCallable.yaml")
# Get the YAML file as a dict first #
wrapped_funcs = run_details.RunDetailsWrappedCommonFuncs # # Get the YAML file as a dict first
# wrapped_funcs = run_details.RunDetailsWrappedCommonFuncs
yaml_callable = run_details.CustomFuncForRunDetails(user_function=wrapped_funcs.get_cal_mapping_dict, #
run_number_string=run_number_string, # yaml_callable = run_details.CustomFuncForRunDetails(user_function=wrapped_funcs.get_cal_mapping_dict,
inst_settings=mock_inst) # run_number_string=run_number_string,
# inst_settings=mock_inst)
empty_callable = yaml_callable.add_to_func_chain(user_function=wrapped_funcs.cal_dictionary_key_helper, #
key="custom_empty_run_numbers") # empty_callable = yaml_callable.add_to_func_chain(user_function=wrapped_funcs.cal_dictionary_key_helper,
vanadium_callable = yaml_callable.add_to_func_chain(user_function=wrapped_funcs.cal_dictionary_key_helper, # key="custom_empty_run_numbers")
key="custom_vanadium_run_numbers") # vanadium_callable = yaml_callable.add_to_func_chain(user_function=wrapped_funcs.cal_dictionary_key_helper,
grouping_callable = run_details.CustomFuncForRunDetails(user_function=lambda: expected_grouping_file_name) # key="custom_vanadium_run_numbers")
output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst, # grouping_callable = run_details.CustomFuncForRunDetails(user_function=lambda: expected_grouping_file_name)
is_vanadium_run=True, empty_run_call=empty_callable, # output_obj = run_details.create_run_details_object(run_number_string=run_number_string, inst_settings=mock_inst,
vanadium_run_call=vanadium_callable, # is_vanadium_run=True, empty_run_call=empty_callable,
grouping_file_name_call=grouping_callable) # vanadium_run_call=vanadium_callable,
# grouping_file_name_call=grouping_callable)
self.assertEqual(output_obj.label, expected_label) #
self.assertEqual(output_obj.empty_runs, expected_empty_runs) # self.assertEqual(output_obj.label, expected_label)
self.assertEqual(output_obj.grouping_file_path, # self.assertEqual(output_obj.empty_runs, expected_empty_runs)
os.path.join(mock_inst.calibration_dir, expected_grouping_file_name)) # self.assertEqual(output_obj.grouping_file_path,
self.assertEqual(output_obj.vanadium_run_numbers, expected_vanadium_runs) # os.path.join(mock_inst.calibration_dir, expected_grouping_file_name))
self.assertEqual(output_obj.run_number, expected_vanadium_runs) # self.assertEqual(output_obj.vanadium_run_numbers, expected_vanadium_runs)
# self.assertEqual(output_obj.run_number, expected_vanadium_runs)
def test_run_details_splined_name_list_is_used(self): def test_run_details_splined_name_list_is_used(self):
expected_vanadium_runs = "11-12" expected_vanadium_runs = "11-12"
expected_offset_file_name = "offset_file_name" expected_offset_file_name = "offset_file_name"
splined_name_list = ["bar", "bang", "baz"] splined_name_list = ["bar", "bang", "baz"]
run_number_string = "10"
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml")
mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml") mock_inst = self.setup_mock_inst_settings(yaml_file_path="ISISPowderRunDetailsTest.yaml")
output_obj = run_details.create_run_details_object(run_number_string=10, inst_settings=mock_inst, run_number2 = common.get_first_run_number(run_number_string=run_number_string)
is_vanadium_run=False, splined_name_list=splined_name_list) cal_mapping_dict = yaml_parser.get_run_dictionary(run_number_string=run_number2,
file_path=mock_inst.cal_mapping_path)
grouping_filename = mock_inst.grouping_file_name
empty_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="empty_run_numbers")
vanadium_runs = common.cal_map_dictionary_key_helper(dictionary=cal_mapping_dict, key="vanadium_run_numbers")
output_obj = run_details.create_run_details_object(run_number_string, inst_settings=mock_inst,
is_vanadium_run=False, splined_name_list=splined_name_list,
grouping_file_name=grouping_filename,
empty_run_number=empty_runs, vanadium_string=vanadium_runs)
expected_splined_out_str = ''.join('_' + val for val in splined_name_list) expected_splined_out_str = ''.join('_' + val for val in splined_name_list)
expected_output_name = "VanSplined_" + expected_vanadium_runs + expected_splined_out_str expected_output_name = "VanSplined_" + expected_vanadium_runs + expected_splined_out_str
expected_output_name += '_' + expected_offset_file_name + ".nxs" expected_output_name += ".nxs"
expected_path = os.path.join(mock_inst.calibration_dir, output_obj.label, expected_output_name) expected_path = os.path.join(mock_inst.calibration_dir, output_obj.label, expected_output_name)
self.assertEqual(expected_path, output_obj.splined_vanadium_file_path) self.assertEqual(expected_path, output_obj.splined_vanadium_file_path)
class MockInstSettings(object): class MockInstSettings(object):
def __init__(self, cal_file_path, calibration_dir): def __init__(self, cal_file_path, calibration_dir):
self.calibration_dir = calibration_dir self.calibration_dir = calibration_dir
self.cal_mapping_path = cal_file_path self.cal_mapping_path = cal_file_path
self.grouping_file_name = MockInstSettings.gen_random_string() self.grouping_file_name = MockInstSettings.gen_random_string()
self.file_extension = MockInstSettings.gen_random_string() self.file_extension = MockInstSettings.gen_random_string()
self.mode = "PDF"
@staticmethod @staticmethod
def gen_random_string(): def gen_random_string():
return ''.join(random.choice(string.ascii_lowercase) for _ in range(10)) return ''.join(random.choice(string.ascii_lowercase) for _ in range(10))
def _get_current_mode_dictionary(run_number_string, inst_settings):
mapping_dict = run_details.get_cal_mapping_dict(run_number_string, inst_settings.cal_mapping_path)
# Get the current mode "Rietveld" or "PDF" run numbers
return common.cal_map_dictionary_key_helper(mapping_dict, inst_settings.mode)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment