From b5609f14823ecccf2ce7f207b7c0364771e6d4a7 Mon Sep 17 00:00:00 2001 From: Lowri Jenkins Date: Fri, 12 Jul 2024 16:14:31 +0100 Subject: [PATCH] Run ruff --fix --- check_version.py | 4 +- run_tests.py | 3 +- src/common_upgrades/add_to_base_iocs.py | 20 ++--- .../change_macro_in_globals.py | 39 +++------ src/common_upgrades/change_macros_in_xml.py | 31 +++---- src/common_upgrades/change_pvs_in_xml.py | 28 +++---- src/common_upgrades/sql_utilities.py | 28 +++---- .../synoptics_and_device_screens.py | 9 +-- src/common_upgrades/utils/macro.py | 3 +- src/file_access.py | 80 +++++++------------ src/git_utils.py | 2 +- src/local_logger.py | 16 ++-- src/upgrade.py | 17 ++-- src/upgrade_step.py | 8 +- src/upgrade_step_add_meta_tag.py | 13 ++- src/upgrade_step_check_init_inst.py | 19 ++--- src/upgrade_step_from_10p0p0.py | 6 +- src/upgrade_step_from_11p0p0.py | 8 +- src/upgrade_step_from_12p0p0.py | 5 +- src/upgrade_step_from_12p0p1.py | 3 +- src/upgrade_step_from_12p0p2.py | 6 +- src/upgrade_step_from_12p0p3.py | 6 +- src/upgrade_step_from_6p0p0.py | 3 +- src/upgrade_step_from_7p2p0.py | 23 +++--- src/upgrade_step_from_7p4p0.py | 3 +- src/upgrade_step_from_9p0p0.py | 9 +-- src/upgrade_step_noop.py | 8 +- test/mother.py | 13 +-- test/test_add_to_base_iocs.py | 10 +-- test/test_globals_macro_changing.py | 7 +- test/test_sql_utils.py | 5 +- test/test_upgrade_base.py | 6 +- test/test_upgrade_step_check_init_inst.py | 14 ++-- test/test_upgrade_step_from_10p0p0.py | 4 +- test/test_upgrade_step_from_12p0p0.py | 3 +- test/test_upgrade_step_from_7p2p0.py | 8 +- test/test_utils.py | 1 + test/test_xml_macro_changer.py | 18 ++--- test/test_xml_pv_changer.py | 4 +- upgrade.py | 5 +- 40 files changed, 196 insertions(+), 302 deletions(-) diff --git a/check_version.py b/check_version.py index 30a4fc6..7ce98de 100644 --- a/check_version.py +++ b/check_version.py @@ -1,4 +1,6 @@ -import upgrade, sys +import sys + +import upgrade def compare_version_number(version_to_check): diff --git a/run_tests.py b/run_tests.py index 015faac..b223750 100644 --- a/run_tests.py +++ b/run_tests.py @@ -22,9 +22,10 @@ os.environ["MYDIRBLOCK"] = ".." sys.path.insert(0, os.path.abspath("..")) # Standard imports +import argparse import unittest + import xmlrunner -import argparse DEFAULT_DIRECTORY = os.path.join("..", "..", "..", "test-reports") diff --git a/src/common_upgrades/add_to_base_iocs.py b/src/common_upgrades/add_to_base_iocs.py index f8bf12c..62017e2 100644 --- a/src/common_upgrades/add_to_base_iocs.py +++ b/src/common_upgrades/add_to_base_iocs.py @@ -1,8 +1,6 @@ from xml.dom import minidom from xml.parsers.expat import ExpatError -from src.local_logger import LocalLogger - IOC_FILENAME = "configurations\components\_base\iocs.xml" FILE_TO_CHECK_STR = "IOC default component file" @@ -12,8 +10,7 @@ class AddToBaseIOCs: - """ - Add the ioc autostart to _base ioc so that it autostarts + """Add the ioc autostart to _base ioc so that it autostarts """ def __init__(self, ioc_to_add, add_after_ioc, xml_to_add): @@ -22,8 +19,7 @@ def __init__(self, ioc_to_add, add_after_ioc, xml_to_add): self._xml_to_add = xml_to_add def perform(self, file_access, logger): - """ - Add the autostart of the given. + """Add the autostart of the given. Args: file_access (FileAccess): file access. @@ -60,8 +56,7 @@ def perform(self, file_access, logger): @staticmethod def _get_ioc_names(xml): - """ - Gets the names of all the iocs in the xml. + """Gets the names of all the iocs in the xml. Args: xml: XML to check. @@ -72,8 +67,7 @@ def _get_ioc_names(xml): return [ioc.getAttribute("name") for ioc in xml.getElementsByTagName("ioc")] def _check_final_file_contains_one_of_added_ioc(self, logger, xml): - """ - Check the file to make sure it now contains one and only one ioc added entry. + """Check the file to make sure it now contains one and only one ioc added entry. Args: logger (Logger): Logger to write to. @@ -92,8 +86,7 @@ def _check_final_file_contains_one_of_added_ioc(self, logger, xml): return True def _check_prerequistes_for_file(self, xml, logger): - """ - Check the file can be modified. + """Check the file can be modified. Args: xml: XML to check @@ -117,8 +110,7 @@ def _check_prerequistes_for_file(self, xml, logger): return True def _add_ioc(self, ioc_xml, logger): - """ - Add IOC entry after add after ioc specified if it exists. + """Add IOC entry after add after ioc specified if it exists. Args: ioc_xml: XML to add to. diff --git a/src/common_upgrades/change_macro_in_globals.py b/src/common_upgrades/change_macro_in_globals.py index e8ec10c..fb56843 100644 --- a/src/common_upgrades/change_macro_in_globals.py +++ b/src/common_upgrades/change_macro_in_globals.py @@ -1,15 +1,14 @@ import re + from src.common_upgrades.utils.constants import GLOBALS_FILENAME class ChangeMacroInGlobals(object): - """ - An interface to replace arbitrary macros in a globals.txt file + """An interface to replace arbitrary macros in a globals.txt file """ def __init__(self, file_access, logger): - """ - Initialise. + """Initialise. Args: file_access: Object to allow for file access. @@ -20,22 +19,19 @@ def __init__(self, file_access, logger): self._loaded_file = self.load_globals_file() def load_globals_file(self): - """ - Loads in a globals file as a list of strings. + """Loads in a globals file as a list of strings. Returns: Globals file loaded as list of strings if globals file exists. Empty list otherwise. """ - if self._file_access.exists(GLOBALS_FILENAME): return self._file_access.open_file(GLOBALS_FILENAME) else: return [] def change_macros(self, ioc_name, macros_to_change): - """ - Changes a list of macros in the globals.txt file for a specific IOC. + """Changes a list of macros in the globals.txt file for a specific IOC. Args: ioc_name: Name of the IOC. @@ -45,7 +41,6 @@ def change_macros(self, ioc_name, macros_to_change): Returns: None """ - for old_macro, new_macro in macros_to_change: for index in self._globals_filter_generator(ioc_name): self._apply_regex_macro_change(ioc_name, old_macro, new_macro, index) @@ -53,8 +48,7 @@ def change_macros(self, ioc_name, macros_to_change): self.write_modified_globals_file() def change_ioc_name(self, old_ioc_name, new_ioc_name): - """ - Changes the name of an IOC in a globals.txt file. + """Changes the name of an IOC in a globals.txt file. Args: old_ioc_name: String, the old name of the IOC @@ -64,15 +58,13 @@ def change_ioc_name(self, old_ioc_name, new_ioc_name): None """ - for index in self._globals_filter_generator(old_ioc_name): self._change_ioc_name(old_ioc_name, new_ioc_name, index) self.write_modified_globals_file() def _globals_filter_generator(self, ioc_to_change): - """ - Returns lines containing specified IOCs from globals.txt + """Returns lines containing specified IOCs from globals.txt Generator that gives all the lines for a given IOC in globals.txt. This will match IOCs with the same name as the root plus any that have a number @@ -84,15 +76,13 @@ def _globals_filter_generator(self, ioc_to_change): Yields: Index that the ioc is on. """ - for index, line in enumerate(self._loaded_file): if line.startswith("{}_".format(ioc_to_change)): self._logger.info("Found line '{}' in {}".format(line, GLOBALS_FILENAME)) yield index def _determine_replacement_values(self, old_macro, new_macro): - """ - Determines the strings to search for and replace. + """Determines the strings to search for and replace. Args: old_macro: Old Macro object with old macro name and old macro value. @@ -101,7 +91,6 @@ def _determine_replacement_values(self, old_macro, new_macro): Returns: regex_changes: Dictionary of regex representations of the strings to search for/replace. """ - if old_macro.value is None: old_value_search = r".*" @@ -123,8 +112,7 @@ def _determine_replacement_values(self, old_macro, new_macro): return regex_changes def _apply_regex_macro_change(self, ioc_name, old_macro, new_macro, line_number): - """ - Applies a regular expression to modify a macro. + """Applies a regular expression to modify a macro. Args: ioc_name: Name of the IOC to @@ -132,7 +120,6 @@ def _apply_regex_macro_change(self, ioc_name, old_macro, new_macro, line_number) Returns: None """ - regex_args = self._determine_replacement_values(old_macro, new_macro) replace_regex = re.compile( @@ -150,8 +137,7 @@ def _apply_regex_macro_change(self, ioc_name, old_macro, new_macro, line_number) ) def _change_ioc_name(self, ioc_name, new_ioc_name, line_number): - """ - If a new name is supplied, changes the name of the IOC + """If a new name is supplied, changes the name of the IOC Args: ioc_name: String, the current name of the IOC @@ -160,19 +146,16 @@ def _change_ioc_name(self, ioc_name, new_ioc_name, line_number): Returns: None """ - if new_ioc_name is not None: self._loaded_file[line_number] = self._loaded_file[line_number].replace( ioc_name, new_ioc_name.upper() ) def write_modified_globals_file(self): - """ - Writes the modified globals file if it has been loaded. + """Writes the modified globals file if it has been loaded. Returns: None """ - if self._loaded_file: self._file_access.write_file(GLOBALS_FILENAME, self._loaded_file) diff --git a/src/common_upgrades/change_macros_in_xml.py b/src/common_upgrades/change_macros_in_xml.py index 29f9012..db9e875 100644 --- a/src/common_upgrades/change_macros_in_xml.py +++ b/src/common_upgrades/change_macros_in_xml.py @@ -5,8 +5,7 @@ def change_macro_name(macro, old_macro_name, new_macro_name): - """ - Changes the macro name of a macro xml node. + """Changes the macro name of a macro xml node. Args: macro : The macro node to change. @@ -19,8 +18,7 @@ def change_macro_name(macro, old_macro_name, new_macro_name): def change_macro_value(macro, old_macro_value, new_macro_value): - """ - Changes the macros in the given xml if a new macro value is given. + """Changes the macros in the given xml if a new macro value is given. Args: macro : The macro xml node to change. @@ -36,8 +34,7 @@ def change_macro_value(macro, old_macro_value, new_macro_value): def find_macro_with_name(macros, name_to_find): - """ - Find whether macro with name attribute equal to argument name_to_find exists + """Find whether macro with name attribute equal to argument name_to_find exists Args: macros: XML element containing list of macros @@ -52,13 +49,11 @@ def find_macro_with_name(macros, name_to_find): class ChangeMacrosInXML(object): - """ - Changes macros in XML files. + """Changes macros in XML files. """ def __init__(self, file_access, logger): - """ - Initialise. + """Initialise. Args: file_access: Object to allow for file access. @@ -70,8 +65,7 @@ def __init__(self, file_access, logger): def add_macro( self, ioc_name, macro_to_add, pattern, description="No description", default_value=None ): - """ - Add a macro with a specified name and value to all IOCs whose name begins with ioc_name, unless a macro + """Add a macro with a specified name and value to all IOCs whose name begins with ioc_name, unless a macro with that name already exists Args: @@ -96,12 +90,12 @@ def add_macro( self._file_access.write_xml_file(path, ioc_xml) def change_macros(self, ioc_name, macros_to_change): - """ - Changes macros in all xml files that contain the correct macros for a specified ioc. + """Changes macros in all xml files that contain the correct macros for a specified ioc. Args: ioc_name: Name of the IOC to change macros within. macros_to_change: List of 2-tuples of old_macro and new_macro Macro classes. + Returns: None. """ @@ -119,8 +113,7 @@ def change_macros(self, ioc_name, macros_to_change): self._file_access.write_xml_file(path, ioc_xml) def change_ioc_name(self, old_ioc_name, new_ioc_name): - """ - Replaces all instances of old_ioc_name with new_ioc_name in an XML tree + """Replaces all instances of old_ioc_name with new_ioc_name in an XML tree Args: old_ioc_name: String, the old ioc prefix (without _XX number suffix) new_ioc_name: String, The desired new IOC prefix (without _XX number suffix) @@ -140,8 +133,7 @@ def change_ioc_name(self, old_ioc_name, new_ioc_name): self._file_access.write_xml_file(path, ioc_xml) def change_ioc_name_in_synoptics(self, old_ioc_name, new_ioc_name): - """ - Replaces instances of old_ioc_name with new_ioc_name + """Replaces instances of old_ioc_name with new_ioc_name Args: old_ioc_name: String, the old ioc prefix (without _XX number suffix) @@ -176,8 +168,7 @@ def change_ioc_name_in_synoptics(self, old_ioc_name, new_ioc_name): self._file_access.write_xml_file(xml_path, synoptic_xml) def ioc_tag_generator(self, path, ioc_xml, ioc_to_change): - """ - Generator giving all the IOC tags in all configurations. + """Generator giving all the IOC tags in all configurations. Args: path: Path to the xml file diff --git a/src/common_upgrades/change_pvs_in_xml.py b/src/common_upgrades/change_pvs_in_xml.py index 48c87e1..e494e91 100644 --- a/src/common_upgrades/change_pvs_in_xml.py +++ b/src/common_upgrades/change_pvs_in_xml.py @@ -2,13 +2,11 @@ class ChangePVsInXML(object): - """ - Changes pvs in XML files. + """Changes pvs in XML files. """ def __init__(self, file_access, logger): - """ - Initialise. + """Initialise. Args: file_access: Object to allow for file access. @@ -18,8 +16,8 @@ def __init__(self, file_access, logger): self._logger = logger def node_text_filter(self, filter_text, element_name, path, xml): - """ - A generator that gives all the instances of filter_text within the element_name elements of the input_files. + """A generator that gives all the instances of filter_text within the element_name elements of the input_files. + Args: filter_text: String, ext to find element_name: String, tag name of the elements where to look for filter_text @@ -38,8 +36,7 @@ def node_text_filter(self, filter_text, element_name, path, xml): yield node def _replace_text_in_elements(self, old_text, new_text, element_name, input_files): - """ - Replaces all instances of old_text with new_text in all element_name elements of one or more XML files + """Replaces all instances of old_text with new_text in all element_name elements of one or more XML files Args: old_text: String, old text to find new_text: String, new text to substitute @@ -54,8 +51,7 @@ def _replace_text_in_elements(self, old_text, new_text, element_name, input_file self._file_access.write_xml_file(path, xml) def change_pv_name(self, old_pv_name, new_pv_name): - """ - Replaces all instances of old_pv_name with new_pv_name in the blocks config and all synoptics + """Replaces all instances of old_pv_name with new_pv_name in the blocks config and all synoptics Args: old_pv_name: String, the old pv name new_pv_name: String, The desired new pv name @@ -65,8 +61,8 @@ def change_pv_name(self, old_pv_name, new_pv_name): self.change_pv_names_in_synoptics(old_pv_name, new_pv_name) def change_pv_name_in_blocks(self, old_pv_name, new_pv_name): - """ - Move any blocks pointing at old_pv_name to point at new_pv_name. + """Move any blocks pointing at old_pv_name to point at new_pv_name. + Args: old_pv_name: The old PV to remove references to new_pv_name: The new PV to replace it with @@ -76,8 +72,8 @@ def change_pv_name_in_blocks(self, old_pv_name, new_pv_name): ) def change_pv_names_in_synoptics(self, old_pv_name, new_pv_name): - """ - Move any synoptic PV targets from pointing at old_pv_name to point to new_pv_name. + """Move any synoptic PV targets from pointing at old_pv_name to point to new_pv_name. + Args: old_pv_name: The old PV to remove references to new_pv_name: The new PV to replace it with @@ -87,8 +83,8 @@ def change_pv_names_in_synoptics(self, old_pv_name, new_pv_name): ) def get_number_of_instances_of_pv(self, pv_names): - """ - Get the number of instances of a PV in the config and synoptic. + """Get the number of instances of a PV in the config and synoptic. + Args: pv_names: String, a list of pvs to search for Return: diff --git a/src/common_upgrades/sql_utilities.py b/src/common_upgrades/sql_utilities.py index 6c00301..9788660 100644 --- a/src/common_upgrades/sql_utilities.py +++ b/src/common_upgrades/sql_utilities.py @@ -1,16 +1,15 @@ -""" -Helpful sql utilities +"""Helpful sql utilities """ -from getpass import getpass import os import re +from getpass import getpass + import mysql.connector class SqlConnection: - """ - Class to allow sql access. Should be used in the top scope and sessions are got using get_session. + """Class to allow sql access. Should be used in the top scope and sessions are got using get_session. """ _connection = None @@ -20,8 +19,8 @@ def __init__(self): @staticmethod def get_session(logger): - """ - Get the database session; creates one if needed. + """Get the database session; creates one if needed. + Args: logger: the logger to use @@ -49,8 +48,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): def run_sql(logger, sql): - """ - Sends an SQL statement to the database. + """Sends an SQL statement to the database. + Args: logger: the logger to use to log messages sql: The statement to send @@ -64,8 +63,8 @@ def run_sql(logger, sql): def run_sql_list(logger, sql_list): - """ - Sends a list of SQL statement to the database. + """Sends a list of SQL statement to the database. + Args: logger: the logger to use to log messages sql_list: The statement to send @@ -81,8 +80,8 @@ def run_sql_list(logger, sql_list): def run_sql_file(logger, file): - """ - Sends an SQL statement to the database. + """Sends an SQL statement to the database. + Args: logger: the logger to use to log messages file: The file of sql statement to send @@ -109,8 +108,7 @@ def run_sql_file(logger, file): def add_new_user(logger, user, password): - """ - Adds a user with all permissions to the exp_user database + """Adds a user with all permissions to the exp_user database Args: logger: the logger to use to log messages user: The name of the user in form 'username'@'host' diff --git a/src/common_upgrades/synoptics_and_device_screens.py b/src/common_upgrades/synoptics_and_device_screens.py index a991c90..463b11d 100644 --- a/src/common_upgrades/synoptics_and_device_screens.py +++ b/src/common_upgrades/synoptics_and_device_screens.py @@ -2,8 +2,7 @@ class SynopticsAndDeviceScreens(object): - """ - Manipulate an instrument's synoptics and device_screens + """Manipulate an instrument's synoptics and device_screens """ def __init__(self, file_access, logger): @@ -17,8 +16,7 @@ def __init__(self, file_access, logger): ) def update_opi_keys(self, keys_to_update): - """ - Update the OPI keys in all synoptics and device screens + """Update the OPI keys in all synoptics and device screens Args: keys_to_update (Dict)): The OPI keys that need updating as a dictionary with {old_key: new_key} @@ -52,8 +50,7 @@ def update_opi_keys(self, keys_to_update): return result def _update_opi_keys_in_xml(self, path, xml, keys_to_update, root_tag, key_tag): - """ - Replaces an opi key with a different key + """Replaces an opi key with a different key Args: path (String): path to file to update diff --git a/src/common_upgrades/utils/macro.py b/src/common_upgrades/utils/macro.py index c4ad7a2..c765f50 100644 --- a/src/common_upgrades/utils/macro.py +++ b/src/common_upgrades/utils/macro.py @@ -1,6 +1,5 @@ class Macro(object): - """ - Macro Object + """Macro Object Attributes: name: Macro name. E.g. GALILADDR. diff --git a/src/file_access.py b/src/file_access.py index 1b4f2cd..4618483 100644 --- a/src/file_access.py +++ b/src/file_access.py @@ -1,24 +1,23 @@ import os -from xml.dom import minidom import shutil +from xml.dom import minidom from xml.parsers.expat import ExpatError + from src.common_upgrades.utils.constants import ( - CONFIG_FOLDER, COMPONENT_FOLDER, - SYNOPTIC_FOLDER, + CONFIG_FOLDER, DEVICE_SCREEN_FILE, DEVICE_SCREENS_FOLDER, + SYNOPTIC_FOLDER, ) class FileAccess(object): - """ - File access for the configuration + """File access for the configuration """ def __init__(self, logger, config_root): - """ - Constructor + """Constructor Args: logger: the logger to use @@ -29,9 +28,7 @@ def __init__(self, logger, config_root): self._logger = logger def rename_file(self, filename, new_name): - """ - - Rename a file + """Rename a file Args: filename: current filename @@ -41,9 +38,7 @@ def rename_file(self, filename, new_name): os.rename(filename, new_name) def open_file(self, filename): - """ - - Open a file and return the object + """Open a file and return the object Args: filename: filename to open @@ -58,8 +53,7 @@ def open_file(self, filename): return lines def write_version_number(self, version, filename): - """ - Write the version number to the file + """Write the version number to the file Args: version: version to write filename: filename to write to (relative to config root) @@ -72,8 +66,7 @@ def write_version_number(self, version, filename): f.write("{}\n".format(version)) def write_file(self, filename, file_contents, mode="w", file_full=False): - """ - Write file contents (will overwrite existing files) + """Write file contents (will overwrite existing files) Args: filename: filename to write to @@ -93,8 +86,7 @@ def write_file(self, filename, file_contents, mode="w", file_full=False): f.write(file_contents) def create_directories(self, path): - """ - Create directories starting at config base path + """Create directories starting at config base path Args: path: path for directories to be created @@ -105,8 +97,7 @@ def create_directories(self, path): os.makedirs(os.path.dirname(os.path.join(self.config_base, path)), exist_ok=True) def line_exists(self, filename, string): - """ - Check if string exists as a line in file + """Check if string exists as a line in file """ with open(os.path.join(self.config_base, filename), "r") as f: for line in f: @@ -115,8 +106,7 @@ def line_exists(self, filename, string): return False def file_contains(self, filename, string): - """ - Check if a string exists in a file + """Check if a string exists in a file """ with open(os.path.join(self.config_base, filename), "r") as f: for line in f: @@ -125,8 +115,7 @@ def file_contains(self, filename, string): return False def open_xml_file(self, filename): - """ - Open a file and returns the xml it contains + """Open a file and returns the xml it contains Args: filename: filename to open @@ -137,9 +126,7 @@ def open_xml_file(self, filename): return minidom.parse(os.path.join(self.config_base, filename)) def write_xml_file(self, filename, xml): - """ - - Saves xml to a file + """Saves xml to a file Args: filename: filename to save @@ -147,7 +134,6 @@ def write_xml_file(self, filename, xml): Returns: """ - # this can not use pretty print because that will cause it to gain tabs and newlines with open(os.path.join(self.config_base, filename), mode="w") as f: self._logger.info("Writing xml file {0}".format(filename)) @@ -156,8 +142,7 @@ def write_xml_file(self, filename, xml): f.write("\n") def listdir(self, dir): - """ - Returns a list of files in a directory + """Returns a list of files in a directory Args: dir (String): The directory to list @@ -168,8 +153,7 @@ def listdir(self, dir): return [os.path.join(dir, f) for f in os.listdir(os.path.join(self.config_base, dir))] def remove_file(self, filename): - """ - Removes a file from the file system. + """Removes a file from the file system. Args: filename (str): The file to remove, relative to the config directory @@ -178,8 +162,7 @@ def remove_file(self, filename): os.remove(os.path.join(self.config_base, filename)) def delete_folder(self, path): - """ - Deletes a folder recursively. + """Deletes a folder recursively. Args: path (String): The folder to remove @@ -187,8 +170,7 @@ def delete_folder(self, path): shutil.rmtree(path) def is_dir(self, path): - """ - Checks whether a path is a directory or file. + """Checks whether a path is a directory or file. Args: path (str): The path relative to the configuration directory. @@ -210,8 +192,7 @@ def _get_xml(self, path): raise ExpatError("{} is invalid xml '{}'".format(path, ex)) def get_config_files(self, file_type): - """ - Generator giving all the config files of a given type. + """Generator giving all the config files of a given type. Args: file_type: The type of file that you want to get e.g. iocs.xml @@ -225,8 +206,7 @@ def get_config_files(self, file_type): yield xml_path, self._get_xml(xml_path) def get_synoptic_files(self): - """ - Generator giving all the synoptic config files + """Generator giving all the synoptic config files Yields: Tuple: The path to the synoptic file and its xml representation. @@ -237,8 +217,7 @@ def get_synoptic_files(self): yield synoptic_path, self._get_xml(synoptic_path) def get_device_screens(self): - """ - Returns the device screen file if it exists, else None. + """Returns the device screen file if it exists, else None. """ device_screens_path = os.path.join(DEVICE_SCREENS_FOLDER, DEVICE_SCREEN_FILE) if os.path.exists(device_screens_path): @@ -247,8 +226,7 @@ def get_device_screens(self): return None def get_file_paths(self, directory: str, extension: str = None): - """ - Generator giving the paths of all files inside a directory, recursively searching all subdirectories. + """Generator giving the paths of all files inside a directory, recursively searching all subdirectories. Args: directory: The directory to search. @@ -264,8 +242,7 @@ def get_file_paths(self, directory: str, extension: str = None): class CachingFileAccess(object): - """ - Context that uses the given file access object but does not actually write to file until the context is left + """Context that uses the given file access object but does not actually write to file until the context is left without an error. """ @@ -286,8 +263,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.write() def open_xml_file(self, filename): - """ - Open a file and returns the xml it contains (returns the cached file if it exists) + """Open a file and returns the xml it contains (returns the cached file if it exists) Args: filename: filename to open @@ -301,8 +277,7 @@ def open_xml_file(self, filename): return self.old_open_method(filename) def write_xml_file(self, filename, xml): - """ - Caches a write of xml to a file + """Caches a write of xml to a file Args: filename: filename to save @@ -311,8 +286,7 @@ def write_xml_file(self, filename, xml): self.cached_writes[filename] = xml def write(self): - """ - Write all cached writes to the file. + """Write all cached writes to the file. """ for filename, xml in self.cached_writes.items(): self._file_access.write_xml_file(filename, xml) diff --git a/src/git_utils.py b/src/git_utils.py index 33c846f..8f5d90a 100644 --- a/src/git_utils.py +++ b/src/git_utils.py @@ -7,6 +7,6 @@ def get_repo(working_directory): # Check repo try: return git.Repo(working_directory, search_parent_directories=True) - except Exception as e: + except Exception: # Not a valid repository raise git.NotUnderVersionControl(working_directory) diff --git a/src/local_logger.py b/src/local_logger.py index a471687..a805c80 100644 --- a/src/local_logger.py +++ b/src/local_logger.py @@ -1,17 +1,14 @@ +import datetime import os import sys -import datetime - class LocalLogger(object): - """ - A local logging object which will write to the screen and a file + """A local logging object which will write to the screen and a file """ def __init__(self, log_dir): - """ - The logging directory in to which to write the log file + """The logging directory in to which to write the log file Args: log_dir: the directory for the file @@ -26,8 +23,7 @@ def __init__(self, log_dir): self._log_file = log_file def error(self, message): - """ - Write the message as an error (to standard err with ERROR in front of it) + """Write the message as an error (to standard err with ERROR in front of it) Args: message: message to write (no new lines needed) @@ -41,8 +37,7 @@ def error(self, message): sys.stderr.write(formatted_message) def info(self, message): - """ - Write the message as info (to standard out with INFO in front of it) + """Write the message as info (to standard out with INFO in front of it) Args: message: message to write (no new lines needed) @@ -50,7 +45,6 @@ def info(self, message): Returns: """ - formatted_message = " INFO: {0}{1}".format(message, os.linesep) with open(self._log_file, mode="a") as f: f.write(formatted_message) diff --git a/src/upgrade.py b/src/upgrade.py index 9154a53..c8f9d28 100644 --- a/src/upgrade.py +++ b/src/upgrade.py @@ -1,28 +1,23 @@ import os from src.common_upgrades.sql_utilities import SqlConnection -from src.file_access import FileAccess -from src.local_logger import LocalLogger VERSION_FILENAME = os.path.join("configurations", "config_version.txt") class UpgradeError(Exception): - """ - There is an error in the upgrade + """There is an error in the upgrade """ pass class Upgrade(object): - """ - Use upgrade steps to upgrade a configuration + """Use upgrade steps to upgrade a configuration """ def __init__(self, file_access, logger, upgrade_steps, git_repo): - """ - Constructor + """Constructor Args: file_access (FileAccess): an object to interact with files @@ -40,8 +35,7 @@ def __init__(self, file_access, logger, upgrade_steps, git_repo): self._git_repo = git_repo def get_version_number(self): - """ - Find the current version number of the repository. If there is no version number the + """Find the current version number of the repository. If there is no version number the repository is considered unversioned and the lowest version is written to the repository Returns: the version number @@ -55,8 +49,7 @@ def get_version_number(self): return initial_version_number def upgrade(self): - """ - Perform an upgrade on the configuration directory + """Perform an upgrade on the configuration directory Returns: status code 0 for success; not 0 for failure diff --git a/src/upgrade_step.py b/src/upgrade_step.py index de07880..13292d4 100644 --- a/src/upgrade_step.py +++ b/src/upgrade_step.py @@ -1,19 +1,15 @@ from abc import ABCMeta, abstractmethod -from src.file_access import FileAccess -from src.local_logger import LocalLogger class UpgradeStep(object): - """ - An upgrade step base object to be inherited from + """An upgrade step base object to be inherited from """ __metaclass__ = ABCMeta @abstractmethod def perform(self, file_access, logger): - """ - Perform the upgrade step this should be implemented + """Perform the upgrade step this should be implemented Args: file_access (FileAccess): file access diff --git a/src/upgrade_step_add_meta_tag.py b/src/upgrade_step_add_meta_tag.py index 7768ee8..588a2dc 100644 --- a/src/upgrade_step_add_meta_tag.py +++ b/src/upgrade_step_add_meta_tag.py @@ -1,14 +1,12 @@ -from src.upgrade_step import UpgradeStep -from src.common_upgrades.utils.constants import CONFIG_FOLDER -from src.common_upgrades.utils.constants import COMPONENT_FOLDER - import os import xml.etree.ElementTree as ET +from src.common_upgrades.utils.constants import COMPONENT_FOLDER, CONFIG_FOLDER +from src.upgrade_step import UpgradeStep + class UpgradeStepAddMetaXmlElement(UpgradeStep): - """ - An upgrade step that adds a passed element to the meta.xml for a configuration. + """An upgrade step that adds a passed element to the meta.xml for a configuration. """ def __init__(self, tag, tag_value): @@ -17,8 +15,7 @@ def __init__(self, tag, tag_value): super(UpgradeStepAddMetaXmlElement, self).__init__() def perform(self, file_access, logger): - """ - Change meta.xml configuration schema to have self.tag element + """Change meta.xml configuration schema to have self.tag element Args: file_access (FileAccess): file access diff --git a/src/upgrade_step_check_init_inst.py b/src/upgrade_step_check_init_inst.py index afd955d..49ae381 100644 --- a/src/upgrade_step_check_init_inst.py +++ b/src/upgrade_step_check_init_inst.py @@ -1,19 +1,16 @@ -from src.file_access import FileAccess -from src.local_logger import LocalLogger -from src.upgrade_step import UpgradeStep -from src.common_upgrades.utils.constants import SCRIPTS_ROOT import os +from src.common_upgrades.utils.constants import SCRIPTS_ROOT +from src.upgrade_step import UpgradeStep + class UpgradeStepCheckInitInst(UpgradeStep): - """ - An upgrade step to check if the instrument uses the old style of loading in pre and post cmd. + """An upgrade step to check if the instrument uses the old style of loading in pre and post cmd. This old style is via API.__localmod in init_.py in the Instrument/Settings/config/NDX/Python folder. """ def search_files(self, files, root, file_access): - """ - Search files from a root folder for pre and post cmd methods. + """Search files from a root folder for pre and post cmd methods. Args: files (List[str]): The names of the files in the root directory. @@ -36,8 +33,7 @@ def search_files(self, files, root, file_access): return 0 def search_folder(self, folder, file_access): - """ - Search folders for the search string. + """Search folders for the search string. Args: folder (str): The folder to search through. @@ -54,8 +50,7 @@ def search_folder(self, folder, file_access): return 0 if file_returns == "" else file_returns def perform(self, file_access, logger): - """ - Check if file exists and if the file includes pre and post cmd methods. + """Check if file exists and if the file includes pre and post cmd methods. Args: file_access (FileAccess): file access diff --git a/src/upgrade_step_from_10p0p0.py b/src/upgrade_step_from_10p0p0.py index 7f4b0a5..6468ff7 100644 --- a/src/upgrade_step_from_10p0p0.py +++ b/src/upgrade_step_from_10p0p0.py @@ -1,10 +1,10 @@ -from src.upgrade_step import UpgradeStep import os +from src.upgrade_step import UpgradeStep + class RemoveReflDeviceScreen(UpgradeStep): - """ - Remove reflectometry device screen from all configs and components + """Remove reflectometry device screen from all configs and components """ path = os.path.join("configurations", "devices", "screens.xml") diff --git a/src/upgrade_step_from_11p0p0.py b/src/upgrade_step_from_11p0p0.py index 905678f..1a039ec 100644 --- a/src/upgrade_step_from_11p0p0.py +++ b/src/upgrade_step_from_11p0p0.py @@ -1,13 +1,13 @@ import socket -from src.upgrade_step import UpgradeStep -from src.common_upgrades.utils.macro import Macro + from src.common_upgrades.change_macros_in_xml import ChangeMacrosInXML from src.common_upgrades.change_pvs_in_xml import ChangePVsInXML +from src.common_upgrades.utils.macro import Macro +from src.upgrade_step import UpgradeStep class RenameMercurySoftwarePressureControlMacros(UpgradeStep): - """ - SPC_... macro names have been adjusted to FLOW_SPC... names to differentiate them + """SPC_... macro names have been adjusted to FLOW_SPC... names to differentiate them from the new VTI Software Pressure Control macros that have been added with the new logic. Rename the old macros to the new ones. diff --git a/src/upgrade_step_from_12p0p0.py b/src/upgrade_step_from_12p0p0.py index 3c03eb6..35322ce 100644 --- a/src/upgrade_step_from_12p0p0.py +++ b/src/upgrade_step_from_12p0p0.py @@ -1,15 +1,14 @@ import os import re -from src.upgrade_step import UpgradeStep from src.common_upgrades.utils.constants import SUPPORT_ROOT from src.file_access import FileAccess from src.local_logger import LocalLogger +from src.upgrade_step import UpgradeStep class UpgradeJawsForPositionAutosave(UpgradeStep): - """ - Update all batch files that load a database file using 'slits.template' to support autosave. + """Update all batch files that load a database file using 'slits.template' to support autosave. """ def perform(self, file_access: FileAccess, logger: LocalLogger): diff --git a/src/upgrade_step_from_12p0p1.py b/src/upgrade_step_from_12p0p1.py index 69dcc03..b364c73 100644 --- a/src/upgrade_step_from_12p0p1.py +++ b/src/upgrade_step_from_12p0p1.py @@ -5,8 +5,7 @@ class AddOscCollimMovingIndicator(UpgradeStep): - """ - Update oscillatingCollimator.cmd on LET and MERLIN to load stability check DB + """Update oscillatingCollimator.cmd on LET and MERLIN to load stability check DB """ path = os.path.join("configurations", "galil", "oscillatingCollimator.cmd") diff --git a/src/upgrade_step_from_12p0p2.py b/src/upgrade_step_from_12p0p2.py index aca777d..9833b65 100644 --- a/src/upgrade_step_from_12p0p2.py +++ b/src/upgrade_step_from_12p0p2.py @@ -1,14 +1,12 @@ import os -import socket -from src.upgrade_step import UpgradeStep from src.common_upgrades.sql_utilities import SqlConnection, run_sql_file from src.common_upgrades.utils.constants import EPICS_ROOT +from src.upgrade_step import UpgradeStep class UpgradeFrom12p0p2(UpgradeStep): - """ - add sql tables for JMS2RDB + """add sql tables for JMS2RDB """ def perform(self, file_access, logger): diff --git a/src/upgrade_step_from_12p0p3.py b/src/upgrade_step_from_12p0p3.py index af1b85a..b4aabcb 100644 --- a/src/upgrade_step_from_12p0p3.py +++ b/src/upgrade_step_from_12p0p3.py @@ -1,14 +1,12 @@ import os -import socket -from src.upgrade_step import UpgradeStep from src.common_upgrades.sql_utilities import SqlConnection, run_sql_file from src.common_upgrades.utils.constants import EPICS_ROOT +from src.upgrade_step import UpgradeStep class UpgradeFrom12p0p3(UpgradeStep): - """ - add sql tables for MOXA + """add sql tables for MOXA """ def perform(self, file_access, logger): diff --git a/src/upgrade_step_from_6p0p0.py b/src/upgrade_step_from_6p0p0.py index a8c7b1f..2674c1e 100644 --- a/src/upgrade_step_from_6p0p0.py +++ b/src/upgrade_step_from_6p0p0.py @@ -6,8 +6,7 @@ class SetDanfysikDisableAutoonoffMacros(UpgradeStep): - """ - Set the DISABLE_AUTONOFF macro to true for EMU or add it if not present. When this macro is true, + """Set the DISABLE_AUTONOFF macro to true for EMU or add it if not present. When this macro is true, settings will be displayed on the Danfysik OPI allowing automatic power turn on/off. """ diff --git a/src/upgrade_step_from_7p2p0.py b/src/upgrade_step_from_7p2p0.py index 6a74a44..65ad2c6 100644 --- a/src/upgrade_step_from_7p2p0.py +++ b/src/upgrade_step_from_7p2p0.py @@ -1,27 +1,25 @@ -import os -from src.upgrade_step import UpgradeStep -from src.common_upgrades.synoptics_and_device_screens import SynopticsAndDeviceScreens +from future.builtins import input + from src.common_upgrades.change_pvs_in_xml import ChangePVsInXML +from src.common_upgrades.synoptics_and_device_screens import SynopticsAndDeviceScreens from src.common_upgrades.utils.constants import MOTION_SET_POINTS_FOLDER from src.file_access import CachingFileAccess -from future.builtins import input +from src.upgrade_step import UpgradeStep ERROR_CODE = -1 SUCCESS_CODE = 0 class IgnoreRcpttSynoptics(UpgradeStep): - """ - Adds "rcptt_*" files to .gitignore, so that test synoptics are no longer committed. + """Adds "rcptt_*" files to .gitignore, so that test synoptics are no longer committed. """ file_name = ".gitignore" text_content = ["*.py[co]", "rcptt_*/", "rcptt_*", "*.swp", "*~", ".idea/", ".project/"] def perform(self, file_access, logger): - """ - Perform the upgrade step + """Perform the upgrade step Args: file_access (FileAccess): file access logger (LocalLogger): logger @@ -50,13 +48,11 @@ def perform(self, file_access, logger): class UpgradeMotionSetPoints(UpgradeStep): - """ - Changes blocks to point at renamed PVs. Warns about changed setup. + """Changes blocks to point at renamed PVs. Warns about changed setup. """ def perform(self, file_access, logger): - """ - Perform the upgrade step + """Perform the upgrade step Args: file_access (FileAccess): file access logger (LocalLogger): logger @@ -118,8 +114,7 @@ class ChangeReflOPITarget(UpgradeStep): REFL_OPI_TARGET_NEW = "Reflectometry OPI" def perform(self, file_access, logger): - """ - Perform the upgrade step + """Perform the upgrade step Args: file_access (FileAccess): file access logger (LocalLogger): logger diff --git a/src/upgrade_step_from_7p4p0.py b/src/upgrade_step_from_7p4p0.py index 4097e03..44ab68a 100644 --- a/src/upgrade_step_from_7p4p0.py +++ b/src/upgrade_step_from_7p4p0.py @@ -6,8 +6,7 @@ class SetISOBUSForILM200(UpgradeStep): - """ - Set the ILM200 ISOBUS value to None for IMAT as they are the first to not use ISOBUS on the ILM200. + """Set the ILM200 ISOBUS value to None for IMAT as they are the first to not use ISOBUS on the ILM200. """ def perform(self, file_access, logger): diff --git a/src/upgrade_step_from_9p0p0.py b/src/upgrade_step_from_9p0p0.py index 5bc87ba..99026af 100644 --- a/src/upgrade_step_from_9p0p0.py +++ b/src/upgrade_step_from_9p0p0.py @@ -1,10 +1,10 @@ import socket + from src.upgrade_step import UpgradeStep class ChangeLETCollimatorCmd(UpgradeStep): - """ - Change the LET/MERLIN collimator code to load in the new LET/MERLIN-specific db file. + """Change the LET/MERLIN collimator code to load in the new LET/MERLIN-specific db file. """ def perform(self, file_access, logger): @@ -26,8 +26,7 @@ def perform(self, file_access, logger): class RenameGalilMulCmd(UpgradeStep): - """ - Rename all galilmul1.cmd -> galilmul01.cmd + """Rename all galilmul1.cmd -> galilmul01.cmd """ def perform(self, file_access, logger): @@ -42,5 +41,5 @@ def perform(self, file_access, logger): ) return 0 - except Exception as e: + except Exception: pass diff --git a/src/upgrade_step_noop.py b/src/upgrade_step_noop.py index a262f70..259447c 100644 --- a/src/upgrade_step_noop.py +++ b/src/upgrade_step_noop.py @@ -1,16 +1,12 @@ from src.upgrade_step import UpgradeStep -from .file_access import FileAccess -from .local_logger import LocalLogger class UpgradeStepNoOp(UpgradeStep): - """ - An upgrade step that does nothing. This can be used to add a upgrade to the latest production version. + """An upgrade step that does nothing. This can be used to add a upgrade to the latest production version. """ def perform(self, file_access, logger): - """ - No nothing return sucess + """No nothing return sucess Args: file_access (FileAccess): file access diff --git a/test/mother.py b/test/mother.py index 634555c..a4c176d 100644 --- a/test/mother.py +++ b/test/mother.py @@ -1,13 +1,11 @@ -""" -Mother for test objects +"""Mother for test objects """ from xml.dom import minidom class LoggingStub(object): - """ - Stub for logging + """Stub for logging """ def __init__(self): @@ -23,8 +21,7 @@ def info(self, message): class FileAccessStub(object): - """ - Stub for file access + """Stub for file access """ SYNOPTIC_FILENAME = "synoptic_file" @@ -78,13 +75,11 @@ def get_synoptic_files(self): def create_xml_with_iocs(iocs): - """ - Args: + """Args: iocs (list): A list of IOC names Returns: str: xml containing the supplied IOCs """ - doc = minidom.Document() top = doc.createElement("iocs") for ioc in iocs: diff --git a/test/test_add_to_base_iocs.py b/test/test_add_to_base_iocs.py index 907602d..ab44a34 100644 --- a/test/test_add_to_base_iocs.py +++ b/test/test_add_to_base_iocs.py @@ -1,16 +1,16 @@ import unittest +from xml.parsers.expat import ExpatError + from hamcrest import * from mock import MagicMock as Mock -from xml.parsers.expat import ExpatError from src.common_upgrades.add_to_base_iocs import ( - AddToBaseIOCs, + ADD_AFTER_MISSING, ALREADY_CONTAINS, FILE_TO_CHECK_STR, - ADD_AFTER_MISSING, + AddToBaseIOCs, ) -from test.mother import LoggingStub, FileAccessStub, create_xml_with_iocs - +from test.mother import FileAccessStub, LoggingStub, create_xml_with_iocs TEST_XML_TO_ADD = """\ diff --git a/test/test_globals_macro_changing.py b/test/test_globals_macro_changing.py index d066a43..fbd84a7 100644 --- a/test/test_globals_macro_changing.py +++ b/test/test_globals_macro_changing.py @@ -1,10 +1,11 @@ import unittest + from hamcrest import assert_that + from src.common_upgrades.change_macro_in_globals import ChangeMacroInGlobals -from test.mother import LoggingStub, FileAccessStub, EXAMPLE_GLOBALS_FILE -import os -from src.common_upgrades.utils.macro import Macro from src.common_upgrades.utils.constants import GLOBALS_FILENAME +from src.common_upgrades.utils.macro import Macro +from test.mother import EXAMPLE_GLOBALS_FILE, FileAccessStub, LoggingStub class TestFindingIOC(unittest.TestCase): diff --git a/test/test_sql_utils.py b/test/test_sql_utils.py index 2054485..9e3a27c 100644 --- a/test/test_sql_utils.py +++ b/test/test_sql_utils.py @@ -1,8 +1,9 @@ import unittest -from mock import patch, MagicMock -from src.common_upgrades.sql_utilities import SqlConnection, run_sql import mysql.connector +from mock import MagicMock, patch + +from src.common_upgrades.sql_utilities import SqlConnection, run_sql class TestSQLUtils(unittest.TestCase): diff --git a/test/test_upgrade_base.py b/test/test_upgrade_base.py index 57f3e60..a1ba123 100644 --- a/test/test_upgrade_base.py +++ b/test/test_upgrade_base.py @@ -1,10 +1,11 @@ import unittest + from hamcrest import * from mock import MagicMock as Mock +from mother import FileAccessStub, LoggingStub from src.upgrade import Upgrade, UpgradeError from src.upgrade_step import UpgradeStep -from mother import LoggingStub, FileAccessStub class TestUpgradeBase(unittest.TestCase): @@ -161,7 +162,8 @@ def test_GIVEN_upgrade_step_failes_WHEN_upgrade_THEN_fail(self): assert_that(result, is_(expect_error_code), "Fail exit") def test_GIVEN_version_number_THEN_upgrade_check_works(self): - import upgrade, check_version + import check_version + import upgrade result_not_match = check_version.compare_version_number(upgrade.UPGRADE_STEPS[-2][0]) result_match = check_version.compare_version_number(upgrade.UPGRADE_STEPS[-1][0]) diff --git a/test/test_upgrade_step_check_init_inst.py b/test/test_upgrade_step_check_init_inst.py index 62f546f..3257b85 100644 --- a/test/test_upgrade_step_check_init_inst.py +++ b/test/test_upgrade_step_check_init_inst.py @@ -1,19 +1,19 @@ +import sys import unittest + from hamcrest import assert_that, equal_to, is_not -from mock import MagicMock, patch, mock_open -from mother import LoggingStub, FileAccessStub -from src.upgrade_step_check_init_inst import UpgradeStepCheckInitInst -import os +from mock import mock_open, patch +from mother import FileAccessStub, LoggingStub -import sys +from src.upgrade_step_check_init_inst import UpgradeStepCheckInitInst module_ = "builtins" module_ = module_ if module_ in sys.modules else "builtins" try: import unittest.mock as mock -except (ImportError,) as e: - import mock +except (ImportError,): + pass class TestUpgradeStepCheckInitInst(unittest.TestCase): diff --git a/test/test_upgrade_step_from_10p0p0.py b/test/test_upgrade_step_from_10p0p0.py index 5999023..4d098ea 100644 --- a/test/test_upgrade_step_from_10p0p0.py +++ b/test/test_upgrade_step_from_10p0p0.py @@ -1,6 +1,8 @@ import os import unittest -from mother import LoggingStub, FileAccessStub + +from mother import LoggingStub + from src.file_access import FileAccess from src.upgrade_step_from_10p0p0 import RemoveReflDeviceScreen diff --git a/test/test_upgrade_step_from_12p0p0.py b/test/test_upgrade_step_from_12p0p0.py index 368888d..37c7a39 100644 --- a/test/test_upgrade_step_from_12p0p0.py +++ b/test/test_upgrade_step_from_12p0p0.py @@ -1,7 +1,8 @@ import unittest -import mock +import mock from mother import FileAccessStub, LoggingStub + from src.upgrade_step_from_12p0p0 import UpgradeJawsForPositionAutosave diff --git a/test/test_upgrade_step_from_7p2p0.py b/test/test_upgrade_step_from_7p2p0.py index 38585c7..95a1801 100644 --- a/test/test_upgrade_step_from_7p2p0.py +++ b/test/test_upgrade_step_from_7p2p0.py @@ -1,10 +1,10 @@ -import os import unittest + from mock import MagicMock as Mock -from test.test_utils import test_changing_synoptics_and_blocks, test_action_does_not_write -from mother import LoggingStub, FileAccessStub +from mother import FileAccessStub, LoggingStub + from src.upgrade_step_from_7p2p0 import IgnoreRcpttSynoptics, UpgradeMotionSetPoints -from functools import partial +from test.test_utils import test_action_does_not_write, test_changing_synoptics_and_blocks class TestIgnoreRcpttSynoptics(unittest.TestCase): diff --git a/test/test_utils.py b/test/test_utils.py index 9603007..69a0824 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,4 +1,5 @@ from hamcrest import * + from src.common_upgrades.utils.constants import BLOCK_FILE BLOCK_NAMESPACE = "http://epics.isis.rl.ac.uk/schema/blocks/1.0" diff --git a/test/test_xml_macro_changer.py b/test/test_xml_macro_changer.py index 1fc3518..cd1bfa9 100644 --- a/test/test_xml_macro_changer.py +++ b/test/test_xml_macro_changer.py @@ -1,17 +1,18 @@ import unittest -from hamcrest import * +import xml.etree.ElementTree as ET from functools import partial +from xml.dom import minidom + +from hamcrest import * +from mock import MagicMock as Mock + from src.common_upgrades.change_macros_in_xml import ( ChangeMacrosInXML, change_macro_name, change_macro_value, ) from src.common_upgrades.utils.macro import Macro -from test.mother import LoggingStub, FileAccessStub, create_xml_with_iocs -from xml.dom import minidom -from mock import MagicMock as Mock -import xml.etree.ElementTree as ET - +from test.mother import FileAccessStub, LoggingStub, create_xml_with_iocs NAMESPACE = "http://epics.isis.rl.ac.uk/schema/iocs/1.0" @@ -390,8 +391,8 @@ def setUp(self): self.macro_changer = ChangeMacrosInXML(self.file_access, self.logger) def create_synoptic_file_with_multiple_IOCs(self, iocs): - """ - Mocks out a synoptic file with multiple IOCs in it. + """Mocks out a synoptic file with multiple IOCs in it. + Args: iocs: List of strings with the IOC names in it @@ -399,7 +400,6 @@ def create_synoptic_file_with_multiple_IOCs(self, iocs): formatted_synoptic_file: A mock XML document containing a sample synoptic """ - synoptics = "".join([SYOPTIC_XML.format(ioc) for ioc in iocs]) formatted_synoptic_file = SYNOPTIC_FILE_XML.format(synoptics=synoptics) diff --git a/test/test_xml_pv_changer.py b/test/test_xml_pv_changer.py index 4072c34..23ef2f2 100644 --- a/test/test_xml_pv_changer.py +++ b/test/test_xml_pv_changer.py @@ -1,7 +1,9 @@ import unittest + from hamcrest import * + from src.common_upgrades.change_pvs_in_xml import ChangePVsInXML -from test.mother import LoggingStub, FileAccessStub +from test.mother import FileAccessStub, LoggingStub from test.test_utils import create_xml_with_starting_blocks, test_changing_synoptics_and_blocks diff --git a/upgrade.py b/upgrade.py index 89869ae..945adc3 100644 --- a/upgrade.py +++ b/upgrade.py @@ -5,11 +5,12 @@ from src.git_utils import RepoFactory from src.local_logger import LocalLogger from src.upgrade import Upgrade +from src.upgrade_step_add_meta_tag import UpgradeStepAddMetaXmlElement from src.upgrade_step_from_6p0p0 import SetDanfysikDisableAutoonoffMacros from src.upgrade_step_from_7p2p0 import ( + ChangeReflOPITarget, IgnoreRcpttSynoptics, UpgradeMotionSetPoints, - ChangeReflOPITarget, ) from src.upgrade_step_from_7p4p0 import SetISOBUSForILM200 from src.upgrade_step_from_9p0p0 import ChangeLETCollimatorCmd @@ -20,8 +21,6 @@ from src.upgrade_step_from_12p0p2 import UpgradeFrom12p0p2 from src.upgrade_step_from_12p0p3 import UpgradeFrom12p0p3 from src.upgrade_step_noop import UpgradeStepNoOp -from src.upgrade_step_add_meta_tag import UpgradeStepAddMetaXmlElement - # A list of upgrade step tuples tuple is name of version to apply the upgrade to and upgrade class. # The last step should have an upgrade class of None (this is how it knows it has reached the end)