mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Ignore coverage for aiohttp_resolver backport helper (#115177)
* Ignore coverage for aiohttp_resolver backport helper * Adjust generate to sort core items * Adjust validate to sort core items * Split line * Apply suggestion Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com> * Fix suggestion --------- Co-authored-by: Dave T <17680170+davet2001@users.noreply.github.com>
This commit is contained in:
parent
6d22dd073c
commit
bea4c52d10
@ -6,11 +6,12 @@
|
|||||||
source = homeassistant
|
source = homeassistant
|
||||||
omit =
|
omit =
|
||||||
homeassistant/__main__.py
|
homeassistant/__main__.py
|
||||||
|
homeassistant/helpers/backports/aiohttp_resolver.py
|
||||||
homeassistant/helpers/signal.py
|
homeassistant/helpers/signal.py
|
||||||
homeassistant/scripts/__init__.py
|
homeassistant/scripts/__init__.py
|
||||||
|
homeassistant/scripts/benchmark/__init__.py
|
||||||
homeassistant/scripts/check_config.py
|
homeassistant/scripts/check_config.py
|
||||||
homeassistant/scripts/ensure_config.py
|
homeassistant/scripts/ensure_config.py
|
||||||
homeassistant/scripts/benchmark/__init__.py
|
|
||||||
homeassistant/scripts/macos/__init__.py
|
homeassistant/scripts/macos/__init__.py
|
||||||
|
|
||||||
# omit pieces of code that rely on external devices being present
|
# omit pieces of code that rely on external devices being present
|
||||||
|
@ -20,24 +20,17 @@ DONT_IGNORE = (
|
|||||||
"scene.py",
|
"scene.py",
|
||||||
)
|
)
|
||||||
|
|
||||||
PREFIX = """# Sorted by hassfest.
|
CORE_PREFIX = """# Sorted by hassfest.
|
||||||
#
|
#
|
||||||
# To sort, run python3 -m script.hassfest -p coverage
|
# To sort, run python3 -m script.hassfest -p coverage
|
||||||
|
|
||||||
[run]
|
[run]
|
||||||
source = homeassistant
|
source = homeassistant
|
||||||
omit =
|
omit =
|
||||||
homeassistant/__main__.py
|
|
||||||
homeassistant/helpers/signal.py
|
|
||||||
homeassistant/scripts/__init__.py
|
|
||||||
homeassistant/scripts/check_config.py
|
|
||||||
homeassistant/scripts/ensure_config.py
|
|
||||||
homeassistant/scripts/benchmark/__init__.py
|
|
||||||
homeassistant/scripts/macos/__init__.py
|
|
||||||
|
|
||||||
# omit pieces of code that rely on external devices being present
|
|
||||||
"""
|
"""
|
||||||
|
COMPONENTS_PREFIX = (
|
||||||
|
" # omit pieces of code that rely on external devices being present\n"
|
||||||
|
)
|
||||||
SUFFIX = """[report]
|
SUFFIX = """[report]
|
||||||
# Regexes for lines to exclude from consideration
|
# Regexes for lines to exclude from consideration
|
||||||
exclude_lines =
|
exclude_lines =
|
||||||
@ -62,6 +55,7 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
coverage_path = config.root / ".coveragerc"
|
coverage_path = config.root / ".coveragerc"
|
||||||
|
|
||||||
not_found: list[str] = []
|
not_found: list[str] = []
|
||||||
|
unsorted: list[str] = []
|
||||||
checking = False
|
checking = False
|
||||||
|
|
||||||
previous_line = ""
|
previous_line = ""
|
||||||
@ -69,6 +63,10 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
for line in fp:
|
for line in fp:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
||||||
|
if line == COMPONENTS_PREFIX.strip():
|
||||||
|
previous_line = ""
|
||||||
|
continue
|
||||||
|
|
||||||
if not line or line.startswith("#"):
|
if not line or line.startswith("#"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -92,27 +90,21 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
not_found.append(line)
|
not_found.append(line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if line < previous_line:
|
||||||
|
unsorted.append(line)
|
||||||
|
previous_line = line
|
||||||
|
|
||||||
if not line.startswith("homeassistant/components/"):
|
if not line.startswith("homeassistant/components/"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
integration_path = path.parent
|
# Ignore sub-directories
|
||||||
while len(integration_path.parts) > 3:
|
|
||||||
integration_path = integration_path.parent
|
|
||||||
|
|
||||||
integration = integrations[integration_path.name]
|
|
||||||
|
|
||||||
# Ensure sorted
|
|
||||||
if line < previous_line:
|
|
||||||
integration.add_error(
|
|
||||||
"coverage",
|
|
||||||
f"{line} is unsorted in .coveragerc file",
|
|
||||||
)
|
|
||||||
previous_line = line
|
|
||||||
|
|
||||||
# Ignore sub-directories for further checks
|
|
||||||
if len(path.parts) > 4:
|
if len(path.parts) > 4:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
integration_path = path.parent
|
||||||
|
|
||||||
|
integration = integrations[integration_path.name]
|
||||||
|
|
||||||
if (
|
if (
|
||||||
path.parts[-1] == "*"
|
path.parts[-1] == "*"
|
||||||
and Path(f"tests/components/{integration.domain}/__init__.py").exists()
|
and Path(f"tests/components/{integration.domain}/__init__.py").exists()
|
||||||
@ -132,6 +124,15 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
f"{check} must not be ignored by the .coveragerc file",
|
f"{check} must not be ignored by the .coveragerc file",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if unsorted:
|
||||||
|
config.add_error(
|
||||||
|
"coverage",
|
||||||
|
"Paths are unsorted in .coveragerc file. "
|
||||||
|
"Run python3 -m script.hassfest\n - "
|
||||||
|
f"{'\n - '.join(unsorted)}",
|
||||||
|
fixable=True,
|
||||||
|
)
|
||||||
|
|
||||||
if not_found:
|
if not_found:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f".coveragerc references files that don't exist: {', '.join(not_found)}."
|
f".coveragerc references files that don't exist: {', '.join(not_found)}."
|
||||||
@ -141,23 +142,31 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
|
|||||||
def generate(integrations: dict[str, Integration], config: Config) -> None:
|
def generate(integrations: dict[str, Integration], config: Config) -> None:
|
||||||
"""Sort coverage."""
|
"""Sort coverage."""
|
||||||
coverage_path = config.root / ".coveragerc"
|
coverage_path = config.root / ".coveragerc"
|
||||||
lines = []
|
core = []
|
||||||
start = False
|
components = []
|
||||||
|
section = "header"
|
||||||
|
|
||||||
with coverage_path.open("rt") as fp:
|
with coverage_path.open("rt") as fp:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
if (
|
if line == "[report]\n":
|
||||||
not start
|
|
||||||
and line
|
|
||||||
== " # omit pieces of code that rely on external devices being present\n"
|
|
||||||
):
|
|
||||||
start = True
|
|
||||||
elif line == "[report]\n":
|
|
||||||
break
|
break
|
||||||
elif start and line != "\n":
|
|
||||||
lines.append(line)
|
|
||||||
|
|
||||||
content = f"{PREFIX}{"".join(sorted(lines))}\n\n{SUFFIX}"
|
if section != "core" and line == "omit =\n":
|
||||||
|
section = "core"
|
||||||
|
elif section != "components" and line == COMPONENTS_PREFIX:
|
||||||
|
section = "components"
|
||||||
|
elif section == "core" and line != "\n":
|
||||||
|
core.append(line)
|
||||||
|
elif section == "components" and line != "\n":
|
||||||
|
components.append(line)
|
||||||
|
|
||||||
|
assert core, "core should be a non-empty list"
|
||||||
|
assert components, "components should be a non-empty list"
|
||||||
|
content = (
|
||||||
|
f"{CORE_PREFIX}{"".join(sorted(core))}\n"
|
||||||
|
f"{COMPONENTS_PREFIX}{"".join(sorted(components))}\n"
|
||||||
|
f"\n{SUFFIX}"
|
||||||
|
)
|
||||||
|
|
||||||
with coverage_path.open("w") as fp:
|
with coverage_path.open("w") as fp:
|
||||||
fp.write(content)
|
fp.write(content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user