LibBotUniversal/tests/test_config_async.py

75 lines
1.9 KiB
Python
Raw Permalink 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 config_delete, config_get, config_set
2023-08-06 02:25:32 +03:00
@pytest.mark.asyncio
@pytest.mark.parametrize(
"args, expected",
[
(["locale"], "en"),
(["bot_token", "bot"], "sample_token"),
],
)
2023-08-06 20:11:16 +03:00
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
2023-08-06 02:25:32 +03:00
@pytest.mark.asyncio
@pytest.mark.parametrize(
"args, expected",
[
(["bot_stonks", "bot"], pytest.raises(KeyError)),
],
)
2023-08-06 20:11:16 +03:00
async def test_config_get_invalid(
args: List[str], expected: Any, location_config: Path
):
2023-08-06 02:25:32 +03:00
with expected:
2023-08-06 03:08:02 +03:00
assert (
2023-08-06 20:11:16 +03:00
await config_get(args[0], *args[1:], config_file=location_config)
2023-08-06 03:08:02 +03:00
== expected
)
2023-08-06 02:25:32 +03:00
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, path, value",
[
("locale", [], "en"),
("bot_token", ["bot"], "sample_token"),
],
)
2023-08-06 20:11:16 +03:00
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
2024-05-26 16:40:29 +03:00
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, path",
[
("bot_token", ["bot"]),
],
)
async def test_config_delete(key: str, path: List[str], location_config: Path):
await config_delete(key, *path, config_file=location_config)
assert key not in (await config_get(*path, config_file=location_config))
@pytest.mark.asyncio
@pytest.mark.parametrize(
"key, path",
[
("bot_lol", ["bot"]),
],
)
async def test_config_delete_missing(key: str, path: List[str], location_config: Path):
assert (
await config_delete(key, *path, missing_ok=True, config_file=location_config)
is None
)