Differential D4671 Diff 23887 python_modules/dagster/dagster_tests/core_tests/definitions_tests/test_decorators.py
Changeset View
Changeset View
Standalone View
Standalone View
python_modules/dagster/dagster_tests/core_tests/definitions_tests/test_decorators.py
Show First 20 Lines • Show All 311 Lines • ▼ Show 20 Lines | def define_schedules(): | ||||
) | ) | ||||
] | ] | ||||
@schedule(cron_schedule="* * * * *", pipeline_name="foo_pipeline") | @schedule(cron_schedule="* * * * *", pipeline_name="foo_pipeline") | ||||
def echo_time_schedule(context): | def echo_time_schedule(context): | ||||
return { | return { | ||||
"echo_time": ( | "echo_time": ( | ||||
( | ( | ||||
context.scheduled_execution_time_utc.isoformat() | context.scheduled_execution_time.isoformat() | ||||
if context.scheduled_execution_time_utc | if context.scheduled_execution_time | ||||
else "" | else "" | ||||
) | ) | ||||
) | ) | ||||
} | } | ||||
with instance_for_test() as instance: | with instance_for_test() as instance: | ||||
context_without_time = ScheduleExecutionContext(instance, None) | context_without_time = ScheduleExecutionContext(instance, None) | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | with instance_for_test() as instance: | ||||
_check_partitions(hourly_foo_schedule, 24 * (31 + 26), relativedelta(hours=1)) | _check_partitions(hourly_foo_schedule, 24 * (31 + 26), relativedelta(hours=1)) | ||||
assert hourly_foo_schedule.get_run_config(context_without_time) == { | assert hourly_foo_schedule.get_run_config(context_without_time) == { | ||||
"hourly_time": datetime(year=2019, month=2, day=26, hour=23, minute=1).isoformat() | "hourly_time": datetime(year=2019, month=2, day=26, hour=23, minute=1).isoformat() | ||||
} | } | ||||
assert hourly_foo_schedule.should_execute(context_without_time) | assert hourly_foo_schedule.should_execute(context_without_time) | ||||
# time that's invalid since it corresponds to a partition that hasn't happened yet | # time that's invalid since it corresponds to a partition that hasn't happened yet | ||||
# should still generate run config, but should not execute | # should not execute and should throw if it tries to generate run config | ||||
execution_time_with_invalid_partition = datetime( | execution_time_with_invalid_partition = datetime( | ||||
year=2019, month=2, day=27, hour=3, minute=25 | year=2019, month=2, day=27, hour=3, minute=25 | ||||
) | ) | ||||
context_with_invalid_time = ScheduleExecutionContext( | context_with_invalid_time = ScheduleExecutionContext( | ||||
instance, execution_time_with_invalid_partition | instance, execution_time_with_invalid_partition | ||||
) | ) | ||||
assert hourly_foo_schedule.get_run_config(context_with_invalid_time) == { | |||||
"hourly_time": datetime(year=2019, month=2, day=27, hour=2, minute=1).isoformat() | |||||
} | |||||
assert not hourly_foo_schedule.should_execute(context_with_invalid_time) | assert not hourly_foo_schedule.should_execute(context_with_invalid_time) | ||||
with pytest.raises( | |||||
DagsterInvariantViolationError, | |||||
match="The partition selection function `default_partition_selector` did not return a partition from PartitionSet hourly_foo_schedule_partitions", | |||||
): | |||||
hourly_foo_schedule.get_run_config(context_with_invalid_time) | |||||
valid_time = datetime(year=2019, month=1, day=27, hour=1, minute=25) | valid_time = datetime(year=2019, month=1, day=27, hour=1, minute=25) | ||||
context_with_valid_time = ScheduleExecutionContext(instance, valid_time) | context_with_valid_time = ScheduleExecutionContext(instance, valid_time) | ||||
assert hourly_foo_schedule.get_run_config(context_with_valid_time) == { | assert hourly_foo_schedule.get_run_config(context_with_valid_time) == { | ||||
"hourly_time": datetime(year=2019, month=1, day=27, hour=0, minute=1).isoformat() | "hourly_time": datetime(year=2019, month=1, day=27, hour=0, minute=1).isoformat() | ||||
} | } | ||||
assert hourly_foo_schedule.should_execute(context_with_valid_time) | assert hourly_foo_schedule.should_execute(context_with_valid_time) | ||||
▲ Show 20 Lines • Show All 265 Lines • Show Last 20 Lines |