First version

This commit is contained in:
2022-04-09 23:24:47 +03:00
parent 2fc2ff1d7f
commit 559f6878f7
18 changed files with 425 additions and 1 deletions

0
tests/__init__.py Normal file
View File

42
tests/test_config.py Normal file
View File

@@ -0,0 +1,42 @@
from tempfile import NamedTemporaryFile
from src.config import read_ini_config, Config
import pytest
@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),
],
)
def test_ini_config(config_data, expected):
with NamedTemporaryFile() as tf:
if config_data:
tf.write(config_data.encode("utf-8"))
tf.flush()
if expected:
assert read_ini_config(tf.name) == expected
else:
with pytest.raises(RuntimeError):
read_ini_config(tf.name)
def test_ini_config_not_exists():
with pytest.raises(RuntimeError):
read_ini_config("not_existing_file")

View File

@@ -0,0 +1,14 @@
import pytest
from src.repository_name import is_valid_format
@pytest.mark.parametrize(
"name_format, expected",
[
("{blabla}", False),
("", True),
("{owner}/{name}", True),
]
)
def test_name_formatting(name_format, expected):
assert is_valid_format(name_format) == expected