diff --git a/tests/cmdline/commands/test_computer.py b/tests/cmdline/commands/test_computer.py index fa2a1c6f24..00ade7b4e7 100644 --- a/tests/cmdline/commands/test_computer.py +++ b/tests/cmdline/commands/test_computer.py @@ -528,7 +528,6 @@ def test_computer_export_setup(self, tmp_path, sort): assert result.exit_code == 0, '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) @@ -536,6 +535,13 @@ def test_computer_export_setup(self, tmp_path, sort): comp ), 'Internal computer configuration does not agree with exported one.' + # we create a directory so we raise an error when exporting with the same name + # to test the except part of the function + already_existing_filename = tmp_path / 'tmp_dir' + os.mkdir(already_existing_filename) + result = self.cli_runner(computer_export_setup, [sort, comp.label, already_existing_filename], raises=True) + assert result.exit_code == ExitCode.CRITICAL + @pytest.mark.parametrize('sort', ['--sort', '--no-sort']) def test_computer_export_config(self, tmp_path, sort): """Test if 'verdi computer export config' command works""" @@ -556,7 +562,6 @@ def test_computer_export_config(self, tmp_path, sort): 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) @@ -564,6 +569,18 @@ def test_computer_export_config(self, tmp_path, sort): configure_config_data == comp.get_configuration() ), 'Internal computer configuration does not agree with exported one.' + # we create a directory so we raise an error when exporting with the same name + # to test the except part of the function + already_existing_filename = tmp_path / 'tmp_dir' + os.mkdir(already_existing_filename) + result = self.cli_runner(computer_export_config, [comp.label, already_existing_filename], raises=True) + assert result.exit_code == ExitCode.CRITICAL + + result = self.cli_runner( + computer_export_config, ['--user', self.user.email, comp.label, already_existing_filename], raises=True + ) + assert result.exit_code == ExitCode.CRITICAL + class TestVerdiComputerCommands: """Testing verdi computer commands.