Skip to content
Snippets Groups Projects
Commit 332f971d authored by David Fairbrother's avatar David Fairbrother
Browse files

Re #18108 Remove old unit tests and update sys test

parent 4dc64a76
No related branches found
No related tags found
No related merge requests found
...@@ -65,7 +65,7 @@ def _get_input_dir(): ...@@ -65,7 +65,7 @@ def _get_input_dir():
def _get_output_dir(): def _get_output_dir():
return os.path.join(DIRS[0], "PEARL", "SystemTestOutput") return os.path.join(DIRS[0], "PEARL", "SystemTest_Output")
def _run_vanadium_calibration(): def _run_vanadium_calibration():
......
...@@ -72,7 +72,7 @@ def _run_vanadium_calibration(): ...@@ -72,7 +72,7 @@ def _run_vanadium_calibration():
def _run_focus(): def _run_focus():
run_number = 95599 run_number = 95599
polaris_obj = setup_polaris_instrument() polaris_obj = setup_polaris_instrument()
return polaris_obj.focus(run_number=run_number, input_mode="Individual") return polaris_obj.focus(run_number=run_number, input_mode="Individual", do_van_normalisation=True)
def _calibration_validation(cls, results): def _calibration_validation(cls, results):
......
3bca903e6dc91cd658c01efc75e5881a 35cbcc39432281c90c97e36bd6be7e1f
from isis_powder.abstract_inst import AbstractInst from isis_powder.abstract_inst import AbstractInst
from isis_powder.routines import RunDetails
class MockInstrument(AbstractInst): class MockInstrument(AbstractInst):
def __init__(self, user_name, calibration_dir, output_dir, default_ext=""): def __init__(self, user_name, calibration_dir, output_dir):
super(MockInstrument, self).__init__(user_name=user_name, calibration_dir=calibration_dir, super(MockInstrument, self).__init__(user_name=user_name, calibration_dir=calibration_dir,
output_dir=output_dir, default_input_ext=default_ext) output_dir=output_dir)
self.generate_cycle_dir_flag = False self.generate_cycle_dir_flag = False
def _get_lambda_range(self): def generate_output_file_name(self, run_number_string):
return None return "test_output_string"
def _get_focus_tof_binning(self):
return None
def get_create_van_tof_binning(self): def generate_vanadium_absorb_corrections(self, calibration_full_paths, ws_to_match):
return None return None
def get_default_group_names(self): def spline_vanadium_ws(self, focused_vanadium_banks):
return None return None
def get_run_details(self, run_number_string): def get_run_details(self, run_number_string):
# This is here to help remind people of the dict that is expected return RunDetails.RunDetails(run_number=run_number_string)
calibration_details = {"calibration": "cal",
"grouping": "group",
"vanadium_absorption": "van_absorb",
"vanadium": "van"}
return calibration_details
@staticmethod
def generate_input_file_name(run_number):
return "generate_inst_file_name" + str(run_number)
@staticmethod
def get_num_of_banks(instrument=''):
return None
@staticmethod
def _get_label_information(run_number):
# This is here to help remind people of the dict format
cycle_information = {"cycle" : "123",
"instrument_version": "test_v1"}
return cycle_information
def test_set_raw_data_dir(self, new_dir):
# Used for testing to set a new raw_data_dir
self._raw_data_dir = new_dir
...@@ -6,7 +6,6 @@ import mantid.simpleapi as mantid ...@@ -6,7 +6,6 @@ import mantid.simpleapi as mantid
import isis_powder.routines.common as common import isis_powder.routines.common as common
from isis_powder.routines import yaml_parser from isis_powder.routines import yaml_parser
from isis_powder.routines.RunDetails import RunDetails from isis_powder.routines.RunDetails import RunDetails
from isis_powder.pearl_routines import pearl_advanced_config
def attenuate_workspace(attenuation_file_path, ws_to_correct): def attenuate_workspace(attenuation_file_path, ws_to_correct):
......
import unittest
import mantid as mantid # For next import to work
from isis_powder.mock_instrument import MockInstrument
import os
class isis_powder_AbstractInstTest(unittest.TestCase):
def test_init_sets_params(self):
inst = self._get_abstract_inst_all_specified()
# Default Params
self.assertEquals(inst.calibration_dir, self.calibration_dir)
self.assertEquals(inst.output_dir, self.output_dir)
# Optional Params
self.assertEquals(inst.default_input_ext, self.default_ext)
def test_generate_full_input_path(self):
inst = self._get_abstract_inst_all_specified()
run_number = 12345
inst_file_name = inst.generate_input_file_name(run_number)
input_path = "test"
reference_output = os.path.join(input_path, (inst_file_name + self.default_ext))
output = inst._generate_input_full_path(run_number, input_path)
self.assertEquals(output, reference_output)
# Test empty hooks work correctly
def test_attenuate_workspace_hook(self):
inst = self._get_abstract_inst_defaults()
input_ws = "ws_in"
output_ws = inst.attenuate_workspace(input_ws)
self.assertEquals(input_ws, output_ws)
def test_create_calibration_si(self):
inst = self._get_abstract_inst_defaults()
self.assertRaises(NotImplementedError, lambda: inst._create_calibration_silicon("", "", ""))
def test_create_calibration(self):
inst = self._get_abstract_inst_defaults()
self.assertRaises(NotImplementedError, lambda: inst.create_calibration("", "", ""))
def test_get_monitor_spectra_hook(self):
inst = self._get_abstract_inst_defaults()
unused_param = None
output = inst.get_monitor_spectra_index(unused_param)
# Should return empty string
self.assertEquals(output, str(""))
def test_spline_background_hook(self):
inst = self._get_abstract_inst_defaults()
# Use type this isn't None to make sure its not returning to us
unused_param = "unused"
output = inst.spline_vanadium_ws(unused_param, unused_param, unused_param)
self.assertEquals(isinstance(output, type(None)), True)
# Helper methods to create fresh instrument objects
def _get_abstract_inst_defaults(self):
return MockInstrument(user_name=self.user_name, calibration_dir=self.calibration_dir,
output_dir=self.output_dir)
def _get_abstract_inst_all_specified(self):
return MockInstrument(user_name=self.user_name, calibration_dir=self.calibration_dir,
output_dir=self.output_dir, default_ext=self.default_ext)
# Test params
user_name = "unit_test_abstract_inst"
calibration_dir = "calDir"
output_dir = "outDir"
# Optional Params
default_ext = ".ext"
if __name__ == '__main__':
unittest.main()
from __future__ import (absolute_import, division, print_function)
import os
import unittest
import mantid as mantid
from isis_powder import pearl
class isis_powder_PearlTest(unittest.TestCase):
# Static method tests
def test_cycle_information_generates_correctly(self):
# This checks that the cycle information generates using the correct keys for the dict
output = self._get_pearl_inst_defaults()._get_label_information(85500)
expected_cycle = "14_1"
expected_inst_vers = "new2"
self.assertEquals(output["cycle"], expected_cycle)
self.assertEquals(output["instrument_version"], expected_inst_vers)
def test_get_instrument_ranges(self):
# This test checks that the instrument ranges calculate correctly for given instruments
# First the "new" instrument value
new_alg_range, new_save_range = pearl._get_instrument_ranges("new")
self.assertEquals(new_alg_range, 12, "'new' instrument algorithm range got " + str(new_alg_range))
self.assertEquals(new_save_range, 3, "'new' instrument save range got " + str(new_save_range))
new2_alg_range, new2_save_range = pearl._get_instrument_ranges("new2")
self.assertEquals(new2_alg_range, 14, "'new2' instrument algorithm range got " + str(new2_alg_range))
self.assertEquals(new2_save_range, 5, "'new2' instrument save range got " + str(new2_save_range))
def test_generate_inst_file_name(self):
# Tests that the generated names conform to the format expected
old_name_input = 71008 # This is the last run to use the old format
new_name_input = 71009 # Everything after this run should use new format
expected_old_name = "PRL" + str(old_name_input)
expected_new_name = "PEARL" + "000" + str(new_name_input) # New names should have 8 numerical digits
old_output = pearl._gen_file_name(old_name_input)
self.assertEquals(expected_old_name, old_output)
new_output = pearl._gen_file_name(new_name_input)
self.assertEquals(expected_new_name, new_output)
# Non static methods
def _get_pearl_inst_defaults(self):
return pearl.Pearl(user_name="unitTest-PEARL", calibration_dir=self.calibration_dir,
raw_data_dir=self.raw_data_dir, output_dir=self.output_dir)
def _get_pearl_inst_all_specified(self):
return pearl.Pearl(calibration_dir=self.calibration_dir, raw_data_dir=self.raw_data_dir,
output_dir=self.output_dir, input_file_ext=self.default_ext, tt_mode=self.tt_mode)
# Test params
calibration_dir = "calDir"
raw_data_dir = "rawDir"
output_dir = "outDir"
default_tt_mode = "TT88"
# Optional Params
default_ext = ".ext"
tt_mode = "tt_test"
if __name__ == '__main__':
DIRS = mantid.config['datasearch.directories'].split(';')
CalibDir = os.path.join(DIRS[0] + '/PEARL/Calibration_Test/Calibration/')
unittest.main()
\ No newline at end of file
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