73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
from repo_cloner.lib.cloner_config import ClonerConfigParser
|
|
import pytest
|
|
from repo_cloner.lib.config_file_not_found_error import ConfigFileNotFoundError
|
|
from pathlib import Path
|
|
|
|
|
|
@pytest.fixture
|
|
def config_path() -> Path:
|
|
path = Path(__file__).parent.parent
|
|
return path.joinpath("_support_data", "config")
|
|
|
|
|
|
def test_no_config_file():
|
|
with pytest.raises(ConfigFileNotFoundError) as e:
|
|
x = ClonerConfigParser("/tmp/path/that/does/not/exist")
|
|
assert e.__str__() == "<ExceptionInfo ConfigFileNotFoundError('/tmp/path/that/does/not/exist') tblen=2>"
|
|
|
|
|
|
def test_valid_config(config_path: Path):
|
|
cfg = config_path.joinpath("valid.cfg")
|
|
x = ClonerConfigParser(cfg)
|
|
assert x.invalid == False
|
|
assert x.invalid_lines == []
|
|
c = x.config
|
|
assert c.cloner_project_name == "some-random-project"
|
|
assert c.cloner_repo_url == "git@git.somerandomserver.test:/path"
|
|
assert c.cloner_interval == 666
|
|
assert c.cloner_submodules == True
|
|
assert c.cloner_submodule_depth == 500000
|
|
|
|
|
|
def test_empty_config(config_path: Path):
|
|
cfg = config_path.joinpath("empty.cfg")
|
|
x = ClonerConfigParser(cfg)
|
|
assert x.invalid == False
|
|
assert x.invalid_lines == []
|
|
c = x.config
|
|
assert c.cloner_project_name == ""
|
|
assert c.cloner_repo_url == ""
|
|
assert c.cloner_interval == 0
|
|
assert c.cloner_submodules == True
|
|
assert c.cloner_submodule_depth == 0
|
|
|
|
|
|
def test_invalid_config(config_path: Path, caplog):
|
|
cfg = config_path.joinpath("invalid.cfg")
|
|
with caplog.at_level(30):
|
|
x = ClonerConfigParser(cfg)
|
|
|
|
# two invalid lines
|
|
assert x.invalid == True
|
|
assert x.invalid_lines == [
|
|
('invalid_option1', None),
|
|
('invalid_option', "2"),
|
|
]
|
|
# test logging
|
|
assert any(
|
|
(r.levelname == "CRITICAL" and r.message == "'invalid_option is not recognized config option'")
|
|
for r in caplog.records
|
|
)
|
|
|
|
assert any(
|
|
(r.levelname == "WARNING" and r.message == "Line 'invalid_option1' has invalid format!")
|
|
for r in caplog.records
|
|
)
|
|
|
|
c = x.config
|
|
assert c.cloner_project_name == "some-random-project"
|
|
assert c.cloner_repo_url == "git@git.somerandomserver.test:/path"
|
|
assert c.cloner_interval == 666
|
|
assert c.cloner_submodules == True
|
|
assert c.cloner_submodule_depth == 500000
|