From 7293289a1ae1ec02f16b291f61d5e3cbcd6579be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Val=C3=AD=C4=8Dek?= Date: Sun, 26 Jun 2022 01:15:44 +0200 Subject: [PATCH] Extend ConfigFileNotFoundError MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Václav Valíček --- repo_cloner/lib/config_file_not_found_error.py | 10 ++++++---- tests/lib/test_config_file_not_found.py | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/repo_cloner/lib/config_file_not_found_error.py b/repo_cloner/lib/config_file_not_found_error.py index f0bbb8d..e94c2af 100644 --- a/repo_cloner/lib/config_file_not_found_error.py +++ b/repo_cloner/lib/config_file_not_found_error.py @@ -5,16 +5,18 @@ import os class ConfigFileNotFoundError(OSError): def __str__(self): - if len(self.args) == 2: + if len(self.args) in [1, 2]: path: str = "" - filename: str = "" if isinstance(self.args[0], PosixPath): path = str(PosixPath(self.args[0])) else: path = str(self.args[0]) - filename = str(self.args[1]) - path = os.path.join(path, filename) + if len(self.args) == 2: + filename: str = "" + filename = str(self.args[1]) + path = os.path.join(path, filename) + return f"Config file does not exist: {path}" else: return super.__str__(self) diff --git a/tests/lib/test_config_file_not_found.py b/tests/lib/test_config_file_not_found.py index fab505b..ee2edae 100644 --- a/tests/lib/test_config_file_not_found.py +++ b/tests/lib/test_config_file_not_found.py @@ -14,9 +14,9 @@ def test_return(): def test_str_single_arg(): - x = ConfigFileNotFoundError("/tmp") + x = ConfigFileNotFoundError("/tmp/cfg.cfg") s = x.__str__() - assert s == "ConfigFileNotFoundError('/tmp')" + assert s == "Config file does not exist: /tmp/cfg.cfg" def test_return_empty():