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 -%}
|
|
|
|
|
|
|
|
|
|
{% macro properties(exercise, properties) -%}
|
|
|
|
|
from {{ exercise | to_snake }} import {% for prop in properties -%}
|
|
|
|
|
{{ prop | to_snake }}
|
|
|
|
|
{%- if not loop.last %}, {% endif -%}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
{% endmacro -%}
|
2019-08-05 13:18:51 -04:00
|
|
|
|
|
|
|
|
{% macro canonical_ref(version) -%}
|
|
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v{{ version }}
|
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
2019-08-06 08:35:53 -04:00
|
|
|
{% macro header(exercise, props, version) -%}
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
{{ properties(exercise, props) }}
|
|
|
|
|
|
|
|
|
|
{{ canonical_ref(version) }}
|
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
2019-07-29 23:42:12 -05:00
|
|
|
{% macro utility() -%}# Utility functions
|
|
|
|
|
def setUp(self):
|
|
|
|
|
try:
|
|
|
|
|
self.assertRaisesRegex
|
|
|
|
|
except AttributeError:
|
|
|
|
|
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
|
|
|
|
|
|
|
|
def assertRaisesWithMessage(self, exception):
|
|
|
|
|
return self.assertRaisesRegex(exception, r".+")
|
|
|
|
|
{%- endmacro %}
|
2019-08-06 08:35:53 -04:00
|
|
|
|
|
|
|
|
{% macro footer(has_error_case) -%}
|
|
|
|
|
{% if has_error_case %}
|
|
|
|
|
{{ utility() }}
|
|
|
|
|
{% endif %}
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
{%- endmacro %}
|