testsAndMisc/linux_configuration/tests/test_usage_report_pmon_names.py
Krzysztof kuhy Rudnicki 038e08d2be feat: split oversized modules for 500-line limit, fix kasa coverage gap
Split diet_guard/_gatelock.py, wake_alarm/_alarm.py, and the
usage_report.py/_usage_report_parsing.py pair into focused
sub-modules so every Python file is <= 500 lines, satisfying
test_file_length.py. Install python-kasa into .venv (declared in
requirements but missing after the 3.13->3.14 venv upgrade),
fixing 8 failing smart_plug tests and restoring 100% coverage.

Also includes prior in-progress work from the working tree: the
wake_alarm Progress/View/Hardware field-grouping refactor,
brother_printer query module + tests, diet_guard foodbank/state/cli
updates, new shared coerce/logging_setup helpers, morning_routine
orchestrator tweaks, dwm window-manager config, gaming scripts, and
misc maintenance/digital-wellbeing script updates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 07:19:37 +02:00

77 lines
1.8 KiB
Python

"""Regression tests for pmon process-name normalization in usage_report."""
from __future__ import annotations
from typing import TYPE_CHECKING
import _usage_report_pmon as pmon
if TYPE_CHECKING:
import pytest
def test_normalize_pmon_command_prefers_first_executable_token() -> None:
"""The parser should keep executable-like token, not trailing args."""
tokens = ["code-insiders", "--type=", "gpu-process", "Not"]
assert pmon._normalize_pmon_command(tokens) == "code-insiders"
def test_normalize_pmon_command_skips_leading_option_tokens() -> None:
"""If the first token is an option, use the next non-option token."""
tokens = ["--type=", "code-insiders", "--flag"]
assert pmon._normalize_pmon_command(tokens) == "code-insiders"
def test_ingest_pmon_row_uses_command_field_start_not_last_token() -> None:
"""Rows with command args should aggregate under process name, not args."""
row = [
"20260507",
"12:00:00",
"0",
"123",
"C",
"10",
"5",
"0",
"0",
"0",
"0",
"code-insiders",
"--type=",
"gpu-process",
]
agg: dict[str, object] = {}
consumed = pmon._ingest_pmon_row(row, agg)
assert consumed == 1
assert "code-insiders" in agg
def test_ingest_pmon_row_falls_back_to_proc_comm_on_unknown(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""When command field is empty, parser can recover with /proc/<pid>/comm."""
row = [
"20260507",
"12:00:00",
"0",
"999",
"C",
"30",
"10",
"0",
"0",
"0",
"0",
]
agg: dict[str, object] = {}
monkeypatch.setattr(pmon, "_pid_comm_name", lambda _pid: "python")
consumed = pmon._ingest_pmon_row(row, agg)
assert consumed == 1
assert "python" in agg