Skip to content

Commit

Permalink
Better coverage of logger and version utils (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Dec 27, 2021
1 parent d2da4b4 commit 3975305
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
3 changes: 0 additions & 3 deletions custom_components/hacs/utils/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ def concurrent(concurrenttasks=15, sleepafter=0) -> Coroutine[Any, Any, None]:
max_concurrent = asyncio.Semaphore(concurrenttasks)

def inner_function(function) -> Coroutine[Any, Any, None]:
if not asyncio.iscoroutinefunction(function):
return function

@wraps(function)
async def wrapper(*args) -> None:

Expand Down
7 changes: 0 additions & 7 deletions custom_components/hacs/utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
"""Custom logger for HACS."""
import logging
import os

from ..const import PACKAGE_NAME

_HACSLogger: logging.Logger = logging.getLogger(PACKAGE_NAME)

if "GITHUB_ACTION" in os.environ:
logging.basicConfig(
format="::%(levelname)s:: %(message)s",
level="DEBUG",
)


def get_hacs_logger() -> logging.Logger:
"""Return a Logger instance."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hacs/utils/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def render_template(content: str, context: HacsRepository) -> str:
version_available=context.releases.last_release,
version_installed=context.display_installed_version,
)
except BaseException as exception:
except BaseException as exception: # pylint: disable=broad-except
context.logger.debug(exception)
return content
6 changes: 2 additions & 4 deletions custom_components/hacs/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ def version_left_higher_or_equal_then_right(left: str, right: str) -> bool:
"""Return a bool if source is newer than target, will also be true if identical."""
if left == right:
return True
try:
return version_left_higher_then_right(left, right)
except (AwesomeVersionException, AttributeError):
return False

return version_left_higher_then_right(left, right)


def version_to_download(repository: HacsRepository) -> str:
Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@
HacsPythonScriptRepository,
HacsThemeRepository,
)
from custom_components.hacs.repositories.base import HacsRepository
from custom_components.hacs.tasks.manager import HacsTaskManager
from custom_components.hacs.utils.logger import get_hacs_logger
from custom_components.hacs.utils.queue_manager import QueueManager
from custom_components.hacs.utils.version import version_to_download
from custom_components.hacs.validate.manager import ValidationManager

from tests.async_mock import MagicMock
from tests.common import (
TOKEN,
async_test_home_assistant,
dummy_repository_base,
fixture,
mock_storage as mock_storage,
)

# Set default logger
logging.basicConfig(level=logging.DEBUG)
if "GITHUB_ACTION" in os.environ:
logging.basicConfig(
format="::%(levelname)s:: %(message)s",
level=logging.DEBUG,
)

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down
2 changes: 2 additions & 0 deletions tests/handler/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ def test_render_template(repository):
render_template(content, repository)
repository.releases.last_release_object = MockRelease()
render_template(content, repository)

assert render_template("{{test.test}}", repository) == "{{test.test}}"
7 changes: 7 additions & 0 deletions tests/utils/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ def test_version_to_download(repository):
repository.data.default_branch = "main"
repository.data.last_version = "2"
assert version.version_to_download(repository) == "2"

repository.data.default_branch = "main"
repository.data.selected_tag = "main"
repository.data.last_version = None
assert version.version_to_download(repository) == "main"

assert version.version_left_higher_then_right("1", None) is False

0 comments on commit 3975305

Please sign in to comment.