From c241244fb40d796f42b626788820831005ca9faf Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Wed, 11 Sep 2024 15:46:52 +0200 Subject: [PATCH] Make copy_directories error message readable --- src/ert/resources/shell_scripts/copy_directory.py | 4 +++- tests/unit_tests/shared/share/test_shell.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ert/resources/shell_scripts/copy_directory.py b/src/ert/resources/shell_scripts/copy_directory.py index 05f441888b9..5a9ad6e3200 100755 --- a/src/ert/resources/shell_scripts/copy_directory.py +++ b/src/ert/resources/shell_scripts/copy_directory.py @@ -32,4 +32,6 @@ def copy_directory(src_path, target_path): try: copy_directory(src_path, target_path) except IOError as e: - sys.exit(f"COPY_DIRECTORY failed with the following error: {e}") + sys.exit( + f"COPY_DIRECTORY failed with the following error: {''.join(e.args[0])}" + ) diff --git a/tests/unit_tests/shared/share/test_shell.py b/tests/unit_tests/shared/share/test_shell.py index 9e832aedefd..ba2f34db497 100644 --- a/tests/unit_tests/shared/share/test_shell.py +++ b/tests/unit_tests/shared/share/test_shell.py @@ -400,6 +400,17 @@ def test_copy_directory_error(shell): assert b"existing directory" in shell.copy_directory("hei", "target").stderr + empty_dir = "emptytestdir" + if not os.path.exists(empty_dir): + os.makedirs(empty_dir) + + file_path = os.path.join(empty_dir, "file") + + with open(file_path, "w", encoding="utf-8") as f: + f.write("some_text") + + assert b"are the same" in shell.copy_directory(empty_dir, ".").stderr + @pytest.mark.usefixtures("use_tmpdir") def test_copy_file(shell):