Compare commits
3 Commits
253c85985b
...
b6537a50ae
Author | SHA1 | Date | |
---|---|---|---|
b6537a50ae
|
|||
e508f37089
|
|||
d66bb9c93e
|
@@ -9,7 +9,7 @@ from libbot.i18n.classes.bot_locale import BotLocale
|
|||||||
async def _(
|
async def _(
|
||||||
key: str,
|
key: str,
|
||||||
*args: str,
|
*args: str,
|
||||||
locale: str = sync.config_get("locale"),
|
locale: str = "en",
|
||||||
locales_root: Union[str, Path] = Path("locale"),
|
locales_root: Union[str, Path] = Path("locale"),
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Get value of locale string
|
"""Get value of locale string
|
||||||
@@ -17,7 +17,7 @@ async def _(
|
|||||||
### Args:
|
### Args:
|
||||||
* key (`str`): The last key of the locale's keys path.
|
* key (`str`): The last key of the locale's keys path.
|
||||||
* *args (`list`): Path to key like: `dict[args][key]`.
|
* *args (`list`): Path to key like: `dict[args][key]`.
|
||||||
* locale (`str`): Locale to looked up in. Defaults to config's `"locale"` value.
|
* locale (`str`): Locale to looked up in. Defaults to `"en"`.
|
||||||
* locales_root (`Union[str, Path]`, *optional*): Folder where locales are located. Defaults to `Path("locale")`.
|
* locales_root (`Union[str, Path]`, *optional*): Folder where locales are located. Defaults to `Path("locale")`.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
|
@@ -9,7 +9,7 @@ from libbot.sync import config_get, json_read
|
|||||||
def _(
|
def _(
|
||||||
key: str,
|
key: str,
|
||||||
*args: str,
|
*args: str,
|
||||||
locale: str = sync.config_get("locale"),
|
locale: str = "en",
|
||||||
locales_root: Union[str, Path] = Path("locale"),
|
locales_root: Union[str, Path] = Path("locale"),
|
||||||
) -> Any:
|
) -> Any:
|
||||||
"""Get value of locale string
|
"""Get value of locale string
|
||||||
@@ -17,7 +17,7 @@ def _(
|
|||||||
### Args:
|
### Args:
|
||||||
* key (`str`): The last key of the locale's keys path.
|
* key (`str`): The last key of the locale's keys path.
|
||||||
* *args (`list`): Path to key like: `dict[args][key]`.
|
* *args (`list`): Path to key like: `dict[args][key]`.
|
||||||
* locale (`str`): Locale to looked up in. Defaults to config's `"locale"` value.
|
* locale (`str`): Locale to looked up in. Defaults to `"en"`.
|
||||||
* locales_root (`Union[str, Path]`, *optional*): Folder where locales are located. Defaults to `Path("locale")`.
|
* locales_root (`Union[str, Path]`, *optional*): Folder where locales are located. Defaults to `Path("locale")`.
|
||||||
|
|
||||||
### Returns:
|
### Returns:
|
||||||
|
@@ -52,3 +52,9 @@ target-version = ['py38', 'py39', 'py310', 'py311']
|
|||||||
|
|
||||||
[tool.isort]
|
[tool.isort]
|
||||||
profile = "black"
|
profile = "black"
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
minversion = "6.0"
|
||||||
|
python_files = ["test_*.py"]
|
||||||
|
pythonpath = "."
|
||||||
|
testpaths = ["tests"]
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -14,7 +15,10 @@ from libbot import config_get, config_set
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_config_get_valid(args: List[str], expected: str):
|
async def test_config_get_valid(args: List[str], expected: str):
|
||||||
assert await config_get(args[0], *args[1:]) == expected
|
assert (
|
||||||
|
await config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
|
||||||
|
== expected
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -26,7 +30,10 @@ async def test_config_get_valid(args: List[str], expected: str):
|
|||||||
)
|
)
|
||||||
async def test_config_get_invalid(args: List[str], expected: Any):
|
async def test_config_get_invalid(args: List[str], expected: Any):
|
||||||
with expected:
|
with expected:
|
||||||
assert await config_get(args[0], *args[1:]) == expected
|
assert (
|
||||||
|
await config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
|
||||||
|
== expected
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -38,5 +45,5 @@ async def test_config_get_invalid(args: List[str], expected: Any):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_config_set(key: str, path: List[str], value: Any):
|
async def test_config_set(key: str, path: List[str], value: Any):
|
||||||
await config_set(key, value, *path)
|
await config_set(key, value, *path, config_file=Path("tests/config.json"))
|
||||||
assert await config_get(key, *path) == value
|
assert await config_get(key, *path, config_file=Path("tests/config.json")) == value
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
from pathlib import Path
|
||||||
from typing import Any, List
|
from typing import Any, List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -13,7 +14,10 @@ from libbot import sync
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_config_get_valid(args: List[str], expected: str):
|
def test_config_get_valid(args: List[str], expected: str):
|
||||||
assert sync.config_get(args[0], *args[1:]) == expected
|
assert (
|
||||||
|
sync.config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
|
||||||
|
== expected
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -24,7 +28,10 @@ def test_config_get_valid(args: List[str], expected: str):
|
|||||||
)
|
)
|
||||||
def test_config_get_invalid(args: List[str], expected: Any):
|
def test_config_get_invalid(args: List[str], expected: Any):
|
||||||
with expected:
|
with expected:
|
||||||
assert sync.config_get(args[0], *args[1:]) == expected
|
assert (
|
||||||
|
sync.config_get(args[0], *args[1:], config_file=Path("tests/config.json"))
|
||||||
|
== expected
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@@ -35,5 +42,5 @@ def test_config_get_invalid(args: List[str], expected: Any):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_config_set(key: str, path: List[str], value: Any):
|
def test_config_set(key: str, path: List[str], value: Any):
|
||||||
sync.config_set(key, value, *path)
|
sync.config_set(key, value, *path, config_file=Path("tests/config.json"))
|
||||||
assert sync.config_get(key, *path) == value
|
assert sync.config_get(key, *path, config_file=Path("tests/config.json")) == value
|
||||||
|
@@ -12,13 +12,13 @@ from libbot import json_read, json_write
|
|||||||
"path, expected",
|
"path, expected",
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
"data/test.json",
|
"tests/data/test.json",
|
||||||
{
|
{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
("data/empty.json", {}),
|
("tests/data/empty.json", {}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_json_read_valid(path: Union[str, Path], expected: Any):
|
async def test_json_read_valid(path: Union[str, Path], expected: Any):
|
||||||
@@ -29,8 +29,8 @@ async def test_json_read_valid(path: Union[str, Path], expected: Any):
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path, expected",
|
"path, expected",
|
||||||
[
|
[
|
||||||
("data/invalid.json", pytest.raises(JSONDecodeError)),
|
("tests/data/invalid.json", pytest.raises(JSONDecodeError)),
|
||||||
("data/nonexistent.json", pytest.raises(FileNotFoundError)),
|
("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
async def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
||||||
@@ -47,9 +47,9 @@ async def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
||||||
},
|
},
|
||||||
"data/test.json",
|
"tests/data/test.json",
|
||||||
),
|
),
|
||||||
({}, "data/empty.json"),
|
({}, "tests/data/empty.json"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_json_write(data: Any, path: Union[str, Path]):
|
async def test_json_write(data: Any, path: Union[str, Path]):
|
||||||
|
@@ -11,13 +11,13 @@ from libbot import sync
|
|||||||
"path, expected",
|
"path, expected",
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
"data/test.json",
|
"tests/data/test.json",
|
||||||
{
|
{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
("data/empty.json", {}),
|
("tests/data/empty.json", {}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_json_read_valid(path: Union[str, Path], expected: Any):
|
def test_json_read_valid(path: Union[str, Path], expected: Any):
|
||||||
@@ -27,8 +27,8 @@ def test_json_read_valid(path: Union[str, Path], expected: Any):
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"path, expected",
|
"path, expected",
|
||||||
[
|
[
|
||||||
("data/invalid.json", pytest.raises(JSONDecodeError)),
|
("tests/data/invalid.json", pytest.raises(JSONDecodeError)),
|
||||||
("data/nonexistent.json", pytest.raises(FileNotFoundError)),
|
("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
||||||
@@ -44,9 +44,9 @@ def test_json_read_invalid(path: Union[str, Path], expected: Any):
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
"abcdefg": ["higklmnop", {"lol": {"kek": [1.0000035, 0.2542, 1337]}}],
|
||||||
},
|
},
|
||||||
"data/test.json",
|
"tests/data/test.json",
|
||||||
),
|
),
|
||||||
({}, "data/empty.json"),
|
({}, "tests/data/empty.json"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_json_write(data: Any, path: Union[str, Path]):
|
def test_json_write(data: Any, path: Union[str, Path]):
|
||||||
|
Reference in New Issue
Block a user