예제 #1
0
def test_init_clean_ok(
        reg, props, clean_called, remote_clean_called,
        monkeypatch, tmp_path, caplog):
    """Test the init_clean() function logic.

    Params:
        reg (str): Workflow name.
        props (dict): Possible values are (all optional):
            'no dir' (bool): If True, do not create run dir for this test case.
            'log' (tuple): Of form (severity, msg):
                severity (logging level): Expected level e.g. logging.INFO.
                msg (str): Message that is expected to be logged.
            'db platforms' (list): Platform names that would be loaded from
                the database.
            'no db' (bool): If True, workflow database doesn't exist.
        clean_called (bool): If a local clean is expected to go ahead.
        remote_clean_called (bool): If a remote clean is expected to go ahead.
    """
    # --- Setup ---
    expected_log = props.get('log')
    if expected_log:
        level, msg = expected_log
        caplog.set_level(level, CYLC_LOG)

    tmp_path.joinpath('cylc-run').mkdir()
    run_dir = tmp_path.joinpath('cylc-run', reg)
    if not props.get('no dir'):
        run_dir.mkdir(parents=True)

    mocked_clean = mock.Mock()
    monkeypatch.setattr('cylc.flow.workflow_files.clean', mocked_clean)
    mocked_remote_clean = mock.Mock()
    monkeypatch.setattr('cylc.flow.workflow_files.remote_clean',
                        mocked_remote_clean)
    monkeypatch.setattr('cylc.flow.workflow_files.get_workflow_run_dir',
                        lambda x: tmp_path.joinpath('cylc-run', x))

    _get_platforms_from_db = workflow_files.get_platforms_from_db

    def mocked_get_platforms_from_db(run_dir):
        if props.get('no dir') or props.get('no db'):
            return _get_platforms_from_db(run_dir)  # Handle as normal
        return set(props.get('db platforms'))

    monkeypatch.setattr('cylc.flow.workflow_files.get_platforms_from_db',
                        mocked_get_platforms_from_db)

    # --- The actual test ---
    workflow_files.init_clean(reg, opts=mock.Mock())
    if expected_log:
        assert msg in caplog.text
    if clean_called:
        assert mocked_clean.called is True
    else:
        assert mocked_clean.called is False
    if remote_clean_called:
        assert mocked_remote_clean.called is True
    else:
        assert mocked_remote_clean.called is False
예제 #2
0
파일: clean.py 프로젝트: lparkes/cylc
def main(parser: COP, opts: 'Values', reg: str):
    # Note: do not use workflow_files.parse_reg here
    if cylc.flow.flags.verbosity < 2:
        disable_timestamps(LOG)

    if opts.local_only and opts.remote_only:
        raise UserInputError(
            "--local and --remote options are mutually exclusive")

    init_clean(reg, opts)
예제 #3
0
def main(parser: COP, opts: 'Values', reg: str):
    if not cylc.flow.flags.verbosity > 1:
        # for readability omit timestamps from logging unless in debug mode
        for handler in LOG.handlers:
            if isinstance(handler.formatter, CylcLogFormatter):
                handler.formatter.configure(timestamp=False)

    if opts.local_only:
        clean(reg)
    else:
        init_clean(reg, opts)
예제 #4
0
def main(parser: COP, opts: 'Values', reg: str):
    # Note: do not use workflow_files.parse_reg here

    if cylc.flow.flags.verbosity < 2:
        # for readability omit timestamps from logging unless in debug mode
        for handler in LOG.handlers:
            if isinstance(handler.formatter, CylcLogFormatter):
                handler.formatter.configure(timestamp=False)

    if opts.local_only and opts.remote_only:
        raise UserInputError(
            "--local and --remote options are mutually exclusive"
        )

    init_clean(reg, opts)
예제 #5
0
async def run(*ids: str, opts: 'Values') -> None:
    # parse ids from the CLI
    workflows, multi_mode = await parse_ids_async(
        *ids,
        constraint='workflows',
        match_workflows=True,
        match_active=False,
        infer_latest_runs=False,  # don't infer latest runs like other cmds
    )

    # expand partial workflow ids (including run names)
    workflows, multi_mode = await scan(workflows, multi_mode)

    workflows.sort()
    if multi_mode and not opts.skip_interactive:
        prompt(workflows)  # prompt for approval or exit

    for workflow in sorted(workflows):
        init_clean(workflow, opts)