2022-06-30 20:43:04 +00:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
2023-02-01 11:07:00 +00:00
|
|
|
from lightning.app.runners import cloud
|
|
|
|
from lightning.app.runners.runtime import dispatch
|
|
|
|
from lightning.app.runners.runtime_type import RuntimeType
|
ruff: replace isort with ruff +TPU (#17684)
* ruff: replace isort with ruff
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing & imports
* lines in warning test
* docs
* fix enum import
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* fixing
* import
* fix lines
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* type ClusterEnvironment
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-09-26 15:54:55 +00:00
|
|
|
|
2023-03-03 16:55:48 +00:00
|
|
|
from tests_app import _PROJECT_ROOT
|
2022-06-30 20:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"runtime_type",
|
|
|
|
[
|
|
|
|
RuntimeType.MULTIPROCESS,
|
|
|
|
RuntimeType.CLOUD,
|
|
|
|
],
|
|
|
|
)
|
2023-02-01 11:07:00 +00:00
|
|
|
@mock.patch("lightning.app.core.queues.QueuingSystem", mock.MagicMock())
|
|
|
|
@mock.patch("lightning.app.runners.backends.cloud.LightningClient", mock.MagicMock())
|
2022-06-30 20:43:04 +00:00
|
|
|
def test_dispatch(runtime_type, monkeypatch):
|
|
|
|
"""This test ensures the runtime dispatch method gets called when using dispatch."""
|
|
|
|
monkeypatch.setattr(cloud, "CloudBackend", mock.MagicMock())
|
|
|
|
|
|
|
|
with pytest.raises(FileNotFoundError, match="doesnt_exists.py"):
|
|
|
|
dispatch(
|
|
|
|
entrypoint_file=os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/doesnt_exists.py"),
|
|
|
|
runtime_type=runtime_type,
|
|
|
|
start_server=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
runtime = runtime_type.get_runtime()
|
|
|
|
dispath_method_path = f"{runtime.__module__}.{runtime.__name__}.dispatch"
|
|
|
|
|
|
|
|
with mock.patch(dispath_method_path) as dispatch_mock_fn:
|
|
|
|
dispatch(
|
|
|
|
entrypoint_file=os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/app_metadata.py"),
|
|
|
|
runtime_type=runtime_type,
|
|
|
|
start_server=False,
|
|
|
|
)
|
|
|
|
dispatch_mock_fn.assert_called_once()
|
|
|
|
assert signal.getsignal(signal.SIGINT) is signal.default_int_handler
|