コード例 #1
0
async def test_rules_conditions_schedule():
    pulls = [
        FakeQueuePullRequest({
            "number": 1,
            "author": "me",
            "base": "main",
            "current-timestamp": date.utcnow(),
            "current-time": date.utcnow(),
            "current-day": date.Day(22),
            "current-month": date.Month(9),
            "current-year": date.Year(2021),
            "current-day-of-week": date.DayOfWeek(3),
        }),
    ]
    schema = voluptuous.Schema(
        voluptuous.All(
            [voluptuous.Coerce(rules.RuleConditionSchema)],
            voluptuous.Coerce(conditions.QueueRuleConditions),
        ))

    c = schema([
        "base=main",
        "schedule=MON-FRI 08:00-17:00",
        "schedule=MONDAY-FRIDAY 10:00-12:00",
        "schedule=SAT-SUN 07:00-12:00",
    ])

    await c(pulls)

    assert (c.get_summary() == """- [X] `base=main`
- [X] `schedule=MON-FRI 08:00-17:00`
- [ ] `schedule=MONDAY-FRIDAY 10:00-12:00`
- [ ] `schedule=SAT-SUN 07:00-12:00`
""")
コード例 #2
0
def get_scheduled_pr() -> FakePR:
    return FakePR(
        {
            "current-day-of-week": date.DayOfWeek(date.utcnow().isoweekday()),
            "current-year": date.Year(date.utcnow().year),
            "current-day": date.Day(date.utcnow().day),
            "number": 3433,
            "current-time": date.utcnow(),
            "current-month": date.Month(date.utcnow().month),
        }
    )
コード例 #3
0
         ">=": (
             "current-time",
             date.Time(10, 0, tzinfo=zoneinfo.ZoneInfo("PST8PDT")),
         )
     },
 ),
 (
     "current-time>=10:00",
     {
         ">=": (
             "current-time",
             date.Time(10, 0, tzinfo=datetime.timezone.utc),
         )
     },
 ),
 ("current-day=4", {"=": ("current-day", date.Day(4))}),
 ("current-month=5", {"=": ("current-month", date.Month(5))}),
 ("current-year=2000", {"=": ("current-year", date.Year(2000))}),
 ("current-day-of-week=4", {"=": ("current-day-of-week", date.DayOfWeek(4))}),
 ("current-day-of-week=MON", {"=": ("current-day-of-week", date.DayOfWeek(1))}),
 (
     "current-day-of-week=WednesDay",
     {"=": ("current-day-of-week", date.DayOfWeek(3))},
 ),
 ("current-day-of-week=sun", {"=": ("current-day-of-week", date.DayOfWeek(7))}),
 (
     "schedule: MON-FRI 08:00-17:00",
     {
         "@": (
             "schedule",
             {
コード例 #4
0
async def test_day_near_datetime() -> None:
    with freeze_time("2012-01-06T12:15:00", tz_offset=0) as frozen_time:
        today = frozen_time().replace(
            hour=0, minute=0, second=0, microsecond=0, tzinfo=UTC
        )
        nextday = today.replace(day=today.day + 1)
        nextmonth = today.replace(month=today.month + 1, day=1)
        nextmonth_at_six = today.replace(month=today.month + 1, day=6)

        f = filter.NearDatetimeFilter({"<=": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextday
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextmonth
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<=": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextday
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextmonth
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"=": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextday
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth_at_six
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"!=": ("foo", date.Day(6))})
        frozen_time.move_to(today.replace(day=6))
        assert await f(FakePR({"foo": date.Day(6)})) == nextday
        frozen_time.move_to(today.replace(day=7))
        assert await f(FakePR({"foo": date.Day(7)})) == nextmonth_at_six
        frozen_time.move_to(today.replace(day=1))
        assert await f(FakePR({"foo": date.Day(1)})) == today
        assert await f(FakePR({"foo": None})) == date.DT_MAX