|
5 | 5 | from re import escape |
6 | 6 | from time import sleep |
7 | 7 | from unittest import mock |
8 | | -from unittest.mock import Mock |
| 8 | +from unittest.mock import MagicMock, Mock |
9 | 9 |
|
10 | 10 | import pytest |
11 | 11 |
|
12 | 12 | from lightning_app import LightningApp, LightningFlow, LightningWork |
13 | 13 | from lightning_app.runners import MultiProcessRuntime |
14 | | -from lightning_app.storage.path import artifacts_path, is_lit_path, Path, shared_storage_path, storage_root_dir |
| 14 | +from lightning_app.storage.path import ( |
| 15 | + _is_s3fs_available, |
| 16 | + artifacts_path, |
| 17 | + filesystem, |
| 18 | + is_lit_path, |
| 19 | + Path, |
| 20 | + shared_storage_path, |
| 21 | + storage_root_dir, |
| 22 | +) |
15 | 23 | from lightning_app.storage.requests import ExistsResponse, GetResponse |
16 | 24 | from lightning_app.testing.helpers import EmptyWork, MockQueue, RunIf |
17 | 25 | from lightning_app.utilities.app_helpers import LightningJSONEncoder |
@@ -678,3 +686,21 @@ def test_artifacts_path(): |
678 | 686 | work = Mock() |
679 | 687 | work.name = "root.flow.work" |
680 | 688 | assert artifacts_path(work) == shared_storage_path() / "artifacts" / "root.flow.work" |
| 689 | + |
| 690 | + |
| 691 | +@pytest.mark.skipif(not _is_s3fs_available(), reason="This test requires s3fs.") |
| 692 | +@mock.patch.dict(os.environ, {"LIGHTNING_BUCKET_ENDPOINT_URL": "a"}) |
| 693 | +@mock.patch.dict(os.environ, {"LIGHTNING_BUCKET_NAME": "b"}) |
| 694 | +@mock.patch.dict(os.environ, {"LIGHTNING_AWS_ACCESS_KEY_ID": "c"}) |
| 695 | +@mock.patch.dict(os.environ, {"LIGHTNING_AWS_SECRET_ACCESS_KEY": "d"}) |
| 696 | +@mock.patch.dict(os.environ, {"LIGHTNING_CLOUD_APP_ID": "e"}) |
| 697 | +def test_filesystem(monkeypatch): |
| 698 | + from lightning_app.storage import path |
| 699 | + |
| 700 | + mock = MagicMock() |
| 701 | + monkeypatch.setattr(path, "S3FileSystem", mock) |
| 702 | + fs = filesystem() |
| 703 | + assert fs._mock_new_parent._mock_mock_calls[0].kwargs["key"] == "c" |
| 704 | + assert fs._mock_new_parent._mock_mock_calls[0].kwargs["secret"] == "d" |
| 705 | + assert not fs._mock_new_parent._mock_mock_calls[0].kwargs["use_ssl"] |
| 706 | + assert fs._mock_new_parent._mock_mock_calls[0].kwargs["client_kwargs"] == {"endpoint_url": "a"} |
0 commit comments