Validate coveragerc with hassfest (#31112)

* Validate coveragerc

* Test if files exists

* Print progress

* Flush
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-01-24 10:25:46 -08:00
1 parent 7e4b9adc3d
commit 98bac43228
3 files changed
+64 -10

No files matched your search

+14 -1
View File
@@ -1,10 +1,12 @@
"""Validate manifests."""
import pathlib
import sys
from time import monotonic
from . import (
codeowners,
config_flow,
coverage,
dependencies,
json,
manifest,
@@ -18,6 +20,7 @@ PLUGINS = [
json,
codeowners,
config_flow,
coverage,
dependencies,
manifest,
services,
@@ -48,7 +51,17 @@ def main():
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
for plugin in PLUGINS:
plugin.validate(integrations, config)
try:
start = monotonic()
print(f"Validating {plugin.__name__.split('.')[-1]}...", end="", flush=True)
plugin.validate(integrations, config)
print(" done in {:.2f}s".format(monotonic() - start))
except RuntimeError as err:
print()
print()
print("Error!")
print(err)
return 1
# When we generate, all errors that are fixable will be ignored,
# as generating them will be fixed.
+50
View File
@@ -0,0 +1,50 @@
"""Validate coverage files."""
from pathlib import Path
from typing import Dict
from .model import Config, Integration
def validate(integrations: Dict[str, Integration], config: Config):
"""Validate coverage."""
coverage_path = config.root / ".coveragerc"
not_found = []
checking = False
with coverage_path.open("rt") as fp:
for line in fp:
line = line.strip()
if not line or line.startswith("#"):
continue
if not checking:
if line == "omit =":
checking = True
continue
# Finished
if line == "[report]":
break
path = Path(line)
# Discard wildcard
while "*" in path.name:
path = path.parent
if not path.exists():
not_found.append(line)
if not not_found:
return
errors = []
if not_found:
errors.append(
f".coveragerc references files that don't exist: {', '.join(not_found)}."
)
raise RuntimeError(" ".join(errors))