Extend ConfigFileNotFoundError
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
parent
97054b4fcc
commit
7293289a1a
|
@ -5,16 +5,18 @@ import os
|
||||||
class ConfigFileNotFoundError(OSError):
|
class ConfigFileNotFoundError(OSError):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if len(self.args) == 2:
|
if len(self.args) in [1, 2]:
|
||||||
path: str = ""
|
path: str = ""
|
||||||
filename: str = ""
|
|
||||||
if isinstance(self.args[0], PosixPath):
|
if isinstance(self.args[0], PosixPath):
|
||||||
path = str(PosixPath(self.args[0]))
|
path = str(PosixPath(self.args[0]))
|
||||||
else:
|
else:
|
||||||
path = str(self.args[0])
|
path = str(self.args[0])
|
||||||
|
|
||||||
filename = str(self.args[1])
|
if len(self.args) == 2:
|
||||||
path = os.path.join(path, filename)
|
filename: str = ""
|
||||||
|
filename = str(self.args[1])
|
||||||
|
path = os.path.join(path, filename)
|
||||||
|
|
||||||
return f"Config file does not exist: {path}"
|
return f"Config file does not exist: {path}"
|
||||||
else:
|
else:
|
||||||
return super.__str__(self)
|
return super.__str__(self)
|
||||||
|
|
|
@ -14,9 +14,9 @@ def test_return():
|
||||||
|
|
||||||
|
|
||||||
def test_str_single_arg():
|
def test_str_single_arg():
|
||||||
x = ConfigFileNotFoundError("/tmp")
|
x = ConfigFileNotFoundError("/tmp/cfg.cfg")
|
||||||
s = x.__str__()
|
s = x.__str__()
|
||||||
assert s == "ConfigFileNotFoundError('/tmp')"
|
assert s == "Config file does not exist: /tmp/cfg.cfg"
|
||||||
|
|
||||||
|
|
||||||
def test_return_empty():
|
def test_return_empty():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user