示例#1
0
def test__str_to_datetime__valid() -> None:

    date_YMD: str = f"2020{Defaults.DATE_SEPARATOR}01{Defaults.DATE_SEPARATOR}01"
    date_MDY: str = f"01{Defaults.DATE_SEPARATOR}01{Defaults.DATE_SEPARATOR}2020"
    date_DMY: str = f"01{Defaults.DATE_SEPARATOR}01{Defaults.DATE_SEPARATOR}2020"

    for date in [date_YMD, date_MDY, date_DMY]:
        datetime_date = Utils.str_to_datetime(date)
        assert datetime_date == datetime.datetime(2020, 1, 1)

    date_ISO: str = "2020-01-01 12:00:00"
    datetime_iso = Utils.str_to_datetime(date_ISO)
    assert datetime_iso == datetime.datetime(2020, 1, 1, 12, 0, 0)
示例#2
0
def test__str_to_datetime__invalid() -> None:

    date: str = "01 01 2020"

    with pytest.raises(ValueError):
        Utils.str_to_datetime(date)