{#- Python assertion template
Context variables:
- assertion_type: assertion type ("equals", "contains", etc.)
- field_access: Python expression for the field
- field_is_optional: bool
- expected_val: Python-formatted value string (or empty string)
- has_expected_val: bool
- op: "is" or "==" for equality
- is_string_val: bool
- values_list: array of Python-formatted strings
- n: number (as u64) or 0
- cmp_expr: comparison expression for enum/array
- cmp_expr_any: comparison for any containment
- call_expr: method call expression
- check: method_result check type
- check_val: check value (or empty)
- has_check_val: bool
- check_n: number for check (or 0)
- is_boolean_val: bool
- bool_is_true: bool
- bool_val_str: "True" or "False"
#}
{% if assertion_type == "equals" %}
{% if is_string_val %}
{% if is_enum %}
assert _alef_e2e_text({{ field_access }}).lower() {{ op }} {{ expected_val }}.lower() # noqa: S101
{% else %}
assert {{ field_access }}.strip() {{ op }} {{ expected_val }} # noqa: S101
{% endif %}
{% else %}
assert {{ field_access }} {{ op }} {{ expected_val }} # noqa: S101
{% endif %}
{% elif assertion_type == "contains" %}
{% if field_is_optional %}
assert {{ field_access }} is not None # noqa: S101
{% endif %}
assert {{ cmp_expr }} # noqa: S101
{% elif assertion_type == "contains_all" %}
{% for val in values_list %}
{% if field_is_optional %}
assert {{ field_access }} is not None # noqa: S101
{% endif %}
assert {{ val }} # noqa: S101
{% endfor %}
{% elif assertion_type == "not_contains" %}
{% if field_is_optional %}
assert {{ field_access }} is None or not ({{ cmp_expr }}) # noqa: S101
{% else %}
assert not ({{ cmp_expr }}) # noqa: S101
{% endif %}
{% elif assertion_type == "not_empty" %}
assert {{ field_access }} # noqa: S101
{% elif assertion_type == "is_empty" %}
assert not {{ field_access }} # noqa: S101
{% elif assertion_type == "contains_any" %}
{% if field_is_optional %}
assert {{ field_access }} is not None # noqa: S101
{% endif %}
assert {{ cmp_expr_any }} # noqa: S101
{% elif assertion_type == "greater_than" %}
assert {{ field_access }} > {{ expected_val }} # noqa: S101
{% elif assertion_type == "less_than" %}
assert {{ field_access }} < {{ expected_val }} # noqa: S101
{% elif assertion_type == "greater_than_or_equal" or assertion_type == "min" %}
assert {{ field_access }} >= {{ expected_val }} # noqa: S101
{% elif assertion_type == "less_than_or_equal" or assertion_type == "max" %}
assert {{ field_access }} <= {{ expected_val }} # noqa: S101
{% elif assertion_type == "starts_with" %}
assert {{ field_access }}.startswith({{ expected_val }}) # noqa: S101
{% elif assertion_type == "ends_with" %}
assert {{ field_access }}.endswith({{ expected_val }}) # noqa: S101
{% elif assertion_type == "min_length" %}
assert len({{ field_access }}) >= {{ n }} # noqa: S101
{% elif assertion_type == "max_length" %}
assert len({{ field_access }}) <= {{ n }} # noqa: S101
{% elif assertion_type == "count_min" %}
assert len({{ field_access }}) >= {{ n }} # noqa: S101
{% elif assertion_type == "count_equals" %}
assert len({{ field_access }}) == {{ n }} # noqa: S101
{% elif assertion_type == "is_true" %}
assert {{ field_access }} is True # noqa: S101
{% elif assertion_type == "is_false" %}
assert not {{ field_access }} # noqa: S101
{% elif assertion_type == "method_result" %}
{% if check == "equals" %}
{% if is_boolean_val %}
assert {{ call_expr }} is {{ bool_val_str }} # noqa: S101
{% else %}
assert {{ call_expr }} == {{ check_val }} # noqa: S101
{% endif %}
{% elif check == "is_true" %}
assert {{ call_expr }} # noqa: S101
{% elif check == "is_false" %}
assert not {{ call_expr }} # noqa: S101
{% elif check == "greater_than_or_equal" %}
assert {{ call_expr }} >= {{ check_n }} # noqa: S101
{% elif check == "count_min" %}
assert len({{ call_expr }}) >= {{ check_n }} # noqa: S101
{% elif check == "contains" %}
assert {{ check_val }} in {{ call_expr }} # noqa: S101
{% elif check == "is_error" %}
with pytest.raises(Exception): # noqa: B017
{{ call_expr }}
{% endif %}
{% elif assertion_type == "matches_regex" %}
import re # noqa: PLC0415
assert re.search({{ expected_val }}, {{ field_access }}) is not None # noqa: S101
{% endif %}