2019-08-05 13:18:51 -04:00
|
|
|
{# Usage: {%- import "generator_macros.j2" as macros -%} #}
|
2019-08-06 08:35:53 -04:00
|
|
|
{# {{ 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 -%}
|
|
|
|
|
|
2019-08-07 09:45:02 -04:00
|
|
|
{% macro canonical_ref() -%}
|
2019-08-05 13:18:51 -04:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v{{ version }}
|
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
2019-08-07 09:45:02 -04:00
|
|
|
{% macro header(imports=[], ignore=[]) -%}
|
2019-08-06 08:35:53 -04:00
|
|
|
import unittest
|
|
|
|
|
|
2019-08-07 09:45:02 -04:00
|
|
|
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 %})
|
2019-08-06 08:35:53 -04:00
|
|
|
|
2019-08-07 09:45:02 -04:00
|
|
|
{{ canonical_ref() }}
|
2019-08-06 08:35:53 -04:00
|
|
|
{%- endmacro %}
|
|
|
|
|
|
2019-07-29 23:42:12 -05:00
|
|
|
{% macro utility() -%}# Utility functions
|
|
|
|
|
def assertRaisesWithMessage(self, exception):
|
|
|
|
|
return self.assertRaisesRegex(exception, r".+")
|
|
|
|
|
{%- endmacro %}
|
2019-08-06 08:35:53 -04:00
|
|
|
|
2019-10-22 10:56:24 -04:00
|
|
|
{% macro footer(_has_error_case) -%}
|
|
|
|
|
{% if has_error_case or _has_error_case %}
|
2019-08-06 08:35:53 -04:00
|
|
|
{{ utility() }}
|
|
|
|
|
{% endif %}
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
{%- endmacro %}
|