LibBotUniversal/tests/test_config_sync.py

47 lines
1.1 KiB
Python
Raw Normal View History

2023-08-06 03:08:02 +03:00
from pathlib import Path
2023-08-06 02:25:32 +03:00
from typing import Any, List
import pytest
from libbot import sync
@pytest.mark.parametrize(
"args, expected",
[
(["locale"], "en"),
(["bot_token", "bot"], "sample_token"),
],
)
def test_config_get_valid(args: List[str], expected: str):
2023-08-06 03:08:02 +03:00
assert (
sync.config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
== expected
)
2023-08-06 02:25:32 +03:00
@pytest.mark.parametrize(
"args, expected",
[
(["bot_stonks", "bot"], pytest.raises(KeyError)),
],
)
def test_config_get_invalid(args: List[str], expected: Any):
with expected:
2023-08-06 03:08:02 +03:00
assert (
sync.config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
== expected
)
2023-08-06 02:25:32 +03:00
@pytest.mark.parametrize(
"key, path, value",
[
("locale", [], "en"),
("bot_token", ["bot"], "sample_token"),
],
)
def test_config_set(key: str, path: List[str], value: Any):
2023-08-06 03:08:02 +03:00
sync.config_set(key, value, *path, config_file=Path("tests/config.json"))
assert sync.config_get(key, *path, config_file=Path("tests/config.json")) == value