Exemplo n.º 1
0
def test_max_dates_raises_unanchored():
    dates = [
        Date('01-01', '%d-%m'),
        Date('01-12', '%d-%m'),
    ]
    with pytest.raises(ValueError) as exec_info:
        _ = max_date(dates)

    expected_exc = 'max_date() arg does not contain any year-anchored date'
    assert expected_exc in str(exec_info.value).lower()
Exemplo n.º 2
0
def test_max_date():
    dates = [
        Date('01-01-1905', '%d-%m-%Y'),
        Date('01-02', '%d-%m'),
        Date('01-01-1989', '%d-%m-%Y'),
    ]
    most_recent = max_date(dates)
    assert most_recent == Date('01-01-1989', '%d-%m-%Y')

    dates = [Date('01-01-1905', '%d-%m-%Y'), Date('01-01-1905', '%d-%m-%Y')]
    most_recent = max_date(dates)
    assert most_recent == Date('01-01-1905', '%d-%m-%Y')

    dates = [
        Date('01-01', '%d-%m'),
        Date('01-01-1905', '%d-%m-%Y'),
    ]
    most_recent = max_date(dates)
    assert most_recent == Date('01-01-1905', '%d-%m-%Y')
Exemplo n.º 3
0
def test_adjust_long_date_span_preserves_locale():
    dates_given = [
        Date('03 November 1899', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('04 Mai 1900', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('01 Januar 1915', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('01 January 1995', '%d %B %Y', date_locale='en_US.UTF-8')
    ]

    dates_expected = [
        Date('03 November 1904', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('04 Mai 1904', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('01 Januar 1915', '%d %B %Y', date_locale='de_DE.UTF-8'),
        Date('01 January 1995', '%d %B %Y', date_locale='en_US.UTF-8')
    ]

    most_recent = Date('01-01-1995', '%d-%m-%Y')
    for given, expected in zip(dates_given, dates_expected):
        shifted = adjust_long_date_span(given,
                                        most_recent=most_recent,
                                        max_delta=90)
        assert shifted == expected
Exemplo n.º 4
0
def test_adjust_long_date_span():
    dates_given = [
        Date('03-11-1899', '%d-%m-%Y'),
        Date('04-05-1900', '%d-%m-%Y'),
        Date('01-01-1915', '%d-%m-%Y'),
        Date('01-01-1995', '%d-%m-%Y')
    ]

    dates_expected = [
        Date('03-11-1904', '%d-%m-%Y'),
        Date('04-05-1904', '%d-%m-%Y'),
        Date('01-01-1915', '%d-%m-%Y'),
        Date('01-01-1995', '%d-%m-%Y'),
    ]

    most_recent = Date('01-01-1995', '%d-%m-%Y')
    for given, expected in zip(dates_given, dates_expected):
        shifted = adjust_long_date_span(given,
                                        most_recent=most_recent,
                                        max_delta=90)
        assert shifted == expected
Exemplo n.º 5
0
def test_minimum_season_offsets():
    fmt = '%Y-%m-%d'
    dates = [
        Date('2018-04-24', fmt),
        Date('2018-7-7', fmt),
        Date('2018-11-11', fmt),
        Date('2018-12-22', fmt),
        Date('2019-1-7', fmt),
        Date('2018-12-21', fmt)
    ]

    negative_shift, positive_shift = minimum_season_offsets(dates)
    assert (negative_shift, positive_shift) == (0, 39)
Exemplo n.º 6
0
def test_day_anchored():
    assert Date('01-01-1905', '%d-%m-%Y').day_anchored()
    assert not Date('01-1905', '%m-%Y').day_anchored()
Exemplo n.º 7
0
def test_year_anchored():
    assert Date('01-01-1905', '%d-%m-%Y').year_anchored()
    assert Date('01-01-18', '%d-%m-%y').year_anchored()
    assert not Date('01-01', '%d-%m').year_anchored()
Exemplo n.º 8
0
def test_season_offsets_unanchored_dates():
    missing_year = Date('04-24', '%m-%d')
    missing_day = Date('2018-04', '%Y-%m')

    assert missing_year.season_offsets() == (34, 57)
    assert missing_day.season_offsets() == (25, 66)
Exemplo n.º 9
0
def test_season_offsets():
    fmt = '%Y-%m-%d'
    spring_date = Date('2018-04-24', fmt)
    summer_date = Date('2018-7-7', fmt)
    autumn_date = Date('2018-11-11', fmt)
    winter_date_end_of_year = Date('2018-12-22', fmt)
    winter_date_start_of_year = Date('2019-1-7', fmt)
    border_date = Date('2018-12-21', fmt)

    assert spring_date.season_offsets() == (34, 57)
    assert summer_date.season_offsets() == (16, 77)
    assert autumn_date.season_offsets() == (49, 39)
    assert winter_date_end_of_year.season_offsets() == (1, 88)
    assert winter_date_start_of_year.season_offsets() == (17, 72)
    assert border_date.season_offsets() == (0, 89)
Exemplo n.º 10
0
def test_adjust_long_date_span_disregard_timezones():
    dt_aware = Date('15-34-2019', '%H-%M%z')
    dt_unaware = Date('ma', '%a', date_locale='nl_NL.UTF-8')
    assert adjust_long_date_span(dt_unaware,
                                 most_recent=dt_aware,
                                 max_delta=90) == dt_unaware
Exemplo n.º 11
0
def test_year_span():
    date_a = Date('01-01-1905', '%d-%m-%Y')
    date_b = Date('01-01-1989', '%d-%m-%Y')

    assert year_span(date_a, date_b) == 84