FletAppDemo/tests/test_gallery.py

34 lines
1.2 KiB
Python

import json
from pathlib import Path
from gallery.examples import ALL_EXAMPLES
from gallery.icon_catalog import ICON_NAMES, PAGE_SIZE, icon_snippet, matching_icons
ROOT = Path(__file__).resolve().parents[1]
def test_example_ids_are_unique() -> None:
ids = [example.id for example in ALL_EXAMPLES]
assert len(ids) == len(set(ids))
assert len(ids) >= 25
def test_every_example_builds_a_control() -> None:
for example in ALL_EXAMPLES:
assert example.builder() is not None, example.id
def test_source_manifest_is_complete_and_exact() -> None:
manifest_path = ROOT / "src" / "gallery" / "source_manifest.json"
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
assert set(manifest) == {example.id for example in ALL_EXAMPLES}
for anchor in manifest.values():
source = (ROOT / anchor["path"]).read_text(encoding="utf-8").splitlines()
assert source[anchor["line"] - 1].startswith(f"def {anchor['function']}(")
def test_icon_catalog_searches_every_icon_and_copies_valid_flet_code() -> None:
assert len(ICON_NAMES) > PAGE_SIZE
assert "HOME" in matching_icons("home")
assert "HOME_OUTLINED" in matching_icons("home outlined")
assert icon_snippet("HOME") == "ft.Icon(ft.Icons.HOME)"