Skip to content

Commit

Permalink
tests: add basic entry_point_plugins tests
Browse files Browse the repository at this point in the history
I needed to further adjust the files lookup to ignore distributions that were
not found.
  • Loading branch information
sijis committed Oct 28, 2024
1 parent d0d8e8a commit 729c7e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 11 additions & 1 deletion errbot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,17 @@ def entry_point_plugins(group):
for entry_point in entry_points:
module_name = entry_point.module
file_name = module_name.replace(".", "/") + ".py"
for f in entry_point.dist.files:
try:
files = entry_point.dist.files
except AttributeError:
# workaround to support python 3.9 and older
try:
files = importlib.metadata.distribution(entry_point.name).files
except importlib.metadata.PackageNotFoundError:
# entrypoint is not a distribution, so let's skip looking for files
continue

for f in files:
if file_name == str(f):
parent = str(pathlib.Path(f).resolve().parent)
paths.append(f"{parent}/{module_name}")
Expand Down
22 changes: 20 additions & 2 deletions tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# coding=utf-8
import logging
import sys

from datetime import timedelta

import pytest
Expand All @@ -11,7 +10,12 @@
from errbot.bootstrap import CORE_STORAGE, bot_config_defaults
from errbot.storage import StoreMixin
from errbot.storage.base import StoragePluginBase
from errbot.utils import version2tuple, format_timedelta, split_string_after
from errbot.utils import (
entry_point_plugins,
format_timedelta,
split_string_after,
version2tuple,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -103,3 +107,17 @@ def test_split_string_after_returns_two_chunks_when_chunksize_equals_half_length
splitter = split_string_after(str_, int(len(str_) / 2))
split = [chunk for chunk in splitter]
assert ["foobar2000", "foobar2000"] == split


def test_entry_point_plugins_no_groups():
result = entry_point_plugins("does_not_exist")
assert [] == result


def test_entry_point_plugins_valid_groups():
results = entry_point_plugins("console_scripts")
match = False
for result in results:
if result.endswith("errbot/errbot.cli"):
match = True
assert match

0 comments on commit 729c7e0

Please sign in to comment.