44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from tempfile import NamedTemporaryFile
|
|
|
|
import pytest
|
|
|
|
from src.config import Config, read_toml_config
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"config_data, expected",
|
|
[
|
|
(
|
|
'[main]\ntoken = "something"\n'
|
|
'format = "{owner}/{name}"\n'
|
|
'ssh_key = "/tmp/no_key"\n'
|
|
'endpoint = "https://example.com"\n'
|
|
'out_dir = "/home/user/repositories"',
|
|
Config(
|
|
token="something",
|
|
repository_format="{owner}/{name}",
|
|
out_dir="/home/user/repositories",
|
|
endpoint="https://example.com",
|
|
ssh_key_path="/tmp/no_key",
|
|
),
|
|
),
|
|
("[main]", None),
|
|
("not valid toml", None),
|
|
],
|
|
)
|
|
def test_toml_config(config_data, expected):
|
|
with NamedTemporaryFile() as tf:
|
|
if config_data:
|
|
tf.write(config_data.encode("utf-8"))
|
|
tf.flush()
|
|
if expected:
|
|
assert read_toml_config(tf.name) == expected
|
|
else:
|
|
with pytest.raises(RuntimeError):
|
|
read_toml_config(tf.name)
|
|
|
|
|
|
def test_toml_config_not_exists():
|
|
with pytest.raises(RuntimeError):
|
|
read_toml_config("not_existing_file")
|