diff --git a/scripts/Diffraction/isis_powder/routines/common.py b/scripts/Diffraction/isis_powder/routines/common.py index 32032fc99b9767ea620ed5f99c112bf0bc608f0e..ee486f728515543fb8284dead4bc8cb52e7e42c7 100644 --- a/scripts/Diffraction/isis_powder/routines/common.py +++ b/scripts/Diffraction/isis_powder/routines/common.py @@ -422,4 +422,4 @@ def _run_number_generator(processed_string): number_generator = kernel.IntArrayProperty('array_generator', processed_string) return number_generator.value.tolist() except RuntimeError: - raise RuntimeError("Could not generate run numbers from this input: " + processed_string) + raise ValueError("Could not generate run numbers from this input: " + processed_string) diff --git a/scripts/test/ISISPowderCommonTest.py b/scripts/test/ISISPowderCommonTest.py index 532bfff2fee30504795e2bd15987bacc6a78f2a1..72da860bc2d50d334c1576d5c7786b382d44e632 100644 --- a/scripts/test/ISISPowderCommonTest.py +++ b/scripts/test/ISISPowderCommonTest.py @@ -138,5 +138,47 @@ class ISISPowderCommonTest(unittest.TestCase): expected_name = input_name + '-' + str(i + 1) self.assertEqual(expected_name, ws.getName()) + def test_generate_run_numbers(self): + # Mantid handles most of this for us + + # First check it can handle int types + test_int_input = 123 + int_input_return = common.generate_run_numbers(run_number_string=test_int_input) + # Expect the returned type is a list + self.assertEqual(int_input_return, [test_int_input]) + + # Check it can handle 10-12 and is inclusive + input_string = "10-12" + expected_values = [10, 11, 12] + returned_values = common.generate_run_numbers(run_number_string=input_string) + self.assertEqual(expected_values, returned_values) + + # Check that the underscore syntax used by older pearl_routines scripts is handled + input_string = "10_12" + returned_values = common.generate_run_numbers(run_number_string=input_string) + self.assertEqual(expected_values, returned_values) + + # Check that the comma notation is working + input_string = "20, 22, 24" + expected_values = [20, 22, 24] + returned_values = common.generate_run_numbers(run_number_string=input_string) + self.assertEqual(expected_values, returned_values) + + # Check we can use a combination of both + input_string = "30-33, 36, 38-39" + expected_values = [30, 31, 32, 33, 36, 38, 39] + returned_values = common.generate_run_numbers(run_number_string=input_string) + self.assertEqual(expected_values, returned_values) + + def test_generate_run_numbers_fails(self): + + run_input_sting = "text-string" + with self.assertRaisesRegexp(ValueError, "Could not generate run numbers from this input"): + common.generate_run_numbers(run_number_string=run_input_sting) + + # Check it says what the actual string was + with self.assertRaisesRegexp(ValueError, run_input_sting): + common.generate_run_numbers(run_number_string=run_input_sting) + if __name__ == "__main__": unittest.main()