def test_render_simple() -> None: attrs = {"foo": "123", "list": ["a", "b", "c"]} res = render_template("query foo={{foo}} and test in {{list}}", attrs) assert res == 'query foo=123 and test in ["a", "b", "c"]' # fallback properties are used if the original list does not contain the value res2 = render_template("query foo={{foo}} and test in {{list}}", {}, [attrs]) assert res2 == 'query foo=123 and test in ["a", "b", "c"]'
def test_render_filter() -> None: attrs = {"foo": "123", "filter": 32} template = "query foo={{foo.parens}}{{#filter}} and some.other.prop == {{filter}}{{/filter}}" res = render_template(template, attrs) assert res == 'query foo="123" and some.other.prop == 32' attrs2 = {"foo": "123"} res = render_template(template, attrs2) assert res == 'query foo="123"'
def render(self, props: Json) -> str: return render_template(self.template, props)
def test_render_list() -> None: attrs = {"is": ["alb", "elb"]} res = render_template( "query {{#is.with_index}}{{^first}} or {{/first}}is({{value}}){{/is.with_index}}", attrs) assert res == "query is(alb) or is(elb)"
def test_from_now() -> None: res = render_template("{{delta.from_now}}", {"delta": "4h"}) in_4_hours = utc() + timedelta(hours=4) assert abs((in_4_hours - from_utc(res)).total_seconds()) < 1
def test_custom_tags() -> None: res = render_template("@test@ and @rest@", dict(test="work", rest="play"), tags=("@", "@")) assert res == "work and play"
def replace_placeholder(cli_input: str, **env: str) -> str: return render_template(cli_input, CLI.replacements(**env), tags=("@", "@"))