def test_get_clock_trigger_time(itask_point: PointBase, offset_str: str, expected: int, set_cycling_type: Callable) -> None: """Test get_clock_trigger_time() for exact and inexact offsets.""" set_cycling_type(itask_point.TYPE) mock_itask = Mock(point=itask_point.standardise(), clock_trigger_time=None) assert TaskProxy.get_clock_trigger_time(mock_itask, offset_str) == expected
def get_xtrig_ctx(self, itask: TaskProxy, label: str) -> SubFuncContext: """Get a real function context from the template. Args: itask: task proxy label: xtrigger label Returns: function context """ farg_templ = { TemplateVariables.CyclePoint.value: str(itask.point), TemplateVariables.TaskName.value: str(itask.tdef.name), TemplateVariables.TaskID.value: str(itask.identity) } farg_templ.update(self.farg_templ) ctx = deepcopy(self.functx_map[label]) args = [] kwargs = {} if ctx.func_name == "wall_clock": if "trigger_time" in ctx.func_kwargs: # Internal (retry timer): trigger_time already set. kwargs["trigger_time"] = ctx.func_kwargs["trigger_time"] elif "offset" in ctx.func_kwargs: # noqa: SIM106 # External (clock xtrigger): convert offset to trigger_time. # Datetime cycling only. kwargs["trigger_time"] = itask.get_clock_trigger_time( ctx.func_kwargs["offset"]) else: # Should not happen! raise ValueError( "wall_clock function kwargs needs trigger time or offset") else: # Other xtrig functions: substitute template values. for val in ctx.func_args: with suppress(TypeError): val = val % farg_templ args.append(val) for key, val in ctx.func_kwargs.items(): with suppress(TypeError): val = val % farg_templ kwargs[key] = val ctx.func_args = args ctx.func_kwargs = kwargs ctx.update_command(self.workflow_run_dir) return ctx