From a124a4dd6d56d020637f1ce34133d9eb7a610cbe Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 13 May 2022 16:11:06 -0500 Subject: [PATCH] test(html tests): restructured tests --- tests/test_html/test_attributes.py | 101 ++++ tests/test_html/test_aurelia.py | 40 ++ tests/test_html/test_comments.py | 39 ++ tests/test_html/test_html.py | 609 -------------------- tests/test_html/test_ignored.py | 151 +++++ tests/test_html/test_selfclosing.py | 64 ++ tests/test_html/test_tag_code.py | 32 + tests/test_html/test_tag_dd.py | 35 ++ tests/test_html/test_tag_details_summary.py | 38 ++ tests/test_html/test_tag_dt.py | 35 ++ tests/test_html/test_tag_fig_caption.py | 38 ++ tests/test_html/test_tag_hr.py | 45 ++ tests/test_html/test_tag_picture.py | 38 ++ tests/test_html/test_tag_pre.py | 36 ++ tests/test_html/test_tag_script.py | 72 +++ tests/test_html/test_tag_small.py | 33 ++ tests/test_html/test_tag_span.py | 48 ++ tests/test_html/test_tag_textarea.py | 93 +++ tests/test_html/test_yaml.py | 16 +- 19 files changed, 949 insertions(+), 614 deletions(-) create mode 100644 tests/test_html/test_attributes.py create mode 100644 tests/test_html/test_aurelia.py create mode 100644 tests/test_html/test_comments.py delete mode 100644 tests/test_html/test_html.py create mode 100644 tests/test_html/test_ignored.py create mode 100644 tests/test_html/test_selfclosing.py create mode 100644 tests/test_html/test_tag_code.py create mode 100644 tests/test_html/test_tag_dd.py create mode 100644 tests/test_html/test_tag_details_summary.py create mode 100644 tests/test_html/test_tag_dt.py create mode 100644 tests/test_html/test_tag_fig_caption.py create mode 100644 tests/test_html/test_tag_hr.py create mode 100644 tests/test_html/test_tag_picture.py create mode 100644 tests/test_html/test_tag_pre.py create mode 100644 tests/test_html/test_tag_script.py create mode 100644 tests/test_html/test_tag_small.py create mode 100644 tests/test_html/test_tag_span.py create mode 100644 tests/test_html/test_tag_textarea.py diff --git a/tests/test_html/test_attributes.py b/tests/test_html/test_attributes.py new file mode 100644 index 0000000..759668d --- /dev/null +++ b/tests/test_html/test_attributes.py @@ -0,0 +1,101 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --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_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""""", + ) + + assert output.exit_code == 1 + + assert ( + output.text + == """ +""" + ) + + # check styles + output = reformat( + tmp_file, + runner, + b"""
+""", + ) + + assert output.exit_code == 0 + + # check styles when tag is first + output = reformat( + tmp_file, + runner, + b"""
+
+
+
+""", + ) + assert output.exit_code == 0 + + +def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""
+
""", + ) + + assert output.exit_code == 1 + print(output.text) + assert ( + output.text + == """
\n
+""" + ) diff --git a/tests/test_html/test_aurelia.py b/tests/test_html/test_aurelia.py new file mode 100644 index 0000000..404362f --- /dev/null +++ b/tests/test_html/test_aurelia.py @@ -0,0 +1,40 @@ +"""Djlint tests specific to aurelia. + +Some tests may be from prettier.io's html test suite. + +Where applicable this notice may be needed: + +#### Prettier.io license #### +Copyright © James Long and contributors +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +run:: + + poetry run pytest tests/test_html/test_aurelia.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + poetry run pytest tests/test_html/test_aurelia.py::test_aurelia + +""" +# pylint: disable=C0116 +from typing import TextIO + +from click.testing import CliRunner + +from tests.conftest import reformat + + +def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None: + + output = reformat( + tmp_file, + runner, + b""" +""", + ) + + assert output.exit_code == 0 diff --git a/tests/test_html/test_comments.py b/tests/test_html/test_comments.py new file mode 100644 index 0000000..a3cd291 --- /dev/null +++ b/tests/test_html/test_comments.py @@ -0,0 +1,39 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
\n
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ +
+""" + ) diff --git a/tests/test_html/test_html.py b/tests/test_html/test_html.py deleted file mode 100644 index 32b8838c..0000000 --- a/tests/test_html/test_html.py +++ /dev/null @@ -1,609 +0,0 @@ -"""Djlint tests specific to html. - -run:: - - pytest tests/test_html.py --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ - --cov-report xml:coverage.xml --cov-report term-missing - - -""" -# 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_code_tag(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b"""
    -
  1. - a b -
  2. -
