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
|
||||
branch = True
|
||||
|
||||
|
||||
[report]
|
||||
show_missing = True
|
||||
skip_covered = True
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ usage::
|
|||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||
from functools import partial
|
||||
|
|
@ -58,7 +59,7 @@ def get_src(src: Path, extension=None):
|
|||
def build_output(error):
|
||||
"""Build output for file errors."""
|
||||
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:
|
||||
return 0
|
||||
|
|
@ -94,7 +95,7 @@ def build_check_output(errors, quiet):
|
|||
return 0
|
||||
|
||||
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:
|
||||
echo(
|
||||
|
|
@ -129,7 +130,7 @@ def build_check_output(errors, quiet):
|
|||
|
||||
def build_quantity(size: int):
|
||||
"""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):
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ Djlint Tests.
|
|||
|
||||
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::
|
||||
|
||||
tox
|
||||
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
|
|
@ -210,27 +211,60 @@ def test_W018(runner, tmp_file):
|
|||
assert "W018 1:" in result.output
|
||||
|
||||
|
||||
# assert "asdf" in result.output
|
||||
|
||||
|
||||
def test_check(runner, tmp_file):
|
||||
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 "Linting 1 file!" in result.output
|
||||
# assert "Linted 1 file, found 0 errors" in result.output
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def test_check_django_ledger(runner, tmp_file):
|
||||
# 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 "Linting 120 files!" 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]
|
||||
envlist =
|
||||
clean,
|
||||
test,
|
||||
cov
|
||||
envlist = test
|
||||
skip_missing_interpreters = True
|
||||
isolated_build = True
|
||||
|
||||
|
|
@ -50,24 +47,8 @@ commands =
|
|||
; check-manifest -v
|
||||
skip_install: true
|
||||
|
||||
|
||||
[testenv:clean]
|
||||
skip_install: true
|
||||
deps = coverage
|
||||
commands = coverage erase
|
||||
|
||||
[testenv]
|
||||
deps = .[test]
|
||||
commands =
|
||||
pytest --cov --cov-append --cov-report=term-missing --disable-warnings --junitxml=report.xml
|
||||
depends =
|
||||
test: clean
|
||||
cov: test
|
||||
pytest --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
|
||||
skip_install: true
|
||||
|
||||
[testenv:cov]
|
||||
skip_install: true
|
||||
deps = coverage
|
||||
commands =
|
||||
coverage report -m
|
||||
coverage xml
|
||||
|
|
|
|||
Loading…
Reference in a new issue