Beispiel #1
0
def test_rfc822_minus_tz():
    codec = Rfc822()
    utc_string = 'Sat, 07 Sep 2013 01:20:43 -0000'
    utc_datetime = datetime.datetime(2013, 9, 7, 1, 20, 43,
                                     tzinfo=utc)

    assert codec.decode(utc_string) == utc_datetime
Beispiel #2
0
def test_rfc822_with_white_space():
    codec = Rfc822()
    utc_string = '''
        Sat, 07 Sep 2013 01:20:43 +0000
    '''
    utc_datetime = datetime.datetime(2013, 9, 7, 1, 20, 43, tzinfo=utc)

    assert codec.decode(utc_string) == utc_datetime
Beispiel #3
0
def test_rfc822_raise():
    codec = Rfc822()
    invalid_kst_string = 'Sat, 07 Sep 2013 01:20:43 +0900w'
    with raises(DecodeError):
        decoded = codec.decode(invalid_kst_string)
        print(decoded)
    datetime_not_contains_tzinfo = datetime.datetime.now()
    not_valid_rfc822_string = 'Sat, 07 Sep 2013 01:20:43'
    with raises(EncodeError):
        codec.encode("it is not datetime.datetime object")
    with raises(EncodeError):
        codec.encode(datetime_not_contains_tzinfo)
    with raises(DecodeError):
        codec.decode(not_valid_rfc822_string)
Beispiel #4
0
def test_rfc822(ms, string, expected):
    codec = Rfc822(microseconds=ms)
    assert codec.decode(string) == expected
    assert codec.encode(expected) == string
    # Locale might affect to the way it parses datetime
    default_locale = locale.getlocale(locale.LC_TIME)
    alt_locales = available_alternative_locales()
    if len(alt_locales) > 5:
        alt_locales = random.sample(alt_locales, 5)
    try:
        for alt_locale in alt_locales:
            try:
                locale.setlocale(locale.LC_TIME, alt_locale)
            except locale.Error:
                pass
            assert codec.decode(string) == expected
            assert codec.encode(expected) == string
    finally:
        locale.setlocale(locale.LC_TIME, default_locale)
Beispiel #5
0
def test_rfc822_namedtz():
    codec = Rfc822()
    gmt_string = 'Sat, 07 Sep 2013 01:20:43 GMT'
    gmt_datetime = datetime.datetime(2013, 9, 7, 1, 20, 43, tzinfo=utc)
    assert codec.decode(gmt_string) == gmt_datetime