Ship name corpus lookup/spin, nickname suggestions, significance UX, site-ideas SMTP, and remove the Logo concepts page and assets.
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Tests for world-name corpus spin/filter helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import random
|
|
|
|
from stork.names_corpus import SpinFilters, filter_pool, load_corpus, meta, spin
|
|
|
|
|
|
def test_corpus_loads() -> None:
|
|
m = meta()
|
|
assert m["total"] > 100
|
|
assert "draw" in m["modes"] and "remix" in m["modes"]
|
|
assert m.get("backend") in {"sqlite", "json", None}
|
|
if m.get("backend") != "sqlite":
|
|
names = load_corpus()
|
|
assert m["total"] == len(names)
|
|
assert len(names) > 100
|
|
|
|
|
|
def test_filter_russian_length_contains_z() -> None:
|
|
pool = filter_pool(SpinFilters(regions=["ru"], length=4, contains="z"))
|
|
assert pool
|
|
for entry in pool:
|
|
assert "ru" in entry.regions
|
|
assert sum(1 for c in entry.name if c.isalpha()) == 4
|
|
assert "z" in entry.name.casefold()
|
|
|
|
|
|
def test_spin_draw_and_remix() -> None:
|
|
rng = random.Random(42)
|
|
drawn = spin("draw", SpinFilters(regions=["en"], min_length=3, max_length=8), rng=rng)
|
|
assert drawn["spelling"]
|
|
assert drawn["mode"] == "draw"
|
|
remixed = spin("remix", SpinFilters(regions=["intl"], min_length=3), rng=rng)
|
|
assert remixed["spelling"]
|
|
assert remixed["mode"] == "remix"
|
|
|
|
|
|
def test_remix_honors_exact_length() -> None:
|
|
rng = random.Random(7)
|
|
for _ in range(8):
|
|
remixed = spin(
|
|
"remix",
|
|
SpinFilters(regions=["en"], length=4, contains="a"),
|
|
rng=rng,
|
|
)
|
|
assert sum(1 for c in remixed["spelling"] if c.isalpha()) == 4
|
|
assert "a" in remixed["spelling"].casefold()
|
|
|
|
|
|
def test_spin_empty_pool() -> None:
|
|
try:
|
|
spin("draw", SpinFilters(regions=["ru"], length=2, contains="qqq"))
|
|
raise AssertionError("expected ValueError")
|
|
except ValueError as exc:
|
|
assert "no matches" in str(exc).lower()
|