mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-16 21:40:24 +00:00
fixed test coverage
This commit is contained in:
parent
582f40b6b1
commit
41e95ce63b
4 changed files with 45 additions and 30 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
source = src/djlint
|
source = src/djlint
|
||||||
branch = True
|
branch = True
|
||||||
|
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
show_missing = True
|
show_missing = True
|
||||||
skip_covered = True
|
skip_covered = True
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ usage::
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
@ -58,7 +59,7 @@ def get_src(src: Path, extension=None):
|
||||||
def build_output(error):
|
def build_output(error):
|
||||||
"""Build output for file errors."""
|
"""Build output for file errors."""
|
||||||
errors = sorted(list(error.values())[0], key=lambda x: int(x["line"].split(":")[0]))
|
errors = sorted(list(error.values())[0], key=lambda x: int(x["line"].split(":")[0]))
|
||||||
width, _ = click.get_terminal_size()
|
width, _ = shutil.get_terminal_size()
|
||||||
|
|
||||||
if len(errors) == 0:
|
if len(errors) == 0:
|
||||||
return 0
|
return 0
|
||||||
|
|
@ -94,7 +95,7 @@ def build_check_output(errors, quiet):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
color = {"-": Fore.YELLOW, "+": Fore.GREEN, "@": Style.BRIGHT + Fore.BLUE}
|
color = {"-": Fore.YELLOW, "+": Fore.GREEN, "@": Style.BRIGHT + Fore.BLUE}
|
||||||
width, _ = click.get_terminal_size()
|
width, _ = shutil.get_terminal_size()
|
||||||
|
|
||||||
if quiet is True and len(list(errors.values())[0]) > 0:
|
if quiet is True and len(list(errors.values())[0]) > 0:
|
||||||
echo(
|
echo(
|
||||||
|
|
@ -129,7 +130,7 @@ def build_check_output(errors, quiet):
|
||||||
|
|
||||||
def build_quantity(size: int):
|
def build_quantity(size: int):
|
||||||
"""Count files in a list."""
|
"""Count files in a list."""
|
||||||
return "%d file%s" % (size, ("s" if size > 1 else ""))
|
return "%d file%s" % (size, ("s" if size > 1 or size == 0 else ""))
|
||||||
|
|
||||||
|
|
||||||
def build_quantity_tense(size: int):
|
def build_quantity_tense(size: int):
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ Djlint Tests.
|
||||||
|
|
||||||
run::
|
run::
|
||||||
|
|
||||||
coverage erase; coverage run -m pytest; coverage report -m
|
pytest --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||||
|
|
||||||
or::
|
or::
|
||||||
|
|
||||||
tox
|
tox
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -210,27 +211,60 @@ def test_W018(runner, tmp_file):
|
||||||
assert "W018 1:" in result.output
|
assert "W018 1:" in result.output
|
||||||
|
|
||||||
|
|
||||||
|
# assert "asdf" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_check(runner, tmp_file):
|
def test_check(runner, tmp_file):
|
||||||
write_to_file(tmp_file.name, b"<div></div>")
|
write_to_file(tmp_file.name, b"<div></div>")
|
||||||
result = runner.invoke(djlint, [tmp_file.name], "--check")
|
result = runner.invoke(djlint, [tmp_file.name, "--check"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
# assert "Linting 1 file!" in result.output
|
# assert "Linting 1 file!" in result.output
|
||||||
# assert "Linted 1 file, found 0 errors" in result.output
|
# assert "Linted 1 file, found 0 errors" in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_check_non_existing_file(runner, tmp_file):
|
def test_check_non_existing_file(runner, tmp_file):
|
||||||
result = runner.invoke(djlint, "tests/nothing.html", "--check")
|
result = runner.invoke(djlint, ["tests/nothing.html", "--check"])
|
||||||
assert result.exit_code == 2
|
assert result.exit_code == 2
|
||||||
|
|
||||||
|
|
||||||
def test_check_non_existing_folder(runner, tmp_file):
|
def test_check_non_existing_folder(runner, tmp_file):
|
||||||
result = runner.invoke(djlint, "tests/nothing", "--check")
|
result = runner.invoke(djlint, ["tests/nothing", "--check"])
|
||||||
assert result.exit_code == 2
|
assert result.exit_code == 2
|
||||||
|
|
||||||
|
|
||||||
def test_check_django_ledger(runner, tmp_file):
|
def test_check_django_ledger(runner, tmp_file):
|
||||||
# source from https://github.com/arrobalytics/django-ledger
|
# source from https://github.com/arrobalytics/django-ledger
|
||||||
result = runner.invoke(djlint, "tests/django_ledger", "--check")
|
result = runner.invoke(djlint, ["tests/django_ledger", "--check"])
|
||||||
assert result.exit_code == 0
|
assert result.exit_code == 0
|
||||||
# assert "Linting 120 files!" in result.output
|
# assert "Linting 120 files!" in result.output
|
||||||
# assert "0 files were updated." in result.output
|
# assert "0 files were updated." in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_reformatter_simple_error(runner, tmp_file):
|
||||||
|
write_to_file(tmp_file.name, b"<div><p>nice stuff here</p></div>")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--check"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "1 file would be updated." in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_reformatter_simple_error(runner, tmp_file):
|
||||||
|
write_to_file(tmp_file.name, b"<div><p>nice stuff here</p></div>")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "1 file was updated." in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_reformatter_simple_error_quiet(runner, tmp_file):
|
||||||
|
write_to_file(tmp_file.name, b"<div><p>nice stuff here</p></div>")
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--check", "--quiet"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "1 file would be updated." in result.output
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_reformatter_no_error(runner, tmp_file):
|
||||||
|
write_to_file(
|
||||||
|
tmp_file.name, b"<div>\n <p>\n nice stuff here\n </p>\n</div>"
|
||||||
|
)
|
||||||
|
result = runner.invoke(djlint, [tmp_file.name, "--check"])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
assert "0 files would be updated." in result.output
|
||||||
|
|
|
||||||
23
tox.ini
23
tox.ini
|
|
@ -1,8 +1,5 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist =
|
envlist = test
|
||||||
clean,
|
|
||||||
test,
|
|
||||||
cov
|
|
||||||
skip_missing_interpreters = True
|
skip_missing_interpreters = True
|
||||||
isolated_build = True
|
isolated_build = True
|
||||||
|
|
||||||
|
|
@ -50,24 +47,8 @@ commands =
|
||||||
; check-manifest -v
|
; check-manifest -v
|
||||||
skip_install: true
|
skip_install: true
|
||||||
|
|
||||||
|
|
||||||
[testenv:clean]
|
|
||||||
skip_install: true
|
|
||||||
deps = coverage
|
|
||||||
commands = coverage erase
|
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps = .[test]
|
deps = .[test]
|
||||||
commands =
|
commands =
|
||||||
pytest --cov --cov-append --cov-report=term-missing --disable-warnings --junitxml=report.xml
|
pytest --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||||
depends =
|
|
||||||
test: clean
|
|
||||||
cov: test
|
|
||||||
skip_install: true
|
skip_install: true
|
||||||
|
|
||||||
[testenv:cov]
|
|
||||||
skip_install: true
|
|
||||||
deps = coverage
|
|
||||||
commands =
|
|
||||||
coverage report -m
|
|
||||||
coverage xml
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue