Skip to content

Commit

Permalink
Rename function in light of subtle change in functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester committed Jan 31, 2025
1 parent abcab4c commit 5f44781
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from blueapi.config import EnvironmentConfig, SourceKind
from blueapi.utils import (
BlueapiPlanModelConfig,
is_sourced_from_module,
is_function_sourced_from_module,
load_module_all,
)

Expand Down Expand Up @@ -109,7 +109,8 @@ def plan_2(...) -> MsgGenerator:
# in which case we only inspect objects listed there, regardless of their
# original source module.
if (
hasattr(module, "__all__") or is_sourced_from_module(obj, module)
hasattr(module, "__all__")
or is_function_sourced_from_module(obj, module)
) and is_bluesky_plan_generator(obj):
self.register_plan(obj)

Expand Down
4 changes: 2 additions & 2 deletions src/blueapi/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .connect_devices import connect_devices
from .file_permissions import get_owner_gid, is_sgid_set
from .invalid_config_error import InvalidConfigError
from .modules import is_sourced_from_module, load_module_all
from .modules import is_function_sourced_from_module, load_module_all
from .serialization import serialize
from .thread_exception import handle_all_exceptions

Expand All @@ -17,5 +17,5 @@
"connect_devices",
"is_sgid_set",
"get_owner_gid",
"is_sourced_from_module",
"is_function_sourced_from_module",
]
3 changes: 3 additions & 0 deletions tests/unit_tests/utils/functions_b.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from .functions_a import a, b # noqa: F401


def c(): ...


Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/utils/test_modules.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib import import_module

from blueapi.utils import is_sourced_from_module, load_module_all
from blueapi.utils import is_function_sourced_from_module, load_module_all


def test_imports_all():
Expand All @@ -15,14 +15,14 @@ def test_imports_everything_without_all():

def test_source_is_in_module():
module = import_module(".functions_b", package="tests.unit_tests.utils")
assert is_sourced_from_module(module.__dict__["c"], module)
assert is_function_sourced_from_module(module.__dict__["c"], module)


def test_source_is_not_in_module():
module = import_module(".functions_b", package="tests.unit_tests.utils")
assert not is_sourced_from_module(module.__dict__["a"], module)
assert not is_function_sourced_from_module(module.__dict__["a"], module)


def test_source_check_on_non_function():
module = import_module(".functions_b", package="tests.unit_tests.utils")
assert not is_sourced_from_module(module.__dict__["e"], module)
assert not is_function_sourced_from_module(module.__dict__["e"], module)

0 comments on commit 5f44781

Please sign in to comment.