Beispiel #1
0
def test_get_day_of_month_error():
    # get_day_of_month is not directly exposed.
    # We test it via roll_qtrday.
    dt = datetime(2017, 11, 15)
    day_opt = "foo"

    with pytest.raises(ValueError, match=day_opt):
        # To hit the raising case we need month == dt.month and n > 0.
        roll_qtrday(dt, n=3, month=11, day_opt=day_opt, modby=12)
Beispiel #2
0
def test_roll_qtr_day_not_mod_unequal(day_opt, month, n):
    expected = {
        3: {
            -3: -2,
            4: 4
        },
        5: {
            -3: -3,
            4: 3
        }
    }

    other = Timestamp(2072, 10, 1, 6, 17, 18)  # Saturday.
    assert roll_qtrday(other, n, month, day_opt, modby=3) == expected[month][n]
Beispiel #3
0
def test_roll_qtrday():
    other = Timestamp(2072, 10, 1, 6, 17, 18)  # Saturday
    for day_opt in ['start', 'end', 'business_start', 'business_end']:
        # as long as (other.month % 3) != (month % 3), day_opt is irrelevant
        # the `day_opt` doesn't matter.
        month = 5  # (other.month % 3) < (month % 3)
        assert roll_qtrday(other, 4, month, day_opt, modby=3) == 3
        assert roll_qtrday(other, -3, month, day_opt, modby=3) == -3

        month = 3  # (other.month % 3) > (month % 3)
        assert roll_qtrday(other, 4, month, day_opt, modby=3) == 4
        assert roll_qtrday(other, -3, month, day_opt, modby=3) == -2

    month = 2
    other = datetime(1999, 5, 31)  # Monday
    # has (other.month % 3) == (month % 3)

    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    other = Timestamp(2072, 10, 1, 6, 17, 18)  # Saturday
    month = 4  # (other.month % 3) == (month % 3)
    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n - 1

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    other = Timestamp(2072, 10, 3, 6, 17, 18)  # First businessday
    month = 4  # (other.month % 3) == (month % 3)
    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n - 1

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n
Beispiel #4
0
def test_roll_qtr_day_mod_equal(other, month, exp_dict, n, day_opt):
    # All cases have (other.month % 3) == (month % 3).
    expected = exp_dict.get(n, {}).get(day_opt, n)
    assert roll_qtrday(other, n, month, day_opt, modby=3) == expected
Beispiel #5
0
def test_roll_qtrday_year2(other, expected, n):
    month = 6
    day_opt = "end"  # `other` will be compared to June 30.

    assert roll_qtrday(other, n, month, day_opt, modby=12) == expected[n]
Beispiel #6
0
def test_roll_qtrday_year(other, expected, n):
    month = 3
    day_opt = "start"  # `other` will be compared to March 1.

    assert roll_qtrday(other, n, month, day_opt, modby=12) == expected[n]
def test_roll_qtrday():
    other = Timestamp(2072, 10, 1, 6, 17, 18)  # Saturday
    for day_opt in ['start', 'end', 'business_start', 'business_end']:
        # as long as (other.month % 3) != (month % 3), day_opt is irrelevant
        # the `day_opt` doesn't matter.
        month = 5  # (other.month % 3) < (month % 3)
        assert roll_qtrday(other, 4, month, day_opt, modby=3) == 3
        assert roll_qtrday(other, -3, month, day_opt, modby=3) == -3

        month = 3  # (other.month % 3) > (month % 3)
        assert roll_qtrday(other, 4, month, day_opt, modby=3) == 4
        assert roll_qtrday(other, -3, month, day_opt, modby=3) == -2

    month = 2
    other = datetime(1999, 5, 31)  # Monday
    # has (other.month % 3) == (month % 3)

    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    other = Timestamp(2072, 10, 1, 6, 17, 18)  # Saturday
    month = 4  # (other.month % 3) == (month % 3)
    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n - 1

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n

    other = Timestamp(2072, 10, 3, 6, 17, 18)  # First businessday
    month = 4  # (other.month % 3) == (month % 3)
    n = 2
    assert roll_qtrday(other, n, month, 'start', modby=3) == n
    assert roll_qtrday(other, n, month, 'end', modby=3) == n - 1
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n - 1

    n = -1
    assert roll_qtrday(other, n, month, 'start', modby=3) == n + 1
    assert roll_qtrday(other, n, month, 'end', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_start', modby=3) == n
    assert roll_qtrday(other, n, month, 'business_end', modby=3) == n