From 30804e5ff36e53393c7b68c4f3ff8737b49e363b Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 21 Aug 2026 12:56:20 +0100 Subject: [PATCH 1/4] Add gui tests --- tests/gui_tests.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/gui_tests.py diff --git a/tests/gui_tests.py b/tests/gui_tests.py new file mode 100644 index 0000000..cc7154c --- /dev/null +++ b/tests/gui_tests.py @@ -0,0 +1,64 @@ + +import binascii +import json +import sys +import zlib + +sys.path.append(".") +sys.path.append("..") +sys.path.append("../..") + +import unittest + +from tests.settings import Settings +from util.channel_access import ChannelAccessUtils +from util.common import skip_on_instruments + + +class GuiTests(unittest.TestCase): + """ + Tests in this class relate to the contents or existence of the globals.txt configuration file. + """ + + def setUp(self): + self.ca = ChannelAccessUtils(Settings.pv_prefix) + + @skip_on_instruments(["HRPD", "EMMA-A", "EMMA-B"], "These instruments use a streaming DAE") + @skip_on_instruments( + [ + "CRYOLAB_R80", + "DCLAB", + "DETMON", + "HYDROGEN1", + "HYDROGEN2", + "IBEXGUITEST", + "MOTION", + "SCIDEMO", + "SELAB", + "SELAB2", + "SOFTMAT", + ], + "Lab/test machines without a DAE at all", + ) + def test_GIVEN_streaming_dae_perspective_exists_THEN_it_is_set_to_not_shown_on_instruments_which_dont_use_a_streaming_dae( + self, + ): + raw_value = self.ca.get_value("CS:PERSP:SETTINGS") + if raw_value is None or raw_value == "": + self.skipTest("Instrument is unavailable") + + version = self.ca.get_version_string() + + version_major = int(version.split(".")[0]) + version_minor = int(version.split(".")[1]) + + if (version_major, version_minor) < (26, 8): + self.skipTest("Instrument is on a version without streaming DAE perspective") + + perspectives = json.loads(zlib.decompress(binascii.unhexlify(raw_value.encode("ascii")))) + + self.assertFalse( + perspectives.get( + "uk.ac.stfc.isis.ibex.client.e4.product.perspective.streamingdae", True + ) + ) From 57bc98150e429e433dafe04fc8e3e0beb9c60ccb Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 21 Aug 2026 12:57:08 +0100 Subject: [PATCH 2/4] Run GUI tests --- run_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_tests.py b/run_tests.py index fea02ab..03791bf 100644 --- a/run_tests.py +++ b/run_tests.py @@ -15,6 +15,7 @@ from tests.configuration_tests import ConfigurationsSingleTests, ConfigurationsTests from tests.dae_tests import DaeTests from tests.globals_tests import GlobalsTests +from tests.gui_tests import GuiTests from tests.motor_tests import MotorTests from tests.scripting_directory_tests import ScriptingDirectoryTests from tests.settings import Settings @@ -42,6 +43,7 @@ def run_instrument_tests(inst_name, reports_path): for case in [ ScriptingDirectoryTests, GlobalsTests, + GuiTests, VersionTests, ConfigurationsSingleTests, ComponentsSingleTests, From 13134a3530edf16b60f46a2b308b0761482abe60 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 21 Aug 2026 12:58:26 +0100 Subject: [PATCH 3/4] ruff --- run_tests.py | 30 ++++++++++-------------------- tests/gui_tests.py | 10 ++-------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/run_tests.py b/run_tests.py index 03791bf..d36cf0a 100644 --- a/run_tests.py +++ b/run_tests.py @@ -1,12 +1,8 @@ -from __future__ import absolute_import, print_function - import argparse import os import sys import traceback -import typing import unittest -from builtins import str from json import JSONDecodeError, loads from xmlrunner import XMLTestRunner @@ -60,11 +56,9 @@ def run_instrument_tests(inst_name, reports_path): configs = ConfigurationUtils(Settings.config_repo_path).get_configurations_as_list() components = ComponentUtils(Settings.config_repo_path).get_configurations_as_list() synoptics = SynopticUtils(Settings.config_repo_path).get_synoptics_filenames() - except IOError as e: + except OSError as e: print( - "Failed to build tests for instrument {}: exception occured while generating tests.".format( - inst_name - ) + f"Failed to build tests for instrument {inst_name}: exception occured while generating tests." ) traceback.print_exc(e) return False @@ -101,11 +95,11 @@ def setup_instrument_tests(instrument): name, hostname, pv_prefix = instrument["name"], instrument["hostName"], instrument["pvPrefix"] try: Settings.set_instrument(name, hostname, pv_prefix) - except Exception: - print("Unable to set instrument to {} because {}".format(name, traceback.format_exc())) + except Exception: # ruff: ignore[BLE001] + print(f"Unable to set instrument to {name} because {traceback.format_exc()}") return False - print("\n\nChecking out git repository for {} ({})...".format(name, hostname)) + print(f"\n\nChecking out git repository for {name} ({hostname})...") config_repo_update_successful = GitUtils(Settings.config_repo_path).update_branch(hostname) version_utils = VersionUtils(Settings.config_repo_path) @@ -113,7 +107,7 @@ def setup_instrument_tests(instrument): if version_utils.version_file_exists(): GuiUtils(Settings.gui_repo_path).get_gui_repo_at_release(version_utils.get_version()) else: - print("Warning: could not determine GUI version for instrument {}".format(instrument)) + print(f"Warning: could not determine GUI version for instrument {instrument}") return config_repo_update_successful @@ -127,7 +121,7 @@ def run_self_tests(reports_path): return XMLTestRunner(output=str(reports_path), stream=sys.stdout).run(suite).wasSuccessful() -def get_excluded_list_of_instruments() -> typing.List[str]: +def get_excluded_list_of_instruments() -> list[str]: """ Gets the excluded list of instruments by getting the value of the environment variable `DISABLE_CHECK_INST`. This needs to be in the format of a JSON list, for example: @@ -170,14 +164,10 @@ def _print_test_run_end_messages(): Method used to print any messages that should be printed at the end of the all instruments test run. """ print( - "{} non interesting component block pvs in total across all instruments".format( - ComponentsSingleTests.TOTAL_NON_INTERESTING_PVS_IN_BLOCKS - ) + f"{ComponentsSingleTests.TOTAL_NON_INTERESTING_PVS_IN_BLOCKS} non interesting component block pvs in total across all instruments" ) print( - "{} non interesting configuration block pvs in total across all instruments".format( - ConfigurationsSingleTests.TOTAL_NON_INTERESTING_PVS_IN_BLOCKS - ) + f"{ConfigurationsSingleTests.TOTAL_NON_INTERESTING_PVS_IN_BLOCKS} non interesting configuration block pvs in total across all instruments" ) @@ -224,7 +214,7 @@ def main(): instruments = ChannelAccessUtils().get_inst_list() if len(instruments) == 0: - raise IOError( + raise OSError( "No instruments found. This is probably because the instrument list PV is unavailable." ) diff --git a/tests/gui_tests.py b/tests/gui_tests.py index cc7154c..1441063 100644 --- a/tests/gui_tests.py +++ b/tests/gui_tests.py @@ -1,14 +1,7 @@ - import binascii import json -import sys -import zlib - -sys.path.append(".") -sys.path.append("..") -sys.path.append("../..") - import unittest +import zlib from tests.settings import Settings from util.channel_access import ChannelAccessUtils @@ -44,6 +37,7 @@ def test_GIVEN_streaming_dae_perspective_exists_THEN_it_is_set_to_not_shown_on_i self, ): raw_value = self.ca.get_value("CS:PERSP:SETTINGS") + assert isinstance(raw_value, str | None) if raw_value is None or raw_value == "": self.skipTest("Instrument is unavailable") From 3f362cbe4ad03d7e98c15923c83af439e29fa5d1 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 21 Aug 2026 13:16:22 +0100 Subject: [PATCH 4/4] remove blatant lie --- tests/gui_tests.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/gui_tests.py b/tests/gui_tests.py index 1441063..4a886f8 100644 --- a/tests/gui_tests.py +++ b/tests/gui_tests.py @@ -9,10 +9,6 @@ class GuiTests(unittest.TestCase): - """ - Tests in this class relate to the contents or existence of the globals.txt configuration file. - """ - def setUp(self): self.ca = ChannelAccessUtils(Settings.pv_prefix)