2022-06-26 05:22:19 +02:00
|
|
|
from repo_cloner.lib.cloner_config import ClonerConfig
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_init():
|
|
|
|
x = ClonerConfig()
|
|
|
|
|
|
|
|
assert x._ClonerConfig__properties == ['cloner_interval', 'cloner_project_name', 'cloner_repo_url',
|
|
|
|
'cloner_submodule_depth', 'cloner_submodules']
|
|
|
|
assert isinstance(x._ClonerConfig__values, dict)
|
|
|
|
assert len(dict(x._ClonerConfig__values)) == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_try_default():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert 888 == x._ClonerConfig__try_default("cloner_interval", 888)
|
|
|
|
with pytest.raises(KeyError) as exc:
|
|
|
|
x._ClonerConfig__try_default("nonexistent_key", 888)
|
|
|
|
assert exc.exconly() == "KeyError: 'nonexistent_key is not recognized config option'"
|
|
|
|
|
|
|
|
x._ClonerConfig__values['cloner_interval'] = 666
|
|
|
|
assert 666 == x._ClonerConfig__try_default("cloner_interval", 888)
|
|
|
|
|
|
|
|
|
|
|
|
def test_cloner_project_name():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert x.cloner_project_name == ""
|
|
|
|
x._ClonerConfig__values['cloner_project_name'] = "asdfgh"
|
|
|
|
assert x.cloner_project_name == "asdfgh"
|
|
|
|
|
|
|
|
|
|
|
|
def test_cloner_repo_url():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert x.cloner_repo_url == ""
|
|
|
|
x._ClonerConfig__values['cloner_repo_url'] = "asdfgh"
|
|
|
|
assert x.cloner_repo_url == "asdfgh"
|
|
|
|
|
|
|
|
|
|
|
|
def test_cloner_interval():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert x.cloner_interval == 0
|
2022-07-24 22:47:13 +02:00
|
|
|
x._ClonerConfig__values['cloner_interval'] = 5
|
|
|
|
assert x.cloner_interval == 5
|
2022-06-26 05:22:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_cloner_submodules():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert x.cloner_submodules == True
|
|
|
|
x._ClonerConfig__values['cloner_submodules'] = False
|
|
|
|
assert not x.cloner_submodules
|
|
|
|
|
|
|
|
|
|
|
|
def test_cloner_submodule_depth():
|
|
|
|
x = ClonerConfig()
|
2022-08-06 02:10:48 +02:00
|
|
|
assert x.cloner_submodule_depth == 0
|
2022-06-26 05:22:19 +02:00
|
|
|
x._ClonerConfig__values['cloner_submodule_depth'] = -1
|
|
|
|
assert x.cloner_submodule_depth == -1
|
|
|
|
|
|
|
|
|
|
|
|
def test_set_property():
|
|
|
|
x = ClonerConfig()
|
|
|
|
assert x.cloner_interval == 0
|
2022-07-24 22:47:13 +02:00
|
|
|
x._set_property("cloner_interval", 5)
|
|
|
|
assert x.cloner_interval == 5
|
|
|
|
x._set_property("cloner_interval", "7")
|
|
|
|
assert x.cloner_interval == 7
|
2022-06-26 05:22:19 +02:00
|
|
|
|
|
|
|
# invalid type
|
|
|
|
with pytest.raises(ValueError) as exc:
|
|
|
|
x._set_property("cloner_interval", "č")
|
2022-07-24 21:14:05 +02:00
|
|
|
assert exc.exconly() == "ValueError: Invalid value for key cloner_interval: type is <class 'str'> instead of <class 'int'>, conversion failed"
|
2022-06-26 05:22:19 +02:00
|
|
|
|
2022-06-26 07:57:54 +02:00
|
|
|
x._set_property("cloner_project_name", "č")
|
|
|
|
|
2022-06-26 05:22:19 +02:00
|
|
|
# undefined property
|
|
|
|
with pytest.raises(KeyError) as exc:
|
|
|
|
x._set_property("nonexistent_key", 888)
|
|
|
|
assert exc.exconly() == "KeyError: 'nonexistent_key is not recognized config option'"
|
2022-07-24 21:14:05 +02:00
|
|
|
|
|
|
|
# boolean conversion
|
|
|
|
x._set_property("cloner_submodules", "1")
|
|
|
|
assert x.cloner_submodules == True
|
|
|
|
|
|
|
|
x._set_property("cloner_submodules", "0")
|
|
|
|
assert x.cloner_submodules == False
|
|
|
|
|
|
|
|
# integer conversion
|
|
|
|
x._set_property("cloner_interval", 60)
|
|
|
|
assert x.cloner_interval == 60
|