Example #1
0
def test_can_coerce_and_raise_UnknownTimeZoneError_or_ValueError(backend):
    tzcol = TimezoneType(backend=backend)
    exceptions = (ValueError, pytz.exceptions.UnknownTimeZoneError,
                  zoneinfo.ZoneInfoNotFoundError)
    with pytest.raises(exceptions):
        tzcol._coerce('SolarSystem/Mars')
    with pytest.raises(exceptions):
        tzcol._coerce('')
def test_can_coerce_None(backend):
    tzcol = TimezoneType(backend=backend)
    assert tzcol._coerce(None) is None
def test_can_coerce_and_raise_UnknownTimeZoneError_or_ValueError(backend):
    tzcol = TimezoneType(backend=backend)
    with pytest.raises((ValueError, pytz.exceptions.UnknownTimeZoneError)):
        tzcol._coerce('SolarSystem/Mars')
    with pytest.raises((ValueError, pytz.exceptions.UnknownTimeZoneError)):
        tzcol._coerce('')
def test_can_coerce_string_for_dateutil_zone(zone):
    tzcol = TimezoneType(backend='dateutil')
    assert isinstance(tzcol._coerce(zone), tzfile)
def test_can_coerce_string_for_pytz_zone(zone):
    tzcol = TimezoneType(backend='pytz')
    assert tzcol._coerce(zone).zone == zone
def test_can_coerce_pytz_StaticTzInfo():
    tzcol = TimezoneType(backend='pytz')
    tz = pytz.timezone('Pacific/Truk')
    assert isinstance(tz, pytz.tzfile.StaticTzInfo)
    assert tzcol._coerce(tz) is tz
def test_can_coerce_pytz_DstTzInfo():
    tzcol = TimezoneType(backend='pytz')
    tz = pytz.timezone('America/New_York')
    assert isinstance(tz, pytz.tzfile.DstTzInfo)
    assert tzcol._coerce(tz) is tz
Example #8
0
def test_can_coerce_None(backend):
    tzcol = TimezoneType(backend=backend)
    assert tzcol._coerce(None) is None
Example #9
0
def test_can_coerce_and_raise_UnknownTimeZoneError_or_ValueError(backend):
    tzcol = TimezoneType(backend=backend)
    with pytest.raises((ValueError, pytz.exceptions.UnknownTimeZoneError)):
        tzcol._coerce('SolarSystem/Mars')
    with pytest.raises((ValueError, pytz.exceptions.UnknownTimeZoneError)):
        tzcol._coerce('')
Example #10
0
def test_can_coerce_string_for_dateutil_zone(zone):
    tzcol = TimezoneType(backend='dateutil')
    assert isinstance(tzcol._coerce(zone), tzfile)
Example #11
0
def test_can_coerce_string_for_pytz_zone(zone):
    tzcol = TimezoneType(backend='pytz')
    assert tzcol._coerce(zone).zone == zone
Example #12
0
def test_can_coerce_pytz_StaticTzInfo():
    tzcol = TimezoneType(backend='pytz')
    tz = pytz.timezone('Pacific/Truk')
    assert isinstance(tz, pytz.tzfile.StaticTzInfo)
    assert tzcol._coerce(tz) is tz
Example #13
0
def test_can_coerce_pytz_DstTzInfo():
    tzcol = TimezoneType(backend='pytz')
    tz = pytz.timezone('America/New_York')
    assert isinstance(tz, pytz.tzfile.DstTzInfo)
    assert tzcol._coerce(tz) is tz
Example #14
0
def test_can_coerce_string_for_zoneinfo_zone(zone):
    tzcol = TimezoneType(backend='zoneinfo')
    assert str(tzcol._coerce(zone)) == zone