예제 #1
0
def test_stringify_on_basic_list():
    """
    Test Simple List stringification.

    `datetime.datetime should be converted to `str`.
    """
    obj = [datetime(2016, 10, 20, 21, 10, 36, 621341)]
    assert formats.stringify(obj) == ['2016-10-20 21:10:36.621341']
예제 #2
0
def test_stringify_on_basic_dict():
    """
    Test Simple dictionary stringification.

    `datetime.datetime should be converted to `str`.
    """
    obj = {'now': datetime(2016, 10, 20, 21, 10, 36, 621341)}
    assert formats.stringify(obj) == {'now': '2016-10-20 21:10:36.621341'}
예제 #3
0
def test_stringify_on_nested_dict():
    """
    Test Stringification on nested dict.

    Ensure `datetime.datetime` is still converted when it is not a
    top level key.
    """
    obj = {"top_level": {"now": datetime(2016, 10, 20, 21, 10, 36, 621341)}}
    assert formats.stringify(obj) == {
        "top_level": {
            "now": '2016-10-20 21:10:36.621341'
        }
    }
예제 #4
0
def test_stringify_on_basic_list():
    """
    Test Simple List stringification.

    `datetime.datetime should be converted to `str`.
    """
    obj = [
        datetime(2016, 10, 20, 21, 10, 36, 621341),
        UUID('34aec16c-4606-4d33-adc2-661e35061cd0')
    ]
    assert formats.stringify(obj) == [
        '2016-10-20 21:10:36.621341', '34aec16c-4606-4d33-adc2-661e35061cd0'
    ]
예제 #5
0
def test_stringify_on_nested_list():
    """Test that `datetime.datetime` is stringified when inside nested list."""
    obj = {
        'nows': [
            datetime(2016, 10, 20, 21, 10, 36, 621341),
            UUID('34aec16c-4606-4d33-adc2-661e35061cd0')
        ]
    }

    expected = {
        'nows':
        ['2016-10-20 21:10:36.621341', '34aec16c-4606-4d33-adc2-661e35061cd0']
    }
    assert formats.stringify(obj) == expected
예제 #6
0
def test_stringify_on_basic_dict():
    """
    Test Simple dictionary stringification.

    `datetime.datetime should be converted to `str`.
    """
    obj = {
        'now': datetime(2016, 10, 20, 21, 10, 36, 621341),
        'uuid': UUID('34aec16c-4606-4d33-adc2-661e35061cd0')
    }
    assert formats.stringify(obj) == {
        'now': '2016-10-20 21:10:36.621341',
        'uuid': '34aec16c-4606-4d33-adc2-661e35061cd0'
    }
예제 #7
0
def test_stringify_on_nested_dict():
    """
    Test Stringification on nested dict.

    Ensure `datetime.datetime` is still converted when it is not a
    top level key.
    """
    obj = {
        "top_level": {
            "now": datetime(2016, 10, 20, 21, 10, 36, 621341),
            "uuid": UUID('34aec16c-4606-4d33-adc2-661e35061cd0')
        }
    }
    assert formats.stringify(obj) == {
        "top_level": {
            "now": '2016-10-20 21:10:36.621341',
            "uuid": '34aec16c-4606-4d33-adc2-661e35061cd0'
        }
    }
예제 #8
0
def test_stringify_on_nested_list():
    """Test that `datetime.datetime` is stringified when inside nested list."""
    obj = {'nows': [datetime(2016, 10, 20, 21, 10, 36, 621341)]}
    assert formats.stringify(obj) == {'nows': ['2016-10-20 21:10:36.621341']}