Ejemplo n.º 1
0
def test_convert_date_accepts_human_string(date_string: str,
                                           starting_date: datetime,
                                           expected_date: datetime) -> None:
    """Test common human word translation to actual datetimes."""
    result = convert_date(date_string, starting_date)

    assert result == expected_date
Ejemplo n.º 2
0
def test_if_convert_date_accepts_months_if_on_31() -> None:
    """Test 1mo works if starting date is the 31th of a month."""
    starting_date = datetime(2020, 1, 31)

    result = convert_date("1mo", starting_date)

    assert result == datetime(2020, 2, 29)
Ejemplo n.º 3
0
def test_next_weekday_if_weekdays_are_equal() -> None:
    """
    Given: starting date is Monday, which is weekday 0
    When: using convert_date to get the next Monday, which is weekday 0
    Then: the next Monday is returned.
    """
    starting_date = datetime(2020, 1, 6)

    result = convert_date("monday", starting_date)

    assert result == datetime(2020, 1, 13)
Ejemplo n.º 4
0
def test_next_weekday_if_starting_weekday_is_greater() -> None:
    """
    Given: starting date is Wednesday, which is weekday 2
    When: using convert_date to get the next Tuesday, which is weekday 1
    Then: the next Tuesday is returned.
    """
    starting_date = datetime(2020, 1, 8)

    result = convert_date("tuesday", starting_date)

    assert result == datetime(2020, 1, 14)
Ejemplo n.º 5
0
def test_next_relative_month_works_if_start_from_fifth_day_of_month() -> None:
    """
    Given: The fifth Monday of the month
    When: asking for the next relative month
    Then: the first Monday of the following to the next month is returned
    """
    starting_date = datetime(2019, 12, 30)

    result = convert_date("1rmo", starting_date)

    assert result == datetime(2020, 2, 3)
Ejemplo n.º 6
0
def test_next_relative_month_works_if_start_from_second_day_of_month() -> None:
    """
    Given: The second Wednesday of the month
    When: asking for the next relative month
    Then: the second Wednesday of the next month is returned
    """
    starting_date = datetime(2020, 1, 8)

    result = convert_date("1rmo", starting_date)

    assert result == datetime(2020, 2, 12)
Ejemplo n.º 7
0
def test_next_relative_month_works_if_start_from_first_day_of_month() -> None:
    """
    Given: The first Tuesday of the month as the starting date
    When: Asking for the next relative month day.
    Then: The 1st Tuesday of the next month is returned
        A month is not equal to 30d, it depends on the days of the month,
        use this in case you want for example the 3rd Friday of the month
    """
    starting_date = datetime(2020, 1, 7)

    result = convert_date("1rmo", starting_date)

    assert result == datetime(2020, 2, 4)
Ejemplo n.º 8
0
def test_convert_date_accepts_today(now: datetime) -> None:
    """Test that today works as date input."""
    result = convert_date("today")

    assert result == now
Ejemplo n.º 9
0
def test_convert_date_accepts_now(now: datetime) -> None:
    """Test that now works as date input."""
    result = convert_date("now")

    assert result == now
Ejemplo n.º 10
0
def test_convert_date_raises_error_if_wrong_format() -> None:
    """Test error is returned if the date format is wrong."""
    with pytest.raises(exceptions.DateParseError):
        convert_date("wrong date string")
Ejemplo n.º 11
0
def test_if_convert_date_accepts_days(now: datetime) -> None:
    """Test days works as date input."""
    result = convert_date("1d", now)

    assert result == now + timedelta(days=1)
Ejemplo n.º 12
0
def test_if_convert_date_accepts_hours(now: datetime) -> None:
    """Test hours works as date input."""
    result = convert_date("1h", now)

    assert result == now + timedelta(hours=1)
Ejemplo n.º 13
0
def test_if_convert_date_accepts_minutes(now: datetime) -> None:
    """Test minutes works as date input."""
    result = convert_date("1m", now)

    assert result == now + timedelta(minutes=1)
Ejemplo n.º 14
0
def test_if_convert_date_accepts_seconds(now: datetime) -> None:
    """Test seconds works as date input."""
    result = convert_date("1s", now)

    assert result == now + timedelta(seconds=1)