Python: basic, package install, error handler for begining

Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
2022-05-04 15:02:55 +02:00
parent 5ce0f7da22
commit 155597aeff
13 changed files with 204 additions and 6 deletions

View File

@@ -0,0 +1,25 @@
from repo_cloner.lib.dir_not_found_error import DirNotFoundError
from pathlib import PosixPath
def test_type():
x = DirNotFoundError()
assert isinstance(x, DirNotFoundError)
def test_return():
x = DirNotFoundError("/tmp")
s = x.__str__()
assert s == "Directory does not exist / is not a dir: /tmp"
def test_return_empty():
x = DirNotFoundError()
s = x.__str__()
assert s == "DirNotFoundError()"
def test_posix_path():
d = PosixPath("/nonexistent")
x = DirNotFoundError(d)
assert x.__str__() == "Directory does not exist / is not a dir: /nonexistent"

View File

@@ -0,0 +1,78 @@
import xml.dom.expatbuilder
from repo_cloner.lib.repo_dir_structure import RepoDirStructure
from repo_cloner.lib.dir_not_found_error import DirNotFoundError
from pathlib import PosixPath
import pytest
def test_init():
X = RepoDirStructure("/tmp")
assert X._base_dir == "/tmp"
assert X._conf_dir == "/tmp/config"
assert X._repos_dir == "/tmp/repos"
assert X._cache_dir == "/tmp/cache"
def test_no_base_dir(tmp_path: PosixPath):
x = tmp_path.joinpath("nonexistent")
X = RepoDirStructure(x)
with pytest.raises(DirNotFoundError) as excinfo:
X.exists
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
assert excinfo.exconly().endswith("/nonexistent")
def test_no_config(tmp_path: PosixPath):
X = RepoDirStructure(tmp_path)
with pytest.raises(DirNotFoundError) as excinfo:
X.exists
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
assert excinfo.exconly().endswith("/config")
def test_no_cache(tmp_path: PosixPath):
tmp_path.joinpath("config").mkdir()
X = RepoDirStructure(tmp_path)
with pytest.raises(DirNotFoundError) as excinfo:
X.exists
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
assert excinfo.exconly().endswith("/cache")
def test_no_repos(tmp_path: PosixPath):
tmp_path.joinpath("config").mkdir()
tmp_path.joinpath("cache").mkdir()
X = RepoDirStructure(tmp_path)
with pytest.raises(DirNotFoundError) as excinfo:
X.exists
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
assert excinfo.exconly().endswith("/repos")
def test_exists_okay(tmp_path: PosixPath):
tmp_path.joinpath("config").mkdir()
tmp_path.joinpath("cache").mkdir()
tmp_path.joinpath("repos").mkdir()
X = RepoDirStructure(tmp_path)
assert True == X.exists
def test_base_dir():
X = RepoDirStructure("/a/b")
assert X.base_dir == "/a/b"
def test_cache_dir():
X = RepoDirStructure("/a/b")
assert X.cache_dir == "/a/b/cache"
def test_config_dir():
X = RepoDirStructure("/a/b")
assert X.conf_dir == "/a/b/config"
def test_repos_dir():
X = RepoDirStructure("/a/c")
assert X.repos_dir == "/a/c/repos"