Пример #1
0
def data():
    folder = os.path.split(__file__)[0]
    db = sqlite3.connect(os.path.join(folder, "sample.db"))
    c = db.cursor()
    c.execute("SELECT name, salary FROM employees")
    cols = [
        dict(id=col[0], label=col[0].capitalize(), type=col[1])
        for col in c.description
    ]
    # sqlite3 unfortunately does not provide type information
    cols[0]['type'] = unicode
    cols[1]['type'] = float

    t = Table(cols)
    for r in c.fetchall():
        name, value = r
        label = "${0}".format(value)
        t.append([name, (value, label)])

    return encoder.encode(t)
Пример #2
0
def test_encode_time():
    time = datetime.time(10, 30, 45)
    js = encode(time)
    python = json.loads(js)
    assert python == [10, 30, 45]
Пример #3
0
def test_encode_unknown():
    with pytest.raises(TypeError):
        encode(object)
Пример #4
0
def test_encode_table():
    from gviz_data_table.table import Table
    table = Table()
    js = encode(table)
    python = json.loads(js)
    assert python == {'rows':[], 'cols':[]}
Пример #5
0
def test_encode_column():
    from gviz_data_table.column import Column
    schema = Column(id='age', type=int)
    js = encode(schema)
    python = json.loads(js)
    assert python == {"type": "number", "id": "age", "label": "age"}
Пример #6
0
def test_encode_cell():
    from gviz_data_table.cell import Cell
    c = Cell(int, 1)
    js = encode(c)
    python = json.loads(js)
    assert python == {"v": 1}
Пример #7
0
def test_encode_datetime():
    today = datetime.datetime(2012, 1, 31, 12, 30, 45)
    js = encode(today)
    python = json.loads(js)
    assert python == "Date(2012, 0, 31, 12, 30, 45)"
Пример #8
0
def test_encode_time():
    time = datetime.time(10, 30, 45)
    js = encode(time)
    python = json.loads(js)
    assert python == [10, 30, 45]
Пример #9
0
def test_encode_unknown():
    with pytest.raises(TypeError):
        encode(object)
Пример #10
0
def test_encode_table():
    from gviz_data_table.table import Table
    table = Table()
    js = encode(table)
    python = json.loads(js)
    assert python == {'rows':[], 'cols':[]}
Пример #11
0
def test_encode_column():
    from gviz_data_table.column import Column
    schema = Column(id='age', type=int)
    js = encode(schema)
    python = json.loads(js)
    assert python == {"type": "number", "id": "age", "label": "age"}
Пример #12
0
def test_encode_cell():
    from gviz_data_table.cell import Cell
    c = Cell(int, 1)
    js = encode(c)
    python = json.loads(js)
    assert python == {"v": 1}
Пример #13
0
def test_encode_datetime():
    today = datetime.datetime(2012, 1, 31, 12, 30, 45)
    js = encode(today)
    python = json.loads(js)
    assert python == "Date(2012, 0, 31, 12, 30, 45)"