Beispiel #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`
""")
Beispiel #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),
        }
    )
Beispiel #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",
             {
                 "and": (
Beispiel #4
0
async def test_month_near_datetime() -> None:
    with freeze_time("2012-06-06T12:15:00", tz_offset=0) as frozen_time:
        today = frozen_time().replace(
            hour=0, minute=0, second=0, microsecond=0, tzinfo=UTC
        )
        in_june = today.replace(month=today.month, day=1)
        in_july = today.replace(month=today.month + 1, day=1)
        next_year_in_january = today.replace(year=today.year + 1, month=1, day=1)
        next_year_in_june = in_june.replace(year=in_june.year + 1, month=6, day=1)

        f = filter.NearDatetimeFilter({"<=": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == in_july
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<=": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == in_july
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"<": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_january
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"=": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == in_july
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_june
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX

        f = filter.NearDatetimeFilter({"!=": ("foo", date.Month(6))})
        frozen_time.move_to(in_june.replace(month=6))
        assert await f(FakePR({"foo": date.Month(6)})) == in_july
        frozen_time.move_to(in_june.replace(month=7))
        assert await f(FakePR({"foo": date.Month(7)})) == next_year_in_june
        frozen_time.move_to(in_june.replace(month=1))
        assert await f(FakePR({"foo": date.Month(1)})) == in_june
        assert await f(FakePR({"foo": None})) == date.DT_MAX