Files
python/config/generator_macros.j2

46 lines
1.1 KiB
Plaintext
Raw Normal View History

{# Usage: {%- import "generator_macros.j2" as macros -%} #}
{# {{ macros.linebreak(text) }} #}
{%- macro linebreak(s) %}
{%- set parts = s.split(": ") -%}
"{{ parts[0] }}: "
{% for part in parts[1].split(", ") %}
"{{ part }}{% if not loop.last %}, {% endif %}"
{%- endfor %}
{% endmacro -%}
{% macro canonical_ref() -%}
# Tests adapted from `problem-specifications//canonical-data.json` @ v{{ version }}
{%- endmacro %}
{% macro header(imports=[], ignore=[]) -%}
import unittest
from {{ exercise | to_snake }} import ({% if imports -%}
{% for name in imports -%}
{{ name }},
{% endfor %}
{%- else -%}
{% for prop in properties -%}
{%- if prop not in ignore -%}
{{ prop | to_snake }},
{%- endif -%}
{% endfor %}
{%- endif %})
{{ canonical_ref() }}
{%- endmacro %}
{% macro utility() -%}# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
{%- endmacro %}
{% macro footer(_has_error_case) -%}
{% if has_error_case or _has_error_case %}
{{ utility() }}
{% endif %}
if __name__ == '__main__':
unittest.main()
{%- endmacro %}