WIP: Overhaul for 4.0.0
This commit is contained in:
@@ -2,8 +2,7 @@ from pathlib import Path
|
||||
from typing import Any, List
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot import config_delete, config_get, config_set
|
||||
from libbot.utils import config_delete, config_get, config_set
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -25,14 +24,9 @@ async def test_config_get_valid(args: List[str], expected: str, location_config:
|
||||
(["bot_stonks", "bot"], pytest.raises(KeyError)),
|
||||
],
|
||||
)
|
||||
async def test_config_get_invalid(
|
||||
args: List[str], expected: Any, location_config: Path
|
||||
):
|
||||
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
|
||||
)
|
||||
assert await config_get(args[0], *args[1:], config_file=location_config) == expected
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -68,7 +62,4 @@ async def test_config_delete(key: str, path: List[str], location_config: Path):
|
||||
],
|
||||
)
|
||||
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
|
||||
)
|
||||
assert await config_delete(key, *path, missing_ok=True, config_file=location_config) is None
|
||||
|
@@ -2,8 +2,7 @@ from pathlib import Path
|
||||
from typing import Any, List
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot import sync
|
||||
from libbot.utils import config_delete, config_get, config_set
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -13,8 +12,8 @@ from libbot import sync
|
||||
(["bot_token", "bot"], "sample_token"),
|
||||
],
|
||||
)
|
||||
def test_config_get_valid(args: List[str], expected: str, location_config: Path):
|
||||
assert sync.config_get(args[0], *args[1:], config_file=location_config) == expected
|
||||
async def test_config_get_valid(args: List[str], expected: str, location_config: Path):
|
||||
assert config_get(args[0], *args[1:], config_file=location_config) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -25,9 +24,7 @@ def test_config_get_valid(args: List[str], expected: str, location_config: Path)
|
||||
)
|
||||
def test_config_get_invalid(args: List[str], expected: Any, location_config: Path):
|
||||
with expected:
|
||||
assert (
|
||||
sync.config_get(args[0], *args[1:], config_file=location_config) == expected
|
||||
)
|
||||
assert config_get(args[0], *args[1:], config_file=location_config) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -38,8 +35,8 @@ def test_config_get_invalid(args: List[str], expected: Any, location_config: Pat
|
||||
],
|
||||
)
|
||||
def test_config_set(key: str, path: List[str], value: Any, location_config: Path):
|
||||
sync.config_set(key, value, *path, config_file=location_config)
|
||||
assert sync.config_get(key, *path, config_file=location_config) == value
|
||||
config_set(key, value, *path, config_file=location_config)
|
||||
assert config_get(key, *path, config_file=location_config) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -49,8 +46,8 @@ def test_config_set(key: str, path: List[str], value: Any, location_config: Path
|
||||
],
|
||||
)
|
||||
def test_config_delete(key: str, path: List[str], location_config: Path):
|
||||
sync.config_delete(key, *path, config_file=location_config)
|
||||
assert key not in sync.config_get(*path, config_file=location_config)
|
||||
config_delete(key, *path, config_file=location_config)
|
||||
assert key not in config_get(*path, config_file=location_config)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -60,7 +57,4 @@ def test_config_delete(key: str, path: List[str], location_config: Path):
|
||||
],
|
||||
)
|
||||
def test_config_delete_missing(key: str, path: List[str], location_config: Path):
|
||||
assert (
|
||||
sync.config_delete(key, *path, missing_ok=True, config_file=location_config)
|
||||
is None
|
||||
)
|
||||
assert config_delete(key, *path, missing_ok=True, config_file=location_config) is None
|
||||
|
@@ -2,8 +2,7 @@ from pathlib import Path
|
||||
from typing import Any, List, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot.i18n import sync
|
||||
from libbot.i18n import _, in_all_locales, in_every_locale
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -25,9 +24,9 @@ def test_i18n_get(
|
||||
location_locale: Path,
|
||||
):
|
||||
assert (
|
||||
sync._(key, *args, locale=locale, locales_root=location_locale)
|
||||
_(key, *args, locale=locale, locales_root=location_locale)
|
||||
if locale is not None
|
||||
else sync._(key, *args, locales_root=location_locale)
|
||||
else _(key, *args, locales_root=location_locale)
|
||||
) == expected
|
||||
|
||||
|
||||
@@ -39,10 +38,8 @@ def test_i18n_get(
|
||||
("nested", ["callbacks", "default"], ["sure", "авжеж"]),
|
||||
],
|
||||
)
|
||||
def test_i18n_in_all_locales(
|
||||
key: str, args: List[str], expected: Any, location_locale: Path
|
||||
):
|
||||
assert (sync.in_all_locales(key, *args, locales_root=location_locale)) == expected
|
||||
def test_i18n_in_all_locales(key: str, args: List[str], expected: Any, location_locale: Path):
|
||||
assert (in_all_locales(key, *args, locales_root=location_locale)) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -53,7 +50,5 @@ def test_i18n_in_all_locales(
|
||||
("nested", ["callbacks", "default"], {"en": "sure", "uk": "авжеж"}),
|
||||
],
|
||||
)
|
||||
def test_i18n_in_every_locale(
|
||||
key: str, args: List[str], expected: Any, location_locale: Path
|
||||
):
|
||||
assert (sync.in_every_locale(key, *args, locales_root=location_locale)) == expected
|
||||
def test_i18n_in_every_locale(key: str, args: List[str], expected: Any, location_locale: Path):
|
||||
assert (in_every_locale(key, *args, locales_root=location_locale)) == expected
|
||||
|
@@ -7,8 +7,7 @@ from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot import json_read, json_write
|
||||
from libbot.utils import json_read, json_write
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
@@ -7,8 +7,7 @@ from pathlib import Path
|
||||
from typing import Any, Union
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot import sync
|
||||
from libbot.utils import json_read, json_write
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -25,7 +24,7 @@ from libbot import sync
|
||||
],
|
||||
)
|
||||
def test_json_read_valid(path: Union[str, Path], expected: Any):
|
||||
assert sync.json_read(path) == expected
|
||||
assert json_read(path) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -37,7 +36,7 @@ def test_json_read_valid(path: Union[str, Path], expected: Any):
|
||||
)
|
||||
def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
||||
with pytest.raises(expected):
|
||||
assert sync.json_read(path) == expected
|
||||
assert json_read(path) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -54,7 +53,7 @@ def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
||||
],
|
||||
)
|
||||
def test_json_write(data: Any, path: Union[str, Path]):
|
||||
sync.json_write(data, path)
|
||||
json_write(data, path)
|
||||
|
||||
assert Path(path).is_file()
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
|
@@ -1,8 +1,7 @@
|
||||
from typing import Any, Dict, List
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot.sync._nested import nested_delete, nested_set
|
||||
from libbot.utils.misc import nested_delete, nested_set
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -56,9 +55,7 @@ def test_nested_set_invalid(
|
||||
expected: Any,
|
||||
):
|
||||
with pytest.raises(expected):
|
||||
assert (
|
||||
nested_set(target, value, *path, create_missing=create_missing)
|
||||
) == expected
|
||||
assert (nested_set(target, value, *path, create_missing=create_missing)) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@@ -1,8 +1,7 @@
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
from libbot._utils import supports_argument
|
||||
from libbot.utils.misc import supports_argument
|
||||
|
||||
|
||||
def func1(foo: str, bar: str):
|
||||
|
Reference in New Issue
Block a user