From 26c1a8dff2adab55d5a485d60bfa1aabd6f61c68 Mon Sep 17 00:00:00 2001 From: David Fairbrother <DavidFair@users.noreply.github.com> Date: Tue, 14 Mar 2017 15:06:30 +0000 Subject: [PATCH] Re #19113 Added test for generate_run_numbers --- .../isis_powder/routines/common.py | 2 +- scripts/test/ISISPowderCommonTest.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/Diffraction/isis_powder/routines/common.py b/scripts/Diffraction/isis_powder/routines/common.py index 32032fc99b9..ee486f72851 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 532bfff2fee..72da860bc2d 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() -- GitLab