Skip to content

Commit

Permalink
moved unit tests to a separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ZohebShaikh committed Sep 5, 2024
1 parent 012238d commit a892389
Show file tree
Hide file tree
Showing 32 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ allowlist_externals =
commands =
pre-commit: pre-commit run --all-files {posargs}
type-checking: mypy src tests {posargs}
tests: pytest --cov=blueapi --cov-report term --cov-report xml:cov.xml {posargs}
tests: pytest --cov=blueapi --cov-report term --cov-report xml:cov.xml tests/unit_tests {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_add_invalid_plan(empty_context: BlueskyContext, plan: PlanGenerator) ->


def test_add_plan_from_module(empty_context: BlueskyContext) -> None:
import tests.core.fake_plan_module as plan_module
import tests.unit_tests.core.fake_plan_module as plan_module

empty_context.with_plan_module(plan_module)
assert {"scan"} == empty_context.plans.keys()
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_override_device_name(


def test_add_devices_from_module(empty_context: BlueskyContext) -> None:
import tests.core.fake_device_module as device_module
import tests.unit_tests.core.fake_device_module as device_module

empty_context.with_device_module(device_module)
assert {
Expand All @@ -192,7 +192,7 @@ def test_add_devices_from_module(empty_context: BlueskyContext) -> None:
def test_add_failing_deivces_from_module(
caplog: LogCaptureFixture, empty_context: BlueskyContext
) -> None:
import tests.core.fake_device_module_failing as device_module
import tests.unit_tests.core.fake_device_module_failing as device_module

caplog.set_level(10)
empty_context.with_device_module(device_module)
Expand All @@ -208,7 +208,7 @@ def test_extra_kwargs_in_with_dodal_module_passed_to_make_all_devices(
"""
Note that this functionality is currently used by hyperion.
"""
import tests.core.fake_device_module as device_module
import tests.unit_tests.core.fake_device_module as device_module

with patch(
"blueapi.core.context.make_all_devices",
Expand Down Expand Up @@ -262,10 +262,11 @@ def test_add_devices_and_plans_from_modules_with_config(
sources=[
Source(
kind=SourceKind.DEVICE_FUNCTIONS,
module="tests.core.fake_device_module",
module="tests.unit_tests.core.fake_device_module",
),
Source(
kind=SourceKind.PLAN_FUNCTIONS, module="tests.core.fake_plan_module"
kind=SourceKind.PLAN_FUNCTIONS,
module="tests.unit_tests.core.fake_plan_module",
),
]
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_can_reload_after_an_error(pool_mock: MagicMock):


def test_function_not_findable_on_subprocess(started_runner: WorkerDispatcher):
from tests.core.fake_device_module import fake_motor_y
from tests.unit_tests.core.fake_device_module import fake_motor_y

# Valid target on main but not sub process
# Change in this process not reflected in subprocess
Expand All @@ -122,7 +122,7 @@ def test_function_not_findable_on_subprocess(started_runner: WorkerDispatcher):

def test_non_callable_excepts_in_main_process(started_runner: WorkerDispatcher):
# Not a valid target on main or sub process
from tests.core.fake_device_module import fetchable_non_callable
from tests.unit_tests.core.fake_device_module import fetchable_non_callable

with pytest.raises(
RpcError,
Expand All @@ -134,7 +134,10 @@ def test_non_callable_excepts_in_main_process(started_runner: WorkerDispatcher):

def test_non_callable_excepts_in_sub_process(started_runner: WorkerDispatcher):
# Valid target on main but finds non-callable in sub process
from tests.core.fake_device_module import fetchable_callable, fetchable_non_callable
from tests.unit_tests.core.fake_device_module import (
fetchable_callable,
fetchable_non_callable,
)

fetchable_callable.__name__ = fetchable_non_callable.__name__

Expand All @@ -156,7 +159,7 @@ def test_clear_message_for_anonymous_function(started_runner: WorkerDispatcher):


def test_clear_message_for_wrong_return(started_runner: WorkerDispatcher):
from tests.core.fake_device_module import wrong_return_type
from tests.unit_tests.core.fake_device_module import wrong_return_type

with pytest.raises(
ValidationError,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py → tests/unit_tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_submit_plan(runner: CliRunner):
match=[matchers.json_params_matcher(body_data)],
)

config_path = "tests/example_yaml/rest_config.yaml"
config_path = "tests/unit_tests/example_yaml/rest_config.yaml"
runner.invoke(
main, ["-c", config_path, "controller", "run", "sleep", '{"time": 5}']
)
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_valid_stomp_config_for_listener(
main,
[
"-c",
"tests/example_yaml/valid_stomp_config.yaml",
"tests/unit_tests/example_yaml/valid_stomp_config.yaml",
"controller",
"listen",
],
Expand Down Expand Up @@ -559,7 +559,7 @@ def test_init_scratch_calls_setup_scratch(mock_setup_scratch: Mock, runner: CliR

result = runner.invoke(
main,
["-c", "tests/example_yaml/scratch.yaml", "setup-scratch"],
["-c", "tests/unit_tests/example_yaml/scratch.yaml", "setup-scratch"],
input="\n",
)
assert result.exit_code == 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


def test_imports_all():
module = import_module(".hasall", package="tests.utils")
module = import_module(".hasall", package="tests.unit_tests.utils")
assert list(load_module_all(module)) == ["hello", 9]


def test_imports_everything_without_all():
module = import_module(".lacksall", package="tests.utils")
module = import_module(".lacksall", package="tests.unit_tests.utils")
assert list(load_module_all(module)) == [3, "hello", 9]
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a892389

Please sign in to comment.