mirror of
https://github.com/aclist/dztui.git
synced 2026-11-12 13:00:37 +01:00
chore: typehint tests
This commit is contained in:
1 parent
a5374d1f1a
commit
e29433b388
23 files changed
+170
-93
No files matched your search
+17
-12
@@ -1,25 +1,30 @@
|
||||
import json
|
||||
import pytest
|
||||
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
from dzgui.const.boilerplate import config_boilerplate
|
||||
from dzgui.config.query import get_config
|
||||
from dzgui.config.xdg import get_xdg_paths, parse_filepaths
|
||||
from dzgui.config import convert
|
||||
from tests.fixtures import fixture_path
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def legacy_config():
|
||||
def legacy_config() -> "Path":
|
||||
return fixture_path("dztuirc_1")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def unset_values():
|
||||
def unset_values() -> "Path":
|
||||
return fixture_path("dztuirc_3")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def keys():
|
||||
def keys() -> list[str]:
|
||||
return [
|
||||
"fav_server",
|
||||
"fav_label",
|
||||
@@ -36,7 +41,7 @@ def keys():
|
||||
|
||||
# TODO: use a static fixture instead of system config
|
||||
@pytest.fixture
|
||||
def config():
|
||||
def config() -> Any:
|
||||
paths = get_xdg_paths()
|
||||
xdg = parse_filepaths(paths)
|
||||
return get_config(xdg.config)
|
||||
@@ -44,21 +49,21 @@ def config():
|
||||
|
||||
@pytest.mark.post_install
|
||||
@pytest.mark.realconfig
|
||||
def test_invalid_config_value(config):
|
||||
def test_invalid_config_value(config: Any) -> None:
|
||||
with pytest.raises(Exception):
|
||||
assert config["foo"] is None
|
||||
|
||||
|
||||
@pytest.mark.post_install
|
||||
@pytest.mark.realconfig
|
||||
def test_default_config_values(keys, config):
|
||||
def test_default_config_values(keys: list[str], config: Any) -> None:
|
||||
for key in keys:
|
||||
assert config[key] is not None
|
||||
|
||||
|
||||
@pytest.mark.post_install
|
||||
@pytest.mark.realconfig
|
||||
def test_contains_invalid_values(keys, config):
|
||||
def test_contains_invalid_values(keys: list[str], config: Any) -> None:
|
||||
for key in config:
|
||||
assert key in keys
|
||||
|
||||
@@ -70,15 +75,15 @@ def test_contains_invalid_values(keys, config):
|
||||
("dztuirc_2", (False, False, False)),
|
||||
],
|
||||
)
|
||||
def test_bool_conversion(fixture, expect):
|
||||
fixture = fixture_path(fixture)
|
||||
j = convert.rc2json(fixture)
|
||||
def test_bool_conversion(fixture: str, expect: tuple[bool, bool, bool]) -> None:
|
||||
fixture_p = fixture_path(fixture)
|
||||
j = convert.rc2json(fixture_p)
|
||||
j = json.loads(j)
|
||||
assert j["fullscreen"] == expect[0]
|
||||
assert not j["use_miles"]
|
||||
|
||||
|
||||
def test_key_conversion(legacy_config):
|
||||
def test_key_conversion(legacy_config: "Path") -> None:
|
||||
j = convert.rc2json(legacy_config)
|
||||
j = json.loads(j)
|
||||
keys = [
|
||||
@@ -92,7 +97,7 @@ def test_key_conversion(legacy_config):
|
||||
assert key not in j
|
||||
|
||||
|
||||
def test_missing_values(unset_values):
|
||||
def test_missing_values(unset_values: "Path") -> None:
|
||||
j = convert.rc2json(unset_values)
|
||||
j = json.loads(j)
|
||||
assert j.keys() == config_boilerplate.keys()
|
||||
Reference in new issue
Block a user