Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ jobs:

- name: Run tests with coverage
run: |
pytest tests/ --tb=short \
--cov=src \
--cov-report=term-missing \
--cov-report=lcov:coverage/lcov.info \
--cov-fail-under=100
pytest tests/ --tb=short

- name: Upload to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage/lcov.info
flags: unittests
slug: ${{ github.repository }}
disable_search: true
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ omit = [
show_missing = true
skip_covered = false
precision = 1
fail_under = 0
fail_under = 99
exclude_also = [
"if TYPE_CHECKING:",
"raise NotImplementedError",
Expand Down
58 changes: 0 additions & 58 deletions src/helper/debugger.py

This file was deleted.

82 changes: 0 additions & 82 deletions src/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import asyncio
import logging
import sys
import traceback

from aiohttp import ClientSession

Expand All @@ -18,68 +16,6 @@

_LOGGER = logging.getLogger(__name__)

debug: list[str] = []


def exception_handler(_exctype, _value, tb):
"""Custom exception handler.

Args:
exctype ([type]): [description]
value ([type]): [description]
tb ([type]): [description]
"""
last = len(traceback.extract_tb(tb)) - 1
tb_entry = traceback.extract_tb(tb)[last]
_LOGGER.error(
"-> \nError in %s\nwhen running %s function\non line %s - %s \nwith vars %s",
tb_entry.filename,
tb_entry.name,
tb_entry.lineno,
tb_entry.line,
tb_entry.locals,
)
traceback.print_exc()


sys.excepthook = exception_handler


def trace_debug(frame, event, arg):
"""Trace functions.

Args:
frame (object): The current frame being debugged.
event (str): The event type
arg (dict): arguments in debug function..

Returns:
object: returns itself as per tracing docs
"""
if "pyhiveapi/" in str(frame):
co = frame.f_code
func_name = co.co_name
func_line_no = frame.f_lineno
if func_name in debug:
if event == "call":
func_filename = co.co_filename.rsplit("/", 1)
caller = frame.f_back
caller_line_no = caller.f_lineno
caller_filename = caller.f_code.co_filename.rsplit("/", 1)

_LOGGER.debug(
"Call to %s on line %s of %s from line %s of %s",
func_name,
func_line_no,
func_filename[1],
caller_line_no,
caller_filename[1],
)
elif event == "return":
_LOGGER.debug("returning %s", arg)

return trace_debug


class Hive(HiveSession):
"""Hive Class.
Expand Down Expand Up @@ -112,24 +48,6 @@ def __init__(
self.switch = Switch(self.session)
self.sensor = Sensor(self.session)

if debug:
sys.settrace(trace_debug)

def set_debugging(self, debugger: list):
"""Set function to debug.

Args:
debugger (list): a list of functions to debug

Returns:
object: Returns traceback object.
"""
global debug # pylint: disable=global-statement # noqa: PLW0603
debug = debugger
if debug:
return sys.settrace(trace_debug)
return sys.settrace(None)

async def force_update(self) -> bool:
"""Immediately poll the Hive API, bypassing the 2-minute interval.

Expand Down
22 changes: 1 addition & 21 deletions tests/module/test_hub.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Tests for session polling behaviour, HiveHub sensor status, and Hive lifecycle."""

# pylint: disable=protected-access
import sys
from unittest.mock import AsyncMock, MagicMock

from apyhiveapi import Hive
Expand Down Expand Up @@ -118,7 +117,7 @@ async def test_glass_break_missing_returns_none(self):


class TestHiveLifecycle:
"""Tests for Hive context manager and set_debugging."""
"""Tests for Hive context manager."""

async def test_context_manager_aenter_returns_self(self):
"""__aenter__ returns the Hive instance itself."""
Expand All @@ -137,22 +136,3 @@ async def test_close_calls_websession_close(self):
ws = hive.api.websession
# After context exit the session should be closed
assert ws.closed

async def test_set_debugging_empty_list_clears_trace(self):
"""set_debugging([]) removes any active trace function."""
async with Hive(
username="test@example.com",
password="pass", # pragma: allowlist secret
) as hive:
hive.set_debugging([])
assert sys.gettrace() is None

async def test_set_debugging_with_function_sets_trace(self):
"""set_debugging([name]) installs the trace_debug function."""
async with Hive(
username="test@example.com",
password="pass", # pragma: allowlist secret
) as hive:
hive.set_debugging(["some_func"])
assert sys.gettrace() is not None
sys.settrace(None) # clean up
Loading
Loading