|
17 | 17 | """Standard pytest fixtures for unit tests."""
|
18 | 18 |
|
19 | 19 | from pathlib import Path
|
20 |
| -from typing import Any, Callable, Optional, Union |
21 |
| -from unittest.mock import create_autospec, Mock |
| 20 | +from typing import ( |
| 21 | + Any, |
| 22 | + Callable, |
| 23 | + Optional, |
| 24 | + Union, |
| 25 | +) |
| 26 | +from unittest.mock import ( |
| 27 | + Mock, |
| 28 | + create_autospec, |
| 29 | +) |
22 | 30 |
|
23 | 31 | import pytest
|
24 | 32 |
|
25 | 33 | from cylc.flow.cycling.iso8601 import init as iso8601_init
|
26 | 34 | from cylc.flow.cycling.loader import (
|
| 35 | + INTEGER_CYCLING_TYPE, |
27 | 36 | ISO8601_CYCLING_TYPE,
|
28 |
| - INTEGER_CYCLING_TYPE |
29 | 37 | )
|
30 | 38 | from cylc.flow.data_store_mgr import DataStoreMgr
|
31 | 39 | from cylc.flow.install import (
|
32 | 40 | link_runN,
|
33 | 41 | unlink_runN,
|
34 | 42 | )
|
35 | 43 | from cylc.flow.scheduler import Scheduler
|
36 |
| -from cylc.flow.workflow_files import ( |
37 |
| - WorkflowFiles, |
38 |
| -) |
| 44 | +from cylc.flow.workflow_files import WorkflowFiles |
39 | 45 | from cylc.flow.xtrigger_mgr import XtriggerManager
|
40 | 46 |
|
41 | 47 |
|
@@ -219,3 +225,28 @@ def prevent_symlinking(monkeypatch: pytest.MonkeyPatch):
|
219 | 225 | 'cylc.flow.pathutil.make_symlink_dir',
|
220 | 226 | lambda *_, **__: {}
|
221 | 227 | )
|
| 228 | + |
| 229 | + |
| 230 | +def _tmp_flow_config(tmp_run_dir: Callable): |
| 231 | + """Create a temporary flow config file for use in init'ing WorkflowConfig. |
| 232 | + Args: |
| 233 | + id_: Workflow name. |
| 234 | + config: The flow file content. |
| 235 | + Returns the path to the flow file. |
| 236 | + """ |
| 237 | + def __tmp_flow_config(id_: str, config: str) -> 'Path': |
| 238 | + run_dir: 'Path' = tmp_run_dir(id_) |
| 239 | + flow_file = run_dir / WorkflowFiles.FLOW_FILE |
| 240 | + flow_file.write_text(config) |
| 241 | + return flow_file |
| 242 | + return __tmp_flow_config |
| 243 | + |
| 244 | + |
| 245 | +@pytest.fixture |
| 246 | +def tmp_flow_config(tmp_run_dir: Callable): |
| 247 | + return _tmp_flow_config(tmp_run_dir) |
| 248 | + |
| 249 | + |
| 250 | +@pytest.fixture(scope='module') |
| 251 | +def mod_tmp_flow_config(mod_tmp_run_dir: Callable): |
| 252 | + return _tmp_flow_config(mod_tmp_run_dir) |
0 commit comments