{%- import "generator_macros.j2" as macros with context -%}

{% macro test_case(case) %}
    {%- set input = case["input"] %}
    {%- set expected = case["expected"] %}
    {%- set exp_error = expected["error"]  %}
    def test_{{ case["description"] | to_snake }}(self):
    {%- if case is error_case %}
        with self.assertRaises(ValueError) as err:
            {{ case["property"] | to_snake }}({{ input["square"] }})
        self.assertEqual(type(err.exception), ValueError)
        self.assertEqual(err.exception.args[0], "{{ exp_error }}")
    {%- else%}
          self.assertEqual({{ case["property"] | to_snake }}(
            {{ input["square"] }}), {{ case["expected"] }})
    {% endif %}
{%- endmacro %}

{{ macros.header()}}

class {{ exercise | camel_case }}Test(unittest.TestCase):
    {% for case in cases -%}
        {%- if "cases" in case -%} 
        {% for subcase in case['cases'] -%}      
        {{ test_case(subcase) }}
        {% endfor %}
        {%-else%}
        {{test_case(case)}}
        {%-endif%}
    {% endfor %}
    