djLint/tests/test_django/test_if.py
2022-05-13 15:36:55 -05:00

40 lines
1.1 KiB
Python

"""Djlint tests specific to django.
run::
pytest tests/test_django.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
pytest tests/test_django.py::test_alpine_js --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
"""
# pylint: disable=C0116
from typing import TextIO
from click.testing import CliRunner
from tests.conftest import reformat
def test_if(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""{% if athlete_list %}Number of athletes: {{ athlete_list|length }}{% elif athlete_in_locker_room_list %}Athletes should be out of the locker room soon!{% else %}No athletes.{% endif %}""",
)
assert output.exit_code == 1
assert (
output.text
== r"""{% if athlete_list %}
Number of athletes: {{ athlete_list|length }}
{% elif athlete_in_locker_room_list %}
Athletes should be out of the locker room soon!
{% else %}
No athletes.
{% endif %}
"""
)