Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,6 +11,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
Expand Down Expand Up @@ -42,6 +39,7 @@ def run_instrument_tests(inst_name, reports_path):
for case in [
ScriptingDirectoryTests,
GlobalsTests,
GuiTests,
VersionTests,
ConfigurationsSingleTests,
ComponentsSingleTests,
Expand All @@ -58,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
Expand Down Expand Up @@ -99,19 +95,19 @@ 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)

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


Expand All @@ -125,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:
Expand Down Expand Up @@ -168,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"
)


Expand Down Expand Up @@ -222,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."
)

Expand Down
54 changes: 54 additions & 0 deletions tests/gui_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import binascii
import json
import unittest
import zlib

from tests.settings import Settings
from util.channel_access import ChannelAccessUtils
from util.common import skip_on_instruments


class GuiTests(unittest.TestCase):
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")
assert isinstance(raw_value, str | None)
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
)
)