Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor cycling_type unit test fixture #4240

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def tmp_run_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
Args:
reg: Workflow name.
"""
def inner(reg: Optional[str] = None) -> Path:
def _tmp_run_dir(reg: Optional[str] = None) -> Path:
cylc_run_dir = tmp_path / 'cylc-run'
cylc_run_dir.mkdir(exist_ok=True)
monkeypatch.setattr('cylc.flow.pathutil._CYLC_RUN_DIR', cylc_run_dir)
Expand All @@ -52,32 +52,28 @@ def inner(reg: Optional[str] = None) -> Path:
(run_dir / WorkflowFiles.Service.DIRNAME).mkdir(exist_ok=True)
return run_dir
return cylc_run_dir
return inner
return _tmp_run_dir


@pytest.fixture
def cycling_type(monkeypatch: pytest.MonkeyPatch):
"""Initialize the cycling type according to cycling mode.
def set_cycling_type(monkeypatch: pytest.MonkeyPatch):
"""Initialize the Cylc cycling type.

Args:
mode: The cycling mode.
ctype: The cycling type (integer or iso8601).
time_zone: If using ISO8601/datetime cycling type, you can specify a
custom time zone to use.
"""
def _cycling_type(
mode: str = 'integer', time_zone: Optional[str] = None
) -> str:
if mode == 'integer':
ctype = INTEGER_CYCLING_TYPE
else:
ctype = ISO8601_CYCLING_TYPE
def _set_cycling_type(
ctype: str = INTEGER_CYCLING_TYPE, time_zone: Optional[str] = None
) -> None:
class _DefaultCycler:
TYPE = ctype
monkeypatch.setattr(
'cylc.flow.cycling.loader.DefaultCycler', _DefaultCycler)
if ctype == ISO8601_CYCLING_TYPE:
iso8601_init(time_zone=time_zone)
return ctype
return _cycling_type
return _set_cycling_type


@pytest.fixture
Expand Down
Loading