LibBotUniversal/tests/test_config_async.py
profitroll 64aa2686ea
Some checks failed
Tests / test (3.10) (push) Failing after 55s
Tests / test (3.11) (push) Failing after 5s
Tests / test (3.8) (push) Failing after 6s
Tests / test (3.9) (push) Failing after 5s
Updated to 0.2.1
2023-08-06 19:11:16 +02:00

49 lines
1.2 KiB
Python

from pathlib import Path
from typing import Any, List
import pytest
from libbot import config_get, config_set
@pytest.mark.asyncio
@pytest.mark.parametrize(
"args, expected",
[
(["locale"], "en"),
(["bot_token", "bot"], "sample_token"),
],
)
async def test_config_get_valid(args: List[str], expected: str, location_config: Path):
assert await config_get(args[0], *args[1:], config_file=location_config) == expected
@pytest.mark.asyncio
@pytest.mark.parametrize(
"args, expected",
[
(["bot_stonks", "bot"], pytest.raises(KeyError)),
],
)
async def test_config_get_invalid(
args: List[str], expected: Any, location_config: Path
):
with expected:
assert (
await config_get(args[0], *args[1:], config_file=location_config)
== expected
)
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, path, value",
[
("locale", [], "en"),
("bot_token", ["bot"], "sample_token"),
],
)
async def test_config_set(key: str, path: List[str], value: Any, location_config: Path):
await config_set(key, value, *path, config_file=location_config)
assert await config_get(key, *path, config_file=location_config) == value