From 92fe8e31605ce8448f4cfe778a95f3a0adeab899 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 May 2024 05:56:55 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/aiida/cmdline/commands/cmd_computer.py | 12 +++--- tests/cmdline/commands/test_computer.py | 43 ++++++++++++++-------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/aiida/cmdline/commands/cmd_computer.py b/src/aiida/cmdline/commands/cmd_computer.py index 5ca3183982..f6af67d1b7 100644 --- a/src/aiida/cmdline/commands/cmd_computer.py +++ b/src/aiida/cmdline/commands/cmd_computer.py @@ -744,6 +744,7 @@ def computer_export(): def computer_export_setup(computer, output_file): """Export computer setup to a yaml file.""" import yaml + computer_setup_data = { 'label': computer.label, 'description': computer.description, @@ -757,7 +758,7 @@ def computer_export_setup(computer, output_file): 'default_memory_per_machine': computer.get_default_memory_per_machine(), 'prepend_text': computer.get_prepend_text(), 'append_text': computer.get_append_text(), - 'use_double_quotes': computer.get_use_double_quotes() + 'use_double_quotes': computer.get_use_double_quotes(), } try: with open(output_file, 'w', encoding='utf-8') as yfhandle: @@ -774,11 +775,12 @@ def computer_export_setup(computer, output_file): def computer_export_config(computer, output_file): """Export computer configuration to a yaml file.""" import yaml - from aiida import orm - from aiida.transports import cli as transport_cli + if not computer.is_configured: - echo.echo_error(f"Computer<{computer.pk}> {computer.label} config cannot be exported, because computer has not been configured yet.") + echo.echo_error( + f'Computer<{computer.pk}> {computer.label} config cannot be exported, because computer has not been configured yet.' + ) else: computer_config_data = computer.get_configuration() try: @@ -786,4 +788,4 @@ def computer_export_config(computer, output_file): yaml.dump(computer_config_data, yfhandle) echo.echo_success(f"Computer<{computer.pk}> {computer.label} config exported to file '{output_file}'.") except Exception: - raise \ No newline at end of file + raise diff --git a/tests/cmdline/commands/test_computer.py b/tests/cmdline/commands/test_computer.py index 2a2ec73a28..539261f1d6 100644 --- a/tests/cmdline/commands/test_computer.py +++ b/tests/cmdline/commands/test_computer.py @@ -12,20 +12,20 @@ import tempfile import textwrap from collections import OrderedDict -import yaml import pytest +import yaml from aiida import orm from aiida.cmdline.commands.cmd_computer import ( computer_configure, computer_delete, computer_duplicate, + computer_export_config, + computer_export_setup, computer_list, computer_relabel, computer_setup, computer_show, - computer_export_setup, - computer_export_config, computer_test, ) @@ -521,17 +521,23 @@ def test_computer_export_setup(self): comp = self.comp_builder.new() comp.store() - exported_setup_filename = "computer-setup.yml" + exported_setup_filename = 'computer-setup.yml' try: result = self.cli_runner(computer_export_setup, [comp.label, exported_setup_filename]) - assert f"Success" in result.output, "Command should have run successfull." - assert f"{exported_setup_filename}" in result.output, "Filename should be in terminal output but was not found." - assert os.path.exists(exported_setup_filename), f"'{exported_setup_filename}' was not created during export." + assert 'Success' in result.output, 'Command should have run successfull.' + assert ( + f'{exported_setup_filename}' in result.output + ), 'Filename should be in terminal output but was not found.' + assert os.path.exists( + exported_setup_filename + ), f"'{exported_setup_filename}' was not created during export." # verifying correctness by comparing internal and loaded yml object with open(exported_setup_filename, 'r', encoding='utf-8') as yfhandle: configure_setup_data = yaml.safe_load(yfhandle) - assert configure_setup_data == self.comp_builder.get_computer_spec(comp), "Internal computer configuration does not agree with exported one." + assert configure_setup_data == self.comp_builder.get_computer_spec( + comp + ), 'Internal computer configuration does not agree with exported one.' except Exception: raise finally: @@ -545,27 +551,34 @@ def test_computer_export_config(self): comp = self.comp_builder.new() comp.store() - exported_config_filename = "computer-configure.yml" + exported_config_filename = 'computer-configure.yml' try: result = self.cli_runner(computer_export_config, [comp.label, exported_config_filename]) - assert f"Error" in result.output, "Command should have raised an error." + assert 'Error' in result.output, 'Command should have raised an error.' - comp.configure(safe_interval=0.) + comp.configure(safe_interval=0.0) result = self.cli_runner(computer_export_config, [comp.label, exported_config_filename]) - assert f"Success" in result.output, "Command should have run successfull." - assert f"{exported_config_filename}" in result.output, "Filename should be in terminal output but was not found." - assert os.path.exists(exported_config_filename), f"'{exported_config_filename}' was not created during export." + assert 'Success' in result.output, 'Command should have run successfull.' + assert ( + f'{exported_config_filename}' in result.output + ), 'Filename should be in terminal output but was not found.' + assert os.path.exists( + exported_config_filename + ), f"'{exported_config_filename}' was not created during export." # verifying correctness by comparing internal and loaded yml object with open(exported_config_filename, 'r', encoding='utf-8') as yfhandle: configure_config_data = yaml.safe_load(yfhandle) - assert configure_config_data == comp.get_configuration(), "Internal computer configuration does not agree with exported one." + assert ( + configure_config_data == comp.get_configuration() + ), 'Internal computer configuration does not agree with exported one.' except Exception: raise finally: if os.path.exists(exported_config_filename): os.remove(exported_config_filename) + class TestVerdiComputerCommands: """Testing verdi computer commands.