""", - ) - assert output.exit_code == 0 - - -def test_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None: - # added for https://github.com/Riverside-Healthcare/djLint/issues/187 - output = reformat( - tmp_file, - runner, - b"""{% if a %} -
-
asdf
-
asdf
-            
- -

title

-
-{% endif %}""", - ) - assert output.exit_code == 0 - - # def test_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None: - # write_to_file(tmp_file.name, b"""
""") - # runner.invoke(djlint, [tmp_file.name, "--reformat"]) - # assert ( - # Path(tmp_file.name).read_text(encoding="utf8") - # == """
- # - #
- # """ - # ) - # # check double nesting - # output = reformat( - # tmp_file, - # runner, - # b"""
- #
- # - #
- #
- # """, - # ) - - # assert output.exit_code == 0 - - # # check attributes - # output = reformat( - # tmp_file, - # runner, - # b"""
- #
- # - #
- #
- # """, - # ) - - # assert ( - # output.text - # == """
- #
- # - #
- #
- # """ - # ) - - # def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None: - # output = reformat( - # tmp_file, - # runner, - # b"""

- # some nice text asdf, ok - #

""", - # ) - - # assert output.exit_code == 0 - - # # test added for https://github.com/Riverside-Healthcare/djLint/issues/189 - # output = reformat( - # tmp_file, - # runner, - # b""" - # hihi - #
- #

{{ _("Options") }}

- #
- # """) - - assert output.exit_code == 0 - - -def test_script_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
\n \n
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- -
-""" - ) - - # check script includes - output = reformat( - tmp_file, - runner, - b"""""", - ) - - assert output.exit_code == 0 - - output = reformat( - tmp_file, - runner, - b""" -""", - ) - - assert output.exit_code == 0 - - # check bad template tags inside scripts - output = reformat( - tmp_file, - runner, - b"""\n""", - ) - - assert output.exit_code == 0 - - -def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
\n
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- -
-""" - ) - - -def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b"""""", - ) - - assert output.exit_code == 1 - - assert ( - output.text - == """ -""" - ) - - # check styles - output = reformat( - tmp_file, - runner, - b"""
-""", - ) - - assert output.exit_code == 0 - - # check styles when tag is first - output = reformat( - tmp_file, - runner, - b"""
-
-
-
-""", - ) - assert output.exit_code == 0 - - -def test_small_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""text""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """text -""" - ) - - -def test_dd_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
text
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- text -
-""" - ) - - -def test_hr_tag(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b"""
-
-
-
-
-""", - ) - assert output.exit_code == 0 - - output = reformat( - tmp_file, - runner, - b"""
-
-
-
-
-""", - ) - - assert output.exit_code == 0 - - -# def test_span_tag(runner: CliRunner, tmp_file: TextIO) -> None: -# write_to_file( -# tmp_file.name, -# b"""""", -# ) -# runner.invoke(djlint, [tmp_file.name, "--reformat"]) -# assert ( -# Path(tmp_file.name).read_text(encoding="utf8") -# == """ -# """ -# ) - -# # issue #171, span is an inline tag -# output = reformat( -# tmp_file, -# runner, -# b"""
-#
-#

