Esempio n. 1
0
def test_export_no_values(backend):
    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    assert contents == expected
Esempio n. 2
0
def test_export_no_values(backend):
    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    assert contents == expected
Esempio n. 3
0
def test_export_empty():
    b = SQLBackend('sqlite://')
    out_file = StringIO()
    export_json(b, out_file)

    contents = json.loads(out_file.getvalue())
    expected = {'version': ln.__version__, 'series': []}
    assert contents == expected
Esempio n. 4
0
def test_export_empty():
    b = SQLBackend('sqlite://')
    out_file = StringIO()
    export_json(b, out_file)

    contents = json.loads(out_file.getvalue())
    expected = {'version': ln.__version__, 'series': []}
    assert contents == expected
Esempio n. 5
0
def test_export_scalar(backend):
    backend.add_data('float', datetime(2012, 1, 15, 1, 0, 0), 1.0)
    backend.add_data('float', datetime(2012, 1, 30, 1, 0, 0), 2.0)

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][0]['points'] = [['2012-01-15 01:00:00', 1.0],
                                       ['2012-01-30 01:00:00', 2.0]]
    assert contents == expected
Esempio n. 6
0
def test_export_scalar(backend):
    backend.add_data('float', datetime(2012, 1, 15, 1, 0, 0), 1.0)
    backend.add_data('float', datetime(2012, 1, 30, 1, 0, 0), 2.0)

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][0]['points'] = [
        ['2012-01-15 01:00:00', 1.0],
        ['2012-01-30 01:00:00', 2.0]
    ]
    assert contents == expected
Esempio n. 7
0
def test_export_array(backend):
    backend.add_data('array', datetime(2012, 1, 15, 1, 0, 0),
                     [1.0, 2.0, 3.0, 4.0])
    backend.add_data('array', datetime(2012, 1, 30, 1, 0, 0),
                     [2.0, 4.0, 6.0, 8.0])

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][1]['points'] = [[
        '2012-01-15 01:00:00', [1.0, 2.0, 3.0, 4.0]
    ], ['2012-01-30 01:00:00', [2.0, 4.0, 6.0, 8.0]]]
    assert contents == expected
Esempio n. 8
0
def test_export_array(backend):
    backend.add_data('array',
        datetime(2012, 1, 15, 1, 0, 0), [1.0, 2.0, 3.0, 4.0])
    backend.add_data('array',
        datetime(2012, 1, 30, 1, 0, 0), [2.0, 4.0, 6.0, 8.0])

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][1]['points'] = [
        ['2012-01-15 01:00:00', [1.0, 2.0, 3.0, 4.0]],
        ['2012-01-30 01:00:00', [2.0, 4.0, 6.0, 8.0]]
    ]
    assert contents == expected
Esempio n. 9
0
def test_export_blob(backend):
    blob1 = b'\x00\x01\xff'
    blob2 = b'\x20\x40\x60'
    backend.add_data('blob', datetime(2012, 1, 15, 1, 0, 0), blob1)
    backend.add_data('blob', datetime(2012, 1, 30, 1, 0, 0), blob2)

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][2]['points'] = [[
        '2012-01-15 01:00:00',
        base64.b64encode(blob1).decode('utf-8')
    ], ['2012-01-30 01:00:00',
        base64.b64encode(blob2).decode('utf-8')]]
    assert contents == expected
Esempio n. 10
0
def test_export_blob(backend):
    blob1 = b'\x00\x01\xff'
    blob2 = b'\x20\x40\x60'
    backend.add_data('blob',
        datetime(2012, 1, 15, 1, 0, 0), blob1)
    backend.add_data('blob',
        datetime(2012, 1, 30, 1, 0, 0), blob2)

    out_file = StringIO()
    export_json(backend, out_file)

    contents = json.loads(out_file.getvalue())
    expected = basic_contents()
    expected['series'][2]['points'] = [
        ['2012-01-15 01:00:00', base64.b64encode(blob1).decode('utf-8')],
        ['2012-01-30 01:00:00', base64.b64encode(blob2).decode('utf-8')]
    ]
    assert contents == expected