forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator_macros.j2
46 lines (39 loc) · 1.21 KB
/
generator_macros.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{# 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() -%}
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/{{ exercise }}/canonical-data.json
# File last updated on {{ current_date }}
{%- 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 %})
{%- endmacro %}
{% macro utility() -%}# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
{%- endmacro %}
{% macro empty_set(set, list, class_name) -%}
{%- if list|length > 0 -%}
{{ set }} = {{ class_name }}({{ list }})
{%- else -%}
{{ set }} = {{ class_name }}()
{%- endif %}
{%- endmacro %}