-# Hello stranger, do not wrap span, pls. -# Hello stranger, do not wrap span, pls. -#

-#
-#
""", -# ) # noqa: E501 -# assert output.exit_code == 0 - - -def test_dt_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
text
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- text -
-""" - ) - - -def test_details_summary_tags(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
summarybody
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- - summary - - body -
-""" - ) - - -def test_figure_figcaption_tags(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""
caption
""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """
- -
- caption -
-
-""" - ) - - -def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b"""
-
""", - ) - - assert output.exit_code == 1 - print(output.text) - assert ( - output.text - == """
\n
-""" - ) - - -def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""\ -image""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """ - - image - -""" - ) - - -def test_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b""" -

- - """, - ) - - assert output.exit_code == 1 - - assert ( - output.text - == """ -
-

- -

-
- -""" - ) - - # check custom ignore tag {# djlint:off #} {# djlint:on #} - output = reformat( - tmp_file, - runner, - b""" -

- -{# djlint:off #} -

-{# djlint:on #} -{% comment %} djlint:off {% endcomment %} -

-{% comment %} djlint:on {% endcomment %} -{{ /* djlint:off */ }} -

-{{ /* djlint:on */ }} -{{!-- djlint:off --}} -

-{{!-- djlint:on --}} -""", - ) - - assert output.exit_code == 0 - - output = reformat( - tmp_file, - runner, - b"""{# djlint: off #}{# djlint:on #} -""", - ) - - assert output.exit_code == 0 - - # check script tag - output = reformat( - tmp_file, - runner, - b""" -""", - ) - - assert output.exit_code == 0 - - assert ( - """ -""" - in output.text - ) - - # check inline script includes - output = reformat( - tmp_file, - runner, - b""" - - - - - - -""", - ) - print(output.text) - assert output.exit_code == 0 - - -def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( - tmp_file, - runner, - b""" -""", - ) - - assert output.exit_code == 0 - - output = reformat( - tmp_file, - runner, - b""" -""", - ) - - assert output.exit_code == 0 - - # check style includes - output = reformat( - tmp_file, - runner, - b"""""", - ) - - assert output.exit_code == 0 - - -def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""

Hello
World

""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """

- Hello -
- - - - - - World -

-""" - ) - - -def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None: - write_to_file( - tmp_file.name, - b"""

Hello
World

""", - ) - runner.invoke(djlint, [tmp_file.name, "--reformat"]) - assert ( - Path(tmp_file.name).read_text(encoding="utf8") - == """

- Hello -
- - - - - - World -

-""" - ) diff --git a/tests/test_html/test_ignored.py b/tests/test_html/test_ignored.py new file mode 100644 index 0000000..ddb397a --- /dev/null +++ b/tests/test_html/test_ignored.py @@ -0,0 +1,151 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --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_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b""" +

+ + """, + ) + + assert output.exit_code == 1 + + assert ( + output.text + == """ +
+

+ +

+
+ +""" + ) + + # check custom ignore tag {# djlint:off #} {# djlint:on #} + output = reformat( + tmp_file, + runner, + b""" +

+ +{# djlint:off #} +

+{# djlint:on #} +{% comment %} djlint:off {% endcomment %} +

+{% comment %} djlint:on {% endcomment %} +{{ /* djlint:off */ }} +

+{{ /* djlint:on */ }} +{{!-- djlint:off --}} +

+{{!-- djlint:on --}} +""", + ) + + assert output.exit_code == 0 + + output = reformat( + tmp_file, + runner, + b"""{# djlint: off #}{# djlint:on #} +""", + ) + + assert output.exit_code == 0 + + # check script tag + output = reformat( + tmp_file, + runner, + b""" +""", + ) + + assert output.exit_code == 0 + + assert ( + """ +""" + in output.text + ) + + # check inline script includes + output = reformat( + tmp_file, + runner, + b""" + + + + + + +""", + ) + print(output.text) + assert output.exit_code == 0 + + +def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b""" +""", + ) + + assert output.exit_code == 0 + + output = reformat( + tmp_file, + runner, + b""" +""", + ) + + assert output.exit_code == 0 + + # check style includes + output = reformat( + tmp_file, + runner, + b"""""", + ) + + assert output.exit_code == 0 diff --git a/tests/test_html/test_selfclosing.py b/tests/test_html/test_selfclosing.py new file mode 100644 index 0000000..066fec4 --- /dev/null +++ b/tests/test_html/test_selfclosing.py @@ -0,0 +1,64 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""

Hello
World

""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """

+ Hello +
+ + + + + + World +

+""" + ) + + +def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""

Hello
World

""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """

+ Hello +
+ + + + + + World +

+""" + ) diff --git a/tests/test_html/test_tag_code.py b/tests/test_html/test_tag_code.py new file mode 100644 index 0000000..121bde8 --- /dev/null +++ b/tests/test_html/test_tag_code.py @@ -0,0 +1,32 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --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_code_tag(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""
    +
  1. + a b +
  2. +
""", + ) + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_dd.py b/tests/test_html/test_tag_dd.py new file mode 100644 index 0000000..962429f --- /dev/null +++ b/tests/test_html/test_tag_dd.py @@ -0,0 +1,35 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_dd_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
text
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ text +
+""" + ) diff --git a/tests/test_html/test_tag_details_summary.py b/tests/test_html/test_tag_details_summary.py new file mode 100644 index 0000000..c9b21de --- /dev/null +++ b/tests/test_html/test_tag_details_summary.py @@ -0,0 +1,38 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_details_summary_tags(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
summarybody
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ + summary + + body +
+""" + ) diff --git a/tests/test_html/test_tag_dt.py b/tests/test_html/test_tag_dt.py new file mode 100644 index 0000000..33fb63c --- /dev/null +++ b/tests/test_html/test_tag_dt.py @@ -0,0 +1,35 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_dt_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
text
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ text +
+""" + ) diff --git a/tests/test_html/test_tag_fig_caption.py b/tests/test_html/test_tag_fig_caption.py new file mode 100644 index 0000000..22fcf3d --- /dev/null +++ b/tests/test_html/test_tag_fig_caption.py @@ -0,0 +1,38 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_figure_figcaption_tags(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
caption
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ +
+ caption +
+
+""" + ) diff --git a/tests/test_html/test_tag_hr.py b/tests/test_html/test_tag_hr.py new file mode 100644 index 0000000..ce72c57 --- /dev/null +++ b/tests/test_html/test_tag_hr.py @@ -0,0 +1,45 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --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_hr_tag(runner: CliRunner, tmp_file: TextIO) -> None: + output = reformat( + tmp_file, + runner, + b"""
+
+
+
+
+""", + ) + assert output.exit_code == 0 + + output = reformat( + tmp_file, + runner, + b"""
+
+
+
+
+""", + ) + + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_picture.py b/tests/test_html/test_tag_picture.py new file mode 100644 index 0000000..c7d5d50 --- /dev/null +++ b/tests/test_html/test_tag_picture.py @@ -0,0 +1,38 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""\ +image""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """ + + image + +""" + ) diff --git a/tests/test_html/test_tag_pre.py b/tests/test_html/test_tag_pre.py new file mode 100644 index 0000000..f4edba2 --- /dev/null +++ b/tests/test_html/test_tag_pre.py @@ -0,0 +1,36 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --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_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None: + # added for https://github.com/Riverside-Healthcare/djLint/issues/187 + output = reformat( + tmp_file, + runner, + b"""{% if a %} +
+
asdf
+
asdf
+            
+ +

title

+
+{% endif %}""", + ) + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_script.py b/tests/test_html/test_tag_script.py new file mode 100644 index 0000000..72d47b9 --- /dev/null +++ b/tests/test_html/test_tag_script.py @@ -0,0 +1,72 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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_script_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""
\n \n
""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """
+ +
+""" + ) + + # check script includes + output = reformat( + tmp_file, + runner, + b"""""", + ) + + assert output.exit_code == 0 + + output = reformat( + tmp_file, + runner, + b""" +""", + ) + + assert output.exit_code == 0 + + # check bad template tags inside scripts + output = reformat( + tmp_file, + runner, + b"""\n""", + ) + + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_small.py b/tests/test_html/test_tag_small.py new file mode 100644 index 0000000..f16ef1c --- /dev/null +++ b/tests/test_html/test_tag_small.py @@ -0,0 +1,33 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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 write_to_file + + +def test_small_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""text""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """text +""" + ) diff --git a/tests/test_html/test_tag_span.py b/tests/test_html/test_tag_span.py new file mode 100644 index 0000000..36f1dbb --- /dev/null +++ b/tests/test_html/test_tag_span.py @@ -0,0 +1,48 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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_span_tag(runner: CliRunner, tmp_file: TextIO) -> None: + write_to_file( + tmp_file.name, + b"""""", + ) + runner.invoke(djlint, [tmp_file.name, "--reformat"]) + assert ( + Path(tmp_file.name).read_text(encoding="utf8") + == """ +""" + ) + + # issue #171, span is an inline tag + output = reformat( + tmp_file, + runner, + b"""
+
+

+ Hello stranger, do not wrap span, pls. + Hello stranger, do not wrap span, pls. +

+
+
""", + ) # noqa: E501 + assert output.exit_code == 0 diff --git a/tests/test_html/test_tag_textarea.py b/tests/test_html/test_tag_textarea.py new file mode 100644 index 0000000..274c6f4 --- /dev/null +++ b/tests/test_html/test_tag_textarea.py @@ -0,0 +1,93 @@ +"""Djlint tests specific to html. + +run:: + + pytest tests/test_html.py --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \ + --cov-report xml:coverage.xml --cov-report term-missing + + +""" +# 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_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None: +# write_to_file(tmp_file.name, b"""
""") +# runner.invoke(djlint, [tmp_file.name, "--reformat"]) +# assert ( +# Path(tmp_file.name).read_text(encoding="utf8") +# == """
+# +#
+# """ +# ) +# # check double nesting +# output = reformat( +# tmp_file, +# runner, +# b"""
+#
+# +#
+#
+# """, +# ) + +# assert output.exit_code == 0 + +# # check attributes +# output = reformat( +# tmp_file, +# runner, +# b"""
+#
+# +#
+#
+# """, +# ) + +# assert ( +# output.text +# == """
+#
+# +#
+#
+# """ +# ) + +# def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None: +# output = reformat( +# tmp_file, +# runner, +# b"""

+# some nice text asdf, ok +#

""", +# ) + +# assert output.exit_code == 0 + +# # test added for https://github.com/Riverside-Healthcare/djLint/issues/189 +# output = reformat( +# tmp_file, +# runner, +# b""" +# hihi +#
+#

{{ _("Options") }}

+#
+# """) + +# assert output.exit_code == 0 diff --git a/tests/test_html/test_yaml.py b/tests/test_html/test_yaml.py index 3206878..1f81d03 100644 --- a/tests/test_html/test_yaml.py +++ b/tests/test_html/test_yaml.py @@ -9,13 +9,12 @@ run: """ # 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 +from tests.conftest import reformat + def test_invalid(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat( @@ -30,7 +29,9 @@ invalid: """, ) - assert output.text == """--- + assert ( + output.text + == """--- invalid: invalid: --- @@ -41,6 +42,7 @@ invalid: """ + ) def test_valid(runner: CliRunner, tmp_file: TextIO) -> None: @@ -53,7 +55,9 @@ hello: world --- """, ) - assert output.text == """--- + assert ( + output.text + == """--- hello: world --- @@ -63,6 +67,8 @@ hello: world """ + ) + def test_more(runner: CliRunner, tmp_file: TextIO) -> None: output = reformat(