2022-05-04 15:02:55 +02:00
|
|
|
import xml.dom.expatbuilder
|
|
|
|
|
|
|
|
from repo_cloner.lib.repo_dir_structure import RepoDirStructure
|
|
|
|
from repo_cloner.lib.dir_not_found_error import DirNotFoundError
|
2022-06-26 01:24:40 +02:00
|
|
|
from repo_cloner.lib.config_file_not_found_error import ConfigFileNotFoundError
|
2022-05-04 15:02:55 +02:00
|
|
|
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"
|
|
|
|
|
|
|
|
|
2022-06-26 01:24:40 +02:00
|
|
|
def test_config_filename():
|
|
|
|
X = RepoDirStructure("/tmp")
|
|
|
|
assert X._RepoDirStructure__config_filename == "/tmp/config/cloner.cfg"
|
|
|
|
|
|
|
|
|
2022-05-04 15:02:55 +02:00
|
|
|
def test_no_base_dir(tmp_path: PosixPath):
|
|
|
|
x = tmp_path.joinpath("nonexistent")
|
|
|
|
X = RepoDirStructure(x)
|
|
|
|
with pytest.raises(DirNotFoundError) as excinfo:
|
2022-06-26 00:05:36 +02:00
|
|
|
X.base_dir_exists
|
2022-05-04 15:02:55 +02:00
|
|
|
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:
|
2022-06-26 00:05:36 +02:00
|
|
|
X.conf_dir_exists
|
2022-05-04 15:02:55 +02:00
|
|
|
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:
|
2022-06-26 00:05:36 +02:00
|
|
|
X.cache_dir_exists
|
2022-05-04 15:02:55 +02:00
|
|
|
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:
|
2022-06-26 00:05:36 +02:00
|
|
|
X.repos_dir_exists
|
2022-05-04 15:02:55 +02:00
|
|
|
assert "DirNotFoundError: Directory does not exist / is not a dir: " in excinfo.exconly()
|
|
|
|
assert excinfo.exconly().endswith("/repos")
|
|
|
|
|
|
|
|
|
2022-06-26 00:05:36 +02:00
|
|
|
def test_dirs_exist_okay(tmp_path: PosixPath):
|
2022-05-04 15:02:55 +02:00
|
|
|
tmp_path.joinpath("config").mkdir()
|
|
|
|
tmp_path.joinpath("cache").mkdir()
|
|
|
|
tmp_path.joinpath("repos").mkdir()
|
2022-06-26 00:05:36 +02:00
|
|
|
|
2022-05-04 15:02:55 +02:00
|
|
|
X = RepoDirStructure(tmp_path)
|
2022-06-26 00:05:36 +02:00
|
|
|
assert X.base_dir_exists
|
|
|
|
assert X.conf_dir_exists
|
|
|
|
assert X.cache_dir_exists
|
|
|
|
assert X.repos_dir_exists
|
|
|
|
assert X.dirs_exist
|
2022-05-04 15:02:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
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"
|
2022-06-26 01:24:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_has_config(tmp_path: PosixPath):
|
|
|
|
tmp_path.joinpath("config").mkdir()
|
|
|
|
tmp_path.joinpath("cache").mkdir()
|
|
|
|
tmp_path.joinpath("repos").mkdir()
|
|
|
|
|
|
|
|
X = RepoDirStructure(tmp_path)
|
|
|
|
with pytest.raises(ConfigFileNotFoundError) as excinfo:
|
|
|
|
X.has_config
|
|
|
|
assert "Config file does not exist: " in excinfo.exconly()
|
|
|
|
assert "config/cloner.cfg" in excinfo.exconly()
|
|
|
|
|
|
|
|
tmp_path.joinpath("config", "cloner.cfg").touch()
|
|
|
|
assert X.has_config
|
2022-07-24 21:14:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_config_file(tmp_path: PosixPath):
|
|
|
|
X = RepoDirStructure(tmp_path)
|
|
|
|
assert X.config_file == tmp_path.joinpath("config", "cloner.cfg").__str__()
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_config(tmp_path: PosixPath):
|
|
|
|
tmp_path.joinpath("config").mkdir()
|
|
|
|
tmp_path.joinpath("cache").mkdir()
|
|
|
|
tmp_path.joinpath("repos").mkdir()
|
|
|
|
|
|
|
|
X = RepoDirStructure(tmp_path)
|
|
|
|
# no file provided
|
|
|
|
with pytest.raises(ConfigFileNotFoundError) as excinfo:
|
|
|
|
X.config
|
|
|
|
|
|
|
|
# create config file
|
|
|
|
tmp_path.joinpath("config", "cloner.cfg").touch()
|
|
|
|
X = RepoDirStructure(tmp_path)
|
|
|
|
assert X.has_config == True
|
|
|
|
assert 5 == X.config.cloner_interval
|