Commit 25e680df authored by Sean Leavey's avatar Sean Leavey

Add element test framework and tests for mirror

parent 96e1ce25
def pytest_generate_tests(metafunc):
"""Generate test inputs for elements.
This is called once per each test function to generate test inputs.
directive = metafunc.cls.directive
name =
params = metafunc.cls.params
assert directive, "Test class needs a 'directive' attribute"
assert name, "Test class needs a 'name' attribute"
assert params, "Test class needs an 'params' attribute"
newparams = []
for args in params:
newargs = []
newkwargs = {}
expected = {}
for arg in args:
if arg.value is not None:
if arg.expected is not None:
expected[arg.param] = arg.expected
newparams.append((directive, name, newargs, newkwargs, expected))
metafunc.parametrize("directive,name,args,kwargs,expected", newparams)
from .util import Arg, ElementTest
class TestMirror(ElementTest):
directive = "m"
name = "m1"
params = [
[Arg("R", "1", 1), Arg("T", "0", 0)],
[Arg("R", "1", 1), Arg("T", "0", 0), Arg("L", "none", 0)],
[Arg("R", "0.5", 0.5), Arg("T", "0.5", 0.5)],
[Arg("R", "0.5", 0.5), Arg("T", "0.5", 0.5), Arg("L", "none", 0)],
[Arg("R", "0.5", 0.5), Arg("T", "0.5", 0.5), Arg("L", "0", 0)],
import abc
from dataclasses import dataclass
from typing import Any
class Arg:
"""Kat script argument value and expected parsed form."""
param: str
value: str
expected: Any
# DON'T call this TestElement or similar or else pytest will try to run tests on this instance!
class ElementTest(metaclass=abc.ABCMeta):
directive = None
name = None
params = {}
def test_element(self, compiler, directive, name, args, kwargs, expected):
model = compiler.compile(f"{directive} {name} {' '.join(arg for arg in args)}")
for param, value in expected.items():
assert model.reduce_get_attr(f"{name}.{param}") == value
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment