test(yaml): added more yaml tests

This commit is contained in:
Christopher Pickering 2022-05-13 15:49:24 -05:00
parent 98e20ee885
commit eec497d043
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 77 additions and 10 deletions

View file

@ -20,16 +20,7 @@ from src.djlint import main as djlint
from tests.conftest import reformat, write_to_file
def test_front_matter(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""---
layout: <div><div></div></div>
---
<div></div>""",
)
assert output.exit_code == 0
def test_code_tag(runner: CliRunner, tmp_file: TextIO) -> None:

View file

@ -0,0 +1,76 @@
"""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 pathlib import Path
from typing import TextIO
from click.testing import CliRunner
from src.djlint import main as djlint
from tests.conftest import reformat, write_to_file
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