diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 0000000..7637f2b --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,3 @@ +{ + "ignore": ["./src/ibex_device_generator/templates"] +} diff --git a/ruff.toml b/ruff.toml index 80086bb..7df4b5b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,33 +1,74 @@ -# Exclude templates +# Exclude a variety of commonly ignored directories. exclude = [ - "templates", + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", + "uk.ac.stfc.isis.ibex.opis", + "ReflectometryServer/test_modules/test_config/", + "src/ibex_device_generator/templates/6/", + "src/ibex_device_generator/templates/7/" ] -# Set the maximum line length to 79. -line-length = 79 +# Set the maximum line length to 100. +line-length = 100 +indent-width = 4 [lint] extend-select = [ "N", # pep8-naming - "D", # pydocstyle + # "D", # pydocstyle (can use this later but for now causes too many errors) "I", # isort (for imports) "E501", # Line too long ({width} > {limit}) - "ANN001", # Missing type annotation for function argument {name} - "ANN201", # Missing return type annotation for public function {name} - "ANN202", # Missing return type annotation for private function {name} - "ANN204", # Missing return type annotation for special method {name} - "ANN205", # Missing return type annotation for staticmethod {name} - "ANN206", # Missing return type annotation for classmethod {name} + "E", + "F", + "ANN", ] ignore = [ - "D203", # 1 blank line required before class docstring - "D213", # Multi-line docstring summary should start at the second line "D406", # Section name should end with a newline ("{name}") "D407", # Missing dashed underline after section ("{name}") + "N999", # Ignore this because the repo itself would need to be renamed + "ANN101", # ignore this until its removed in future versions + "ANN102", # ignore this until its removed in future versions ] +[lint.per-file-ignores] +"{**/tests/**,/tests/**,**/*tests.py,tests/**,*tests.py,*test.py,**/*test.py,common_tests/**,test_*.py}" = [ + "N802", + "D100", + "D101", + "D102", + "E501", + "ANN", +] + +[lint.pydocstyle] +# Use Google-style docstrings. +convention = "google" [format] quote-style = "double" indent-style = "space" docstring-code-format = true -line-ending = "cr-lf" \ No newline at end of file +line-ending = "auto" diff --git a/src/ibex_device_generator/cli.py b/src/ibex_device_generator/cli.py index 1602cb1..c45c3a0 100644 --- a/src/ibex_device_generator/cli.py +++ b/src/ibex_device_generator/cli.py @@ -11,7 +11,7 @@ from ibex_device_generator.utils.device_info import DeviceInfo -def _configure_logging(level: str = logging.INFO) -> None: +def _configure_logging(level: str = str(logging.INFO)) -> None: logging.basicConfig( level=level, format="%(message)s", @@ -26,9 +26,7 @@ def main() -> None: _configure_logging(level=args.log_level) - device = DeviceInfo( - args.ioc_name, args.device_name, device_count=args.device_count - ) + device = DeviceInfo(args.ioc_name, args.device_name, device_count=args.device_count) IBEXDeviceGenerator( device, args.use_git, args.github_token, args.ticket, args.interactive diff --git a/src/ibex_device_generator/exc.py b/src/ibex_device_generator/exc.py index 6526590..abb9ee4 100644 --- a/src/ibex_device_generator/exc.py +++ b/src/ibex_device_generator/exc.py @@ -89,8 +89,7 @@ def __init__(self, name: str) -> None: def __str__(self) -> str: return ( - "'%s' is an invalid device name," - " it can only cantain ASCII characters." % self.name + "'%s' is an invalid device name," " it can only cantain ASCII characters." % self.name ) @@ -101,10 +100,7 @@ def __init__(self, count: int) -> None: self.count = count def __str__(self) -> str: - return ( - "'%d' is an invalid device count. This must be between 1 and 99." - % self.count - ) + return "'%d' is an invalid device count. This must be between 1 and 99." % self.count class ReassignPlaceholderError(IBEXDeviceGeneratorError): @@ -114,10 +110,7 @@ def __init__(self, placeholder: str) -> None: self.placeholder = placeholder def __str__(self) -> str: - return ( - "Cannot reassign value of '%s' after device info instantiation." - % self.placeholder - ) + return "Cannot reassign value of '%s' after device info instantiation." % self.placeholder # Git related @@ -131,8 +124,7 @@ def __init__(self, path: str) -> None: def __str__(self) -> str: return ( - "Cannot open git repository at %s." - " Check if git repo exists at location." % self.path + "Cannot open git repository at %s." " Check if git repo exists at location." % self.path ) diff --git a/src/ibex_device_generator/ibex_device_generator.py b/src/ibex_device_generator/ibex_device_generator.py index fdd6e13..9258bf0 100644 --- a/src/ibex_device_generator/ibex_device_generator.py +++ b/src/ibex_device_generator/ibex_device_generator.py @@ -1,6 +1,7 @@ """Main file.""" import logging +from typing import Callable, ParamSpec from rich.prompt import Confirm @@ -25,6 +26,8 @@ create_submodule_structure, ) +P = ParamSpec("P") + class IBEXDeviceGenerator: """IBEX device generator.""" @@ -121,11 +124,11 @@ def run(self) -> None: def add_step( self, - repo_path: str, + repo_path: str | None, commit_msg: str, - action: callable, - *args, - **kwargs, + action: Callable[P, None], + *args: P.args, + **kwargs: P.kwargs, ) -> None: """Add a generator step. @@ -137,15 +140,11 @@ def add_step( commit_msg: the commit message action: the function to execute as this step *args: any positional arguments for the action - **kwargs: any keywoprd arguments for the action + **kwargs: any keyword arguments for the action """ - if self.interactive and not Confirm.ask( - f"Do '{commit_msg}'?", default="y" - ): - logging.debug( - ":right_arrow: Skipping step.", extra={"markup": True} - ) + if self.interactive and not Confirm.ask(f"Do '{commit_msg}'?", default="y"): + logging.debug(":right_arrow: Skipping step.", extra={"markup": True}) return try: @@ -157,9 +156,7 @@ def add_step( with commit_changes(repo_path, self.ticket_branch, commit_msg): action(*args, **kwargs) else: - logging.info( - f"Running '{commit_msg}'...", extra={"highlighter": None} - ) + logging.info(f"Running '{commit_msg}'...", extra={"highlighter": None}) action(*args, **kwargs) logging.info( diff --git a/src/ibex_device_generator/utils/arg_parser.py b/src/ibex_device_generator/utils/arg_parser.py index 122b038..092c81a 100644 --- a/src/ibex_device_generator/utils/arg_parser.py +++ b/src/ibex_device_generator/utils/arg_parser.py @@ -23,8 +23,7 @@ def parse_arguments() -> Namespace: """Parse cli arguments.""" parser = argparse.ArgumentParser( description=( - "IBEX Device IOC Generator. " - "Generate boilerplate code for IBEX device support." + "IBEX Device IOC Generator. " "Generate boilerplate code for IBEX device support." ), ) parser.add_argument( @@ -68,10 +67,7 @@ def parse_arguments() -> Namespace: parser.add_argument( "--github_token", type=str, - help=( - 'GitHub token with "repo" scope. ' - "Use to create support repository." - ), + help=('GitHub token with "repo" scope. ' "Use to create support repository."), ) parser.add_argument( "--log_level", @@ -124,7 +120,5 @@ def ticket_number_checker(val: str) -> int: """Check ticket number validity.""" ticket_number = int(val) if not does_github_issue_exist_and_is_open(ticket_number): - raise ArgumentTypeError( - f"GitHub issue {ticket_number} is closed or does not exist." - ) + raise ArgumentTypeError(f"GitHub issue {ticket_number} is closed or does not exist.") return ticket_number diff --git a/src/ibex_device_generator/utils/command.py b/src/ibex_device_generator/utils/command.py index d04a4af..d6ea8d6 100644 --- a/src/ibex_device_generator/utils/command.py +++ b/src/ibex_device_generator/utils/command.py @@ -12,7 +12,8 @@ def run_command( - command: StrOrBytesPath | Sequence[StrOrBytesPath], working_dir: str + command: StrOrBytesPath | Sequence[StrOrBytesPath], + working_dir: str | PathLike, ) -> int: """Run a command using subprocess, waits for completion. @@ -24,9 +25,12 @@ def run_command( The exit code after running the command """ - logging.info( - "Running command {} from {}".format(" ".join(command), working_dir) - ) + if type(command) is Sequence: + logging.info( + "Running command {} from {}".format(" ".join([str(c) for c in command]), working_dir) + ) + else: + logging.info("Running command {} from {}".format(command, working_dir)) with open(devnull, "w") as null_out: cmd = subprocess.Popen( command, diff --git a/src/ibex_device_generator/utils/device_info.py b/src/ibex_device_generator/utils/device_info.py index d65e907..7880845 100644 --- a/src/ibex_device_generator/utils/device_info.py +++ b/src/ibex_device_generator/utils/device_info.py @@ -79,7 +79,7 @@ def __init__( self[p.INDEX] = "01" # noqa # fmt: on - def __setitem__(self, key: Any, value: Any) -> None: + def __setitem__(self, key: Any, value: Any) -> None: # noqa - need to use any to fully overload """Disable value reassignment.""" if self.get(key) and key not in DeviceInfo.editable_substitutions: # Prevent modifying values other than INDEX @@ -101,7 +101,7 @@ def ioc_indexed_name(self, index: int) -> str: if not 0 < index < 100: raise InvalidDeviceCountError(index) - return "{}-IOC-{:02d}".format(self._ioc_name, index) + return "{}-IOC-{:02d}".format(self[p.IOC_NAME], index) def ioc_boot_path(self, index: int) -> str: """Get IOCs indexed booth path. diff --git a/src/ibex_device_generator/utils/file_system.py b/src/ibex_device_generator/utils/file_system.py index b26c880..fcc2e1d 100644 --- a/src/ibex_device_generator/utils/file_system.py +++ b/src/ibex_device_generator/utils/file_system.py @@ -4,8 +4,8 @@ from os.path import join -def _add_entry_to_list(text: str, list_name: str, entry: str) -> str: - """Add entry to prefixed list in llist of strings. +def _add_entry_to_list(text: list[str], list_name: str, entry: str) -> list[str]: + """Add entry to prefixed list in list of strings. Check if 'list_name += entry' already exists in text and add it if not. @@ -51,9 +51,7 @@ def add_to_makefile_list(directory: str, list_name: str, entry: str) -> bool: """ logging.info( - "Adding {} to list {} in Makefile for directory {}".format( - entry, list_name, directory - ) + "Adding {} to list {} in Makefile for directory {}".format(entry, list_name, directory) ) makefile = join(directory, "Makefile") with open(makefile) as f: @@ -63,10 +61,7 @@ def add_to_makefile_list(directory: str, list_name: str, entry: str) -> bool: if old_lines == new_lines: logging.warn( - ( - f"Entry '{entry}' is already added to list '{list_name}' in" - f" '{makefile}'." - ) + (f"Entry '{entry}' is already added to list '{list_name}' in" f" '{makefile}'.") ) return False diff --git a/src/ibex_device_generator/utils/git_utils.py b/src/ibex_device_generator/utils/git_utils.py index 93fa174..ef0c9a8 100644 --- a/src/ibex_device_generator/utils/git_utils.py +++ b/src/ibex_device_generator/utils/git_utils.py @@ -8,7 +8,7 @@ import subprocess from contextlib import contextmanager from os.path import relpath -from typing import Generator +from typing import Any, Generator from git import ( GitCommandError, @@ -31,8 +31,8 @@ def __init__( self, path: str, init: bool = False, - *args, - **kwargs, + *args: Any, # noqa: ANN401 + **kwargs: Any, # noqa: ANN401 ) -> None: """Attach to existing git repository or initialise a new. @@ -50,13 +50,13 @@ def __init__( """ try: - super().__init__(path, *args, **kwargs) + super().__init__(path=path, *args, **kwargs) except (InvalidGitRepositoryError, NoSuchPathError): # This might be overkill for our use case but here we go if init: os.makedirs(os.path.dirname(path), exist_ok=True) self.init(path, initial_branch="main") - super().__init__(path, *args, **kwargs) + super().__init__(path=path, *args, **kwargs) else: raise CannotOpenRepoError(path) @@ -77,9 +77,7 @@ def switch(self, branch: str = "main") -> None: """ try: - logging.info( - f"Switching to branch '{branch}' in {self.working_dir}" - ) + logging.info(f"Switching to branch '{branch}' in {self.working_dir}") if str(branch) == self.active_branch_or_none: logging.info(f"Already on branch '{branch}'") return @@ -92,7 +90,7 @@ def switch(self, branch: str = "main") -> None: self.git.checkout("-b", branch) except GitCommandError as e: - raise FailedToSwitchBranchError(self, branch, e) + raise FailedToSwitchBranchError(self, branch, str(e)) def commit_all(self, msg: str) -> None: """Commit all changes and untracked files in the repository. @@ -102,10 +100,7 @@ def commit_all(self, msg: str) -> None: """ logging.info( - ( - f"Committing all changes and untracked files in" - f" '{self.working_tree_dir}'." - ) + (f"Committing all changes and untracked files in" f" '{self.working_tree_dir}'.") ) if self.is_dirty(untracked_files=True): @@ -116,7 +111,7 @@ def commit_all(self, msg: str) -> None: else: raise NothingToCommitError(self) - def create_submodule(self, name: str, url: str, path: str) -> None: + def create_submodule(self, name: str, url: str, path: str) -> None: # pyright: ignore """Create submodule in this repository. Args: @@ -133,9 +128,7 @@ def create_submodule(self, name: str, url: str, path: str) -> None: # /refs/heads/ prefix to any branch you give it, # and this breaks the repo checks. - cmd = ( - f"git submodule add -b {branch} --name {name} {url} {sub_path}" - ) + cmd = f"git submodule add -b {branch} --name {name} {url} {sub_path}" subprocess.run( cmd, cwd=self.working_tree_dir, @@ -143,16 +136,11 @@ def create_submodule(self, name: str, url: str, path: str) -> None: ) except subprocess.CalledProcessError as e: - logging.error( - "Cannot add {} as a submodule, error: {}".format(path, e) - ) + logging.error("Cannot add {} as a submodule, error: {}".format(path, e)) raise e except Exception as e: raise RuntimeError( - ( - f"Unknown error {e} of type {type(e)} whilst" - f" creating submodule in {path}" - ) + (f"Unknown error {e} of type {type(e)} whilst" f" creating submodule in {path}") ) @@ -195,10 +183,7 @@ def commit_changes( # updated their submodules. logging.warning( - ( - f"Git HEAD is detached in {repo.working_tree_dir}." - " Treating this as OK." - ) + (f"Git HEAD is detached in {repo.working_tree_dir}." " Treating this as OK.") ) repo.switch(branch) diff --git a/src/ibex_device_generator/utils/github.py b/src/ibex_device_generator/utils/github.py index 2d7b3b6..b70dd9d 100644 --- a/src/ibex_device_generator/utils/github.py +++ b/src/ibex_device_generator/utils/github.py @@ -42,12 +42,7 @@ def create_github_repository(device: DeviceInfo, github_token: str) -> None: ) if response.status_code == requests.codes["created"]: - logging.info( - ( - f"Repository {response.json().get('html_url')}" - " created successfully." - ) - ) + logging.info((f"Repository {response.json().get('html_url')}" " created successfully.")) else: raise FailedToCreateGitHubRepositoryError( ORGANIZATION_NAME, device[GITHUB_REPO_NAME], response.reason @@ -83,14 +78,10 @@ def grant_permission( ) ) else: - raise FailedToGrantPermissionError( - permission, repository_name, response.reason - ) + raise FailedToGrantPermissionError(permission, repository_name, response.reason) -def grant_permissions_for_github_repository( - device: DeviceInfo, github_token: str -) -> None: +def grant_permissions_for_github_repository(device: DeviceInfo, github_token: str) -> None: """Grant permissions to teams for the GitHub repository. Args: @@ -131,9 +122,7 @@ def does_github_issue_exist_and_is_open(issue_number: int) -> bool: return result.ok and result.json()["state"] == "open" -def github_repo_url( - repo_name: str, organisation: str = ORGANIZATION_NAME -) -> str: +def github_repo_url(repo_name: str, organisation: str = ORGANIZATION_NAME) -> str: """Get repo url for repo of the organisation. Args: diff --git a/src/ibex_device_generator/utils/gui.py b/src/ibex_device_generator/utils/gui.py index aca6c4d..5e4db25 100644 --- a/src/ibex_device_generator/utils/gui.py +++ b/src/ibex_device_generator/utils/gui.py @@ -3,7 +3,7 @@ import logging import os -from lxml import etree +import lxml.etree as etree from lxml.etree import ElementTree from ibex_device_generator.exc import IBEXDeviceGeneratorError @@ -60,13 +60,9 @@ def _generate_opi_entry(device: DeviceInfo) -> ElementTree: ElementTree template based on the device info """ - concrete_opi_xml_str = DeviceTemplate(template_opi_entry_xml_str).apply( - device - ) + concrete_opi_xml_str = DeviceTemplate(template_opi_entry_xml_str).apply(device) - return etree.fromstring( - concrete_opi_xml_str, etree.XMLParser(remove_blank_text=True) - ) + return etree.fromstring(concrete_opi_xml_str, etree.XMLParser(remove_blank_text=True)) def add_device_opi_to_opi_info(device: DeviceInfo) -> None: diff --git a/src/ibex_device_generator/utils/rich_utils.py b/src/ibex_device_generator/utils/rich_utils.py index cc78cd9..29f14a1 100644 --- a/src/ibex_device_generator/utils/rich_utils.py +++ b/src/ibex_device_generator/utils/rich_utils.py @@ -2,13 +2,12 @@ import os from os import PathLike -from typing import Any from rich.console import Console from rich.tree import Tree -def rich_print(*objects: Any) -> str: +def rich_print(*objects: Tree) -> str: """...""" console = Console() with console.capture() as capture: @@ -18,7 +17,7 @@ def rich_print(*objects: Any) -> str: # TODO suggest a function to rich public # something like -def tree_from_paths(paths: list[PathLike]) -> Tree: +def tree_from_paths(paths: list[PathLike] | list[str]) -> Tree: """...""" root = os.path.commonpath([os.path.dirname(path) for path in paths]) diff --git a/src/ibex_device_generator/utils/step.py b/src/ibex_device_generator/utils/step.py index 2a4d070..9897567 100644 --- a/src/ibex_device_generator/utils/step.py +++ b/src/ibex_device_generator/utils/step.py @@ -48,11 +48,7 @@ def create_submodule(device: DeviceInfo) -> None: log_file_changes( added_files=added_files, - modified_files=( - [os.path.join(EPICS_SUPPORT, "Makefile")] - if did_modify_makefile - else [] - ), + modified_files=([os.path.join(EPICS_SUPPORT, "Makefile")] if did_modify_makefile else []), ) @@ -79,17 +75,11 @@ def create_ioc_from_template(device: DeviceInfo) -> None: subs = device subs[p.INDEX] = "{:02d}".format(i) - added_files.extend( - populate_template_dir(get_template("5_2"), EPICS, subs) - ) + added_files.extend(populate_template_dir(get_template("5_2"), EPICS, subs)) # Add IOC to Makefile - did_modify_makefile = add_to_makefile_list( - IOC_ROOT, "IOCDIRS", device[p.IOC_NAME] - ) - modified_files = ( - [os.path.join(IOC_ROOT, "Makefile")] if did_modify_makefile else [] - ) + did_modify_makefile = add_to_makefile_list(IOC_ROOT, "IOCDIRS", device[p.IOC_NAME]) + modified_files = [os.path.join(IOC_ROOT, "Makefile")] if did_modify_makefile else [] # Run make try: @@ -130,16 +120,16 @@ def add_opi_to_gui(device: DeviceInfo) -> None: def log_file_changes( - added_files: list[PathLike] = [], - modified_files: list[PathLike] = [], - removed_files: list[PathLike] = [], + added_files: list[PathLike] | list[str] = [], + modified_files: list[PathLike] | list[str] = [], + removed_files: list[PathLike] | list[str] = [], ) -> None: """Print file trees to the user.""" if added_files: logging.info( "[green]Added the following files:\n" + rich_print( - tree_from_paths(sorted(added_files, key=str.lower)), + tree_from_paths(sorted([str(f) for f in added_files], key=str.lower)), ), extra={"markup": True, "highlighter": None}, ) @@ -147,7 +137,7 @@ def log_file_changes( logging.info( "[yellow]Modified the following files:\n" + rich_print( - tree_from_paths(sorted(modified_files, key=str.lower)), + tree_from_paths(sorted([str(f) for f in modified_files], key=str.lower)), ), extra={"markup": True, "highlighter": None}, ) @@ -155,7 +145,7 @@ def log_file_changes( logging.info( "[red]Removed the following files:\n" + rich_print( - tree_from_paths(sorted(removed_files, key=str.lower)), + tree_from_paths(sorted([str(f) for f in removed_files], key=str.lower)), ), extra={"markup": True, "highlighter": None}, ) diff --git a/src/ibex_device_generator/utils/templates.py b/src/ibex_device_generator/utils/templates.py index c631062..7416dc8 100644 --- a/src/ibex_device_generator/utils/templates.py +++ b/src/ibex_device_generator/utils/templates.py @@ -49,8 +49,8 @@ def get_template(*pathsegments: str) -> Traversable: def populate_template_file( - template: Traversable, into: PathLike, substitutions: dict[str, str] -) -> PathLike: + template: Traversable, into: PathLike | str, substitutions: dict[str, str] +) -> PathLike | str: """Populate a single template file into a directory on the disk. Args: @@ -74,25 +74,20 @@ def populate_template_file( ) logging.debug( - ( - f"Using template file '{template}'\n" - f"to populate '{substituted_destination}'" - ) + (f"Using template file '{template}'\n" f"to populate '{substituted_destination}'") ) os.makedirs(os.path.dirname(substituted_destination), exist_ok=True) with open(substituted_destination, "w") as file: - substituted_content = DeviceTemplate(template.read_text()).substitute( - substitutions - ) + substituted_content = DeviceTemplate(template.read_text()).substitute(substitutions) file.write(substituted_content) return substituted_destination def populate_template_dir( - template: Traversable, into: PathLike, substitutions: dict[str, str] + template: Traversable, into: PathLike | str, substitutions: dict[str, str] ) -> list[PathLike]: """Populate a template directory into a location on the disk. @@ -129,9 +124,5 @@ def populate_template_dir( substituted_destination = os.path.join( into, DeviceTemplate(item.name).substitute(substitutions) ) - files.extend( - populate_template_dir( - item, substituted_destination, substitutions - ) - ) + files.extend(populate_template_dir(item, substituted_destination, substitutions)) return files diff --git a/tests/test_device_info.py b/tests/test_device_info.py index 8b80164..3b166b9 100644 --- a/tests/test_device_info.py +++ b/tests/test_device_info.py @@ -33,10 +33,7 @@ def test_all_keys_present_in_device_info_substitutions(self) -> None: self.assertIn( value, self.device, - msg=( - f"Key '{name}' ('{value}') is missing from the" - " device info substitutions." - ), + msg=(f"Key '{name}' ('{value}') is missing from the" " device info substitutions."), ) # <- Check all keys in device info substitutions exists # in substitution_keys @@ -61,9 +58,7 @@ def test_device_info_substitutions_are_correct(self) -> None: p.DEVICE_PROTOCOL_NAME: "new_device_1", p.LEWIS_DEVICE_CLASS_NAME: "NewDevice1", p.SUPPORT_PATH: join(EPICS_SUPPORT, "new_device_1"), - p.SUPPORT_MASTER_PATH: join( - EPICS_SUPPORT, "new_device_1", "master" - ), + p.SUPPORT_MASTER_PATH: join(EPICS_SUPPORT, "new_device_1", "master"), p.GITHUB_REPO_NAME: "EPICS-New_Device_1", p.DEVICE_COUNT: 4, p.IOC_PATH: join(EPICS, "ioc", "master", "ND1"), diff --git a/tests/test_file_system_utils.py b/tests/test_file_system_utils.py index e147baa..d35f7a9 100644 --- a/tests/test_file_system_utils.py +++ b/tests/test_file_system_utils.py @@ -18,14 +18,10 @@ def test_GIVEN_entry_and_list_name_WHEN_add_entry_to_list_text_THEN_entry_is_add ] # Act - actual_output = _add_entry_to_list( - iocdirs_input, list_name, device_name - ) + actual_output = _add_entry_to_list(iocdirs_input, list_name, device_name) # Assert - self.assertEqual( - "{} += {}\n".format(list_name, device_name), actual_output[1] - ) + self.assertEqual("{} += {}\n".format(list_name, device_name), actual_output[1]) def test_GIVEN_entry_list_name_and_realistic_make_text_WHEN_add_entry_to_list_text_THEN_entry_exists_in_list_text( self, @@ -49,9 +45,7 @@ def test_GIVEN_entry_list_name_and_realistic_make_text_WHEN_add_entry_to_list_te iocdirs_input = [line.format(list_name) for line in iocdirs_input] # Act - actual_output = _add_entry_to_list( - iocdirs_input, list_name, device_name - ) + actual_output = _add_entry_to_list(iocdirs_input, list_name, device_name) # Assert self.assertTrue(any([device_name in line for line in actual_output])) @@ -78,9 +72,7 @@ def test_GIVEN_entry_list_name_exists_and_realistic_make_text_WHEN_add_entry_to_ iocdirs_input = [line.format(list_name) for line in iocdirs_input] # Act - actual_output = _add_entry_to_list( - iocdirs_input, list_name, device_name - ) + actual_output = _add_entry_to_list(iocdirs_input, list_name, device_name) # Assert self.assertEqual(iocdirs_input, actual_output) diff --git a/tests/test_git_utils.py b/tests/test_git_utils.py index 7e03d7e..0d41495 100644 --- a/tests/test_git_utils.py +++ b/tests/test_git_utils.py @@ -19,12 +19,7 @@ def test_repo_can_init_in_git_directory(self): try: RepoWrapper(tmpdir) except CannotOpenRepoError: - self.fail( - ( - "Repo should be able to initialise in a git tracked" - " directory." - ) - ) + self.fail(("Repo should be able to initialise in a git tracked" " directory.")) def test_repo_fails_to_init_in_non_git_directory(self): with TemporaryDirectory() as tmpdir: diff --git a/tests/test_placeholders.py b/tests/test_placeholders.py index d3c169b..8c2f747 100644 --- a/tests/test_placeholders.py +++ b/tests/test_placeholders.py @@ -21,21 +21,12 @@ def setUp(self) -> None: def test_all_placeholders_in_templates_are_present(self) -> None: """Check templates directory for unknown placeholder.""" with TemporaryDirectory() as tmpdir: - substitutions = { - key: "value" for key in self.placeholders.values() - } + substitutions = {key: "value" for key in self.placeholders.values()} try: - populate_template_dir( - get_template(), join(gettempdir(), tmpdir), substitutions - ) + populate_template_dir(get_template(), join(gettempdir(), tmpdir), substitutions) except KeyError as e: - self.fail( - ( - "There is an undefined placeholder in the" - f" templates directory: {e}" - ) - ) + self.fail(("There is an undefined placeholder in the" f" templates directory: {e}")) def get_placeholders() -> dict[str, str]: @@ -47,8 +38,6 @@ def get_placeholders() -> dict[str, str]: """ placeholders = { - name: value - for (name, value) in vars(keys_file).items() - if not name.startswith("__") + name: value for (name, value) in vars(keys_file).items() if not name.startswith("__") } return placeholders