ConfigFileNotFound exception + run-test script

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
Václav Valíček 2022-06-26 00:46:56 +02:00
parent 69151619f7
commit 97054b4fcc
Signed by: valicek
GPG Key ID: FF05BDCA0C73BB31
4 changed files with 71 additions and 1 deletions

View File

@ -5,7 +5,7 @@ IFS=$'\n\t'
# source libs
mydir=$(dirname $(realpath $0))
source $mydir/cloner-lib-general
source $mydir/cloner-lib-auth
source $mydir/cloner-lib-cfg
source $mydir/detector-lib-cfg

View File

@ -0,0 +1,20 @@
from pathlib import PosixPath
import os
class ConfigFileNotFoundError(OSError):
def __str__(self):
if len(self.args) == 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)
return f"Config file does not exist: {path}"
else:
return super.__str__(self)

19
run-test Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
if [ $# -eq 0 ]
then
python3 -m pytest . \
-v \
-n auto \
--ignore=tests/_support_data \
--color=yes \
--cov . \
--cov-config .coveragerc \
--cov-report term-missing \
--cov-report html \
--capture=no
else
python3 -m pytest --capture=no $1
fi

View File

@ -0,0 +1,31 @@
from repo_cloner.lib.config_file_not_found_error import ConfigFileNotFoundError
from pathlib import PosixPath
def test_type():
x = ConfigFileNotFoundError()
assert isinstance(x, ConfigFileNotFoundError)
def test_return():
x = ConfigFileNotFoundError("/tmp", "cloner.cfg")
s = x.__str__()
assert s == "Config file does not exist: /tmp/cloner.cfg"
def test_str_single_arg():
x = ConfigFileNotFoundError("/tmp")
s = x.__str__()
assert s == "ConfigFileNotFoundError('/tmp')"
def test_return_empty():
x = ConfigFileNotFoundError()
s = x.__str__()
assert s == "ConfigFileNotFoundError()"
def test_posix_path():
d = PosixPath("/nonexistent")
x = ConfigFileNotFoundError(d, "config.cfg")
assert x.__str__() == "Config file does not exist: /nonexistent/config.cfg"