From 00f8b7055b02cdc5ca915e97af393f15fbdff6e7 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@gmail.com>
Date: Thu, 1 Aug 2019 15:29:27 +0100
Subject: [PATCH] Define utility function to check GSL version

Refs #26262
---
 .../lib/systemtests/systemtesting.py          |  9 +++
 .../tests/analysis/EnginXScriptTest.py        | 57 ++++++++++---------
 .../tests/analysis/ISISIndirectInelastic.py   | 16 ++----
 .../tests/analysis/ISIS_PowderGemTest.py      | 12 +---
 4 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/Testing/SystemTests/lib/systemtests/systemtesting.py b/Testing/SystemTests/lib/systemtests/systemtesting.py
index e085b79b7fc..d9315816f96 100644
--- a/Testing/SystemTests/lib/systemtests/systemtesting.py
+++ b/Testing/SystemTests/lib/systemtests/systemtesting.py
@@ -1171,6 +1171,15 @@ def envAsString():
     return env
 
 
+#########################################################################
+# Check if we are on an OS that has GSL v1
+#########################################################################
+def using_gsl_v1():
+    """ Check whether the current build is running GSL v1"""
+    from mantid.buildconfig import GSL_VERSION
+    return GSL_VERSION.startswith('1')
+
+
 #########################################################################
 # Function to keep a pool of threads active in a loop to run the tests.
 # Each thread starts a loop and gathers a first test module from the
diff --git a/Testing/SystemTests/tests/analysis/EnginXScriptTest.py b/Testing/SystemTests/tests/analysis/EnginXScriptTest.py
index af6e46d60d8..738d71b8ff3 100644
--- a/Testing/SystemTests/tests/analysis/EnginXScriptTest.py
+++ b/Testing/SystemTests/tests/analysis/EnginXScriptTest.py
@@ -7,7 +7,6 @@
 
 from __future__ import (absolute_import, division, print_function)
 import os
-import platform
 import shutil
 import systemtesting
 
@@ -27,7 +26,7 @@ focus_directory = os.path.join(root_directory, "focus")
 class CreateVanadiumTest(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(cal_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run=None, force_vanadium=True, directory=cal_directory)
 
     def validate(self):
@@ -41,7 +40,7 @@ class CreateVanadiumTest(systemtesting.MantidSystemTest):
 class CreateCalibrationWholeTest(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(cal_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run=None, do_cal=True, directory=cal_directory)
 
     def validate(self):
@@ -50,18 +49,19 @@ class CreateCalibrationWholeTest(systemtesting.MantidSystemTest):
 
         # this is neccesary due to appendspectra creating spectrum numbers of 0
         self.disableChecking.append('SpectraMap')
-        if _current_os_has_gsl_lvl2():
+        if systemtesting.using_gsl_v1():
+            return ("engg_calibration_bank_1", "engggui_calibration_bank_1_gsl1.nxs",
+                    "engg_calibration_bank_2", "engggui_calibration_bank_2_gsl1.nxs",
+                    "engg_calibration_banks_parameters", "engggui_calibration_banks_parameters_gsl1.nxs",
+                    "Engg difc Zero Peaks Bank 1", "engggui_difc_zero_peaks_bank_1.nxs",
+                    "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs")
+        else:
             return ("engg_calibration_bank_1", "engggui_calibration_bank_1.nxs",
                     "engg_calibration_bank_2", "engggui_calibration_bank_2.nxs",
                     "engg_calibration_banks_parameters", "engggui_calibration_banks_parameters.nxs",
                     "Engg difc Zero Peaks Bank 1", "engggui_difc_zero_peaks_bank_1.nxs",
                     "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs"
                     )
-        return ("engg_calibration_bank_1", "engggui_calibration_bank_1_gsl1.nxs",
-                "engg_calibration_bank_2", "engggui_calibration_bank_2_gsl1.nxs",
-                "engg_calibration_banks_parameters", "engggui_calibration_banks_parameters_gsl1.nxs",
-                "Engg difc Zero Peaks Bank 1", "engggui_difc_zero_peaks_bank_1.nxs",
-                "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs")
 
     def cleanup(self):
         simple.mtd.clear()
@@ -71,7 +71,7 @@ class CreateCalibrationWholeTest(systemtesting.MantidSystemTest):
 class CreateCalibrationCroppedTest(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(cal_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run=None, do_cal=True, directory=cal_directory,
              crop_type="spectra", crop_on="1-20")
 
@@ -81,13 +81,14 @@ class CreateCalibrationCroppedTest(systemtesting.MantidSystemTest):
 
         # this is neccesary due to appendspectra creating spectrum numbers of 0
         self.disableChecking.append('SpectraMap')
-        if _current_os_has_gsl_lvl2():
+        if systemtesting.using_gsl_v1():
+            return ("cropped", "engggui_calibration_bank_cropped.nxs_gsl1.nxs",
+                    "engg_calibration_banks_parameters", "engggui_calibration_cropped_parameters_gsl1.nxs",
+                    "Engg difc Zero Peaks Bank cropped", "engggui_difc_zero_peaks_bank_cropped.nxs")
+        else:
             return ("cropped", "engggui_calibration_bank_cropped.nxs",
                     "engg_calibration_banks_parameters", "engggui_calibration_bank_cropped_parameters.nxs",
                     "Engg difc Zero Peaks Bank cropped", "engggui_difc_zero_peaks_bank_cropped.nxs")
-        return ("cropped", "engggui_calibration_bank_cropped.nxs_gsl1.nxs",
-                "engg_calibration_banks_parameters", "engggui_calibration_cropped_parameters_gsl1.nxs",
-                "Engg difc Zero Peaks Bank cropped", "engggui_difc_zero_peaks_bank_cropped.nxs")
 
     def cleanup(self):
         simple.mtd.clear()
@@ -97,7 +98,7 @@ class CreateCalibrationCroppedTest(systemtesting.MantidSystemTest):
 class CreateCalibrationBankTest(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(cal_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run=None, do_cal=True, directory=cal_directory,
              crop_type="banks", crop_on="South")
 
@@ -107,13 +108,14 @@ class CreateCalibrationBankTest(systemtesting.MantidSystemTest):
 
         # this is neccesary due to appendspectra creating spectrum numbers of 0
         self.disableChecking.append('SpectraMap')
-        if _current_os_has_gsl_lvl2():
+        if systemtesting.using_gsl_v1():
+            return ("engg_calibration_bank_2", "engggui_calibration_bank_2_gsl1.nxs",
+                    "engg_calibration_banks_parameters", "engggui_calibration_bank_south_parameters_gsl1.nxs",
+                    "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs")
+        else:
             return ("engg_calibration_bank_2", "engggui_calibration_bank_2.nxs",
                     "engg_calibration_banks_parameters", "engggui_calibration_bank_south_parameters.nxs",
                     "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs")
-        return ("engg_calibration_bank_2", "engggui_calibration_bank_2_gsl1.nxs",
-                "engg_calibration_banks_parameters", "engggui_calibration_bank_south_parameters_gsl1.nxs",
-                "Engg difc Zero Peaks Bank 2", "engggui_difc_zero_peaks_bank_2.nxs")
 
     def cleanup(self):
         simple.mtd.clear()
@@ -123,7 +125,7 @@ class CreateCalibrationBankTest(systemtesting.MantidSystemTest):
 class FocusBothBanks(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(focus_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run="299080", do_cal=True, directory=focus_directory)
 
     def validate(self):
@@ -138,7 +140,7 @@ class FocusBothBanks(systemtesting.MantidSystemTest):
 class FocusCropped(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(focus_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run="299080", directory=focus_directory,
              crop_type="spectra", crop_on="1-20")
 
@@ -153,7 +155,7 @@ class FocusCropped(systemtesting.MantidSystemTest):
 class FocusTextureMode(systemtesting.MantidSystemTest):
 
     def runTest(self):
-        os.makedirs(focus_directory)
+        _make_test_directories()
         main(vanadium_run="236516", user="test", focus_run=None, do_cal=True, directory=focus_directory)
         simple.mtd.clear()
         csv_file = os.path.join(root_directory, "EnginX.csv")
@@ -180,6 +182,12 @@ class FocusTextureMode(systemtesting.MantidSystemTest):
         _try_delete(focus_directory)
 
 
+def _make_test_directories():
+    """Attempts to make the input directory for the tests"""
+    if not os.path.exists(cal_directory):
+        os.makedirs(cal_directory)
+
+
 def _try_delete(path):
     try:
         # Use this instead of os.remove as we could be passed a non-empty dir
@@ -189,8 +197,3 @@ def _try_delete(path):
             os.remove(path)
     except OSError:
         print("Could not delete output file at: ", path)
-
-
-def _current_os_has_gsl_lvl2():
-    """ Check whether the current OS should be running GSLv2 """
-    return platform.linux_distribution()[0].lower() == "ubuntu" or platform.mac_ver()[0] != ''
diff --git a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py
index d97aa451197..6c0b0930413 100644
--- a/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py
+++ b/Testing/SystemTests/tests/analysis/ISISIndirectInelastic.py
@@ -74,23 +74,18 @@ systemtesting.MantidSystemTest
 '''
 
 from __future__ import (absolute_import, division, print_function)
-import systemtesting
 from abc import ABCMeta, abstractmethod
 
 from mantid.simpleapi import *
 
 # For debugging only.
 from mantid.api import FileFinder
-import platform
-from six import with_metaclass
-
+from systemtesting import MantidSystemTest, using_gsl_v1
 
-def current_OS_has_GSLv2():
-    """ Check whether the current OS should be running GSLv2 """
-    return platform.linux_distribution()[0].lower() == "ubuntu" or platform.mac_ver()[0] != ''
+from six import with_metaclass
 
 
-class ISISIndirectInelasticBase(with_metaclass(ABCMeta, systemtesting.MantidSystemTest)):
+class ISISIndirectInelasticBase(with_metaclass(ABCMeta, MantidSystemTest)):
     '''
     A common base class for the ISISIndirectInelastic* base classes.
     '''
@@ -1118,7 +1113,8 @@ class OSIRISConvFit(ISISIndirectInelasticConvFit):
     def get_reference_files(self):
         self.tolerance = 0.3
         # gsl v2 gives a slightly different result than v1
-        return ['II.OSIRISConvFitSeq_gslv2.nxs'] if current_OS_has_GSLv2() else ['II.OSIRISConvFitSeq.nxs']
+        return ['II.OSIRISConvFitSeq.nxs'] if using_gsl_v1() \
+            else ['II.OSIRISConvFitSeq_gslv2.nxs']
 
 #------------------------- IRIS tests -----------------------------------------
 
@@ -1146,7 +1142,7 @@ class IRISConvFit(ISISIndirectInelasticConvFit):
     def get_reference_files(self):
         self.tolerance = 0.2
         # gsl v2 gives a slightly different result than v1
-        return ['II.IRISConvFitSeq_gslv2.nxs'] if current_OS_has_GSLv2() else ['II.IRISConvFitSeq.nxs']
+        return ['II.IRISConvFitSeq.nxs'] if using_gsl_v1() else ['II.IRISConvFitSeq_gslv2.nxs']
 
 #==============================================================================
 # Transmission Monitor Test
diff --git a/Testing/SystemTests/tests/analysis/ISIS_PowderGemTest.py b/Testing/SystemTests/tests/analysis/ISIS_PowderGemTest.py
index 36fd1490d92..d00a395414f 100644
--- a/Testing/SystemTests/tests/analysis/ISIS_PowderGemTest.py
+++ b/Testing/SystemTests/tests/analysis/ISIS_PowderGemTest.py
@@ -9,7 +9,6 @@ from __future__ import (absolute_import, division, print_function)
 import os
 import systemtesting
 import shutil
-import platform
 
 import mantid.simpleapi as mantid
 from mantid import config
@@ -124,10 +123,10 @@ class CreateCalTest(systemtesting.MantidSystemTest):
 
     def validate(self):
         self.tolerance = 1e-5
-        if _current_os_has_gsl_lvl2():
-            return self.focus_results.name(), "ISIS_Powder-GEM87618_grouped.nxs"
-        else:
+        if systemtesting.using_gsl_v1():
             return self.focus_results.name(), "ISIS_Powder-GEM87618_groupedGSAS1.nxs"
+        else:
+            return self.focus_results.name(), "ISIS_Powder-GEM87618_grouped.nxs"
 
     def cleanup(self):
         try:
@@ -215,8 +214,3 @@ def _try_delete(path):
             os.remove(path)
     except OSError:
         print("Could not delete output file at: ", path)
-
-
-def _current_os_has_gsl_lvl2():
-    """ Check whether the current OS should be running GSLv2 """
-    return platform.linux_distribution()[0].lower() == "ubuntu" or platform.mac_ver()[0] != ''
-- 
GitLab