djLint/tests/test_html/test_yaml.py
2022-05-13 16:11:06 -05:00

82 lines
1.3 KiB
Python

"""DjLint tests for yaml front matter.
run:
pytest tests/test_html/test_yaml.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_yaml.py
"""
# pylint: disable=C0116
from typing import TextIO
from click.testing import CliRunner
from tests.conftest import reformat
def test_invalid(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""---
invalid:
invalid:
---
<html><head></head><body></body></html>""",
)
assert (
output.text
== """---
invalid:
invalid:
---
<html>
<head>
</head>
<body>
</body>
</html>
"""
)
def test_valid(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""
---
hello: world
---
<html><head></head><body></body></html>""",
)
assert (
output.text
== """---
hello: world
---
<html>
<head>
</head>
<body>
</body>
</html>
"""
)
def test_more(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""---
layout: <div><div></div></div>
---
<div></div>""",
)
assert output.exit_code == 0