#!/usr/bin/env python3
from __future__ import annotations
import importlib.util
import io
import sys
import tempfile
from contextlib import redirect_stdout
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
VERIFIER = ROOT / "scripts/verify-polar.py"
def load_verifier():
spec = importlib.util.spec_from_file_location("verify_polar", VERIFIER)
assert spec is not None and spec.loader is not None
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def category(index: int, value: int, endpoint: tuple[float, float] | None) -> str:
body = '{}'.format(value)
if endpoint is not None:
x, y = endpoint
body = (
f''
f'' + body
)
return (
f'{body}'
)
def document(categories: str, extra_svg: str = "") -> str:
return (
'
'
''
)
VALID = document(
category(0, 0, None)
+ category(1, 25, (125, 100))
+ category(2, 50, (100, 150))
+ category(3, 100, (0, 100))
)
def main() -> int:
module = load_verifier()
cases = [
(
"25 percent hub",
VALID.replace('data-polar-inner-radius="0"', 'data-polar-inner-radius="25"'),
"inner radius",
),
(
"sqrt radius",
VALID.replace('x2="125"', 'x2="150"').replace('cx="125"', 'cx="150"'),
"linear endpoint",
),
(
"visible zero ray",
VALID.replace(
'0',
''
'0',
),
"zero category",
),
(
"out of range",
VALID.replace('data-polar-value="100"', 'data-polar-value="101"'),
"outside 0..100",
),
(
"duplicate index",
VALID.replace('data-polar-index="3"', 'data-polar-index="2"'),
"indices",
),
(
"quantitative wedge",
VALID.replace('', ''),
"wedge",
),
(
"unmarked quantitative wedge",
VALID.replace(
'',
'',
),
"wedge",
),
(
"polygon area encoding",
VALID.replace(
'',
'',
),
"unsupported SVG element ",
),
(
"external referenced shape",
VALID.replace('', ''),
"unsupported SVG element