Esempio n. 1
0
def test_invalid_options():
    table = Table()
    with pytest.raises(ValueError):
        table.options = 1

    with pytest.raises(ValueError):
        table.options = [1, 2, 3]
Esempio n. 2
0
def test_source():
    table = Table()
    google = DummyGoogleObject()
    google.visualization = DummyGoogleObject()
    google.visualization.Query = DummyGoogleObject()
    result = eval(table.source())
    expected = {"status": "OK", "table": {"rows": [], "cols": []}, "reqId": 0, "version": 0.6}
    assert result == expected
Esempio n. 3
0
def test_insert_rows():
    table = Table(valid_schema)
    table.extend([bob, (20, 'Sally')])
    rows = table.rows
    row = rows.pop()
    assert row['name'].value == 'Sally'

    row = rows.pop()
    assert row['age'].value == 18
Esempio n. 4
0
def test_add_column():
    table = Table()
    table.add_column(**valid_schema[0])
    table.add_column(**valid_schema[1])
    assert table.schema['age'].id == "age"
    assert table.schema['name'].type == str
    with pytest.raises(TypeError):
        table.add_column('height')
Esempio n. 5
0
def test_with_label():
    table = Table(valid_schema)
    table.append(bob)
    rows = table.rows
    row = rows.pop()
    assert row['name'].label is None

    harry = (17, ('Harry', 'Big Man'))
    table.append(harry)
    row = rows.pop()
    assert row['age'].value == 17
    assert row['name'].value == 'Harry'
    assert row['name'].label == 'Big Man'
Esempio n. 6
0
def test_cell_options():
    table = Table(valid_schema)

    jack = [17, ('Jack', 'Beanstalk', dict(key='value'))]
    table.append(jack)
    row = table.rows.pop()
    assert row['name'].options == {'key':'value'}

    kate = [26, dict(value='Kate', options={'hair':'long'})]
    table.append(kate)
    row = table.rows.pop()
    assert row['name'].value == 'Kate'
    assert row['name'].label == None
    assert row['name'].options == {'hair':'long'}
Esempio n. 7
0
def test_insert_row():
    table = Table(valid_schema)
    table.append(bob)
    row = table.rows.pop()
    assert row['age'].value == 18
    assert row['name'].value == 'Bob'
Esempio n. 8
0
def test_insert_row_no_columns():
    table = Table()
    with pytest.raises(ValueError):
        table.append(('Bob', ))
Esempio n. 9
0
def test_add_column_with_existing_data():
    table = Table(valid_schema)
    table.append(bob)
    with pytest.raises(ValueError):
        table.add_column('size', str)
Esempio n. 10
0
def test_duplicate_column():
    table = Table(valid_schema)
    with pytest.raises(ValueError):
        table.add_column('age', int)
Esempio n. 11
0
def test_missing_id():
    with pytest.raises(TypeError):
        Table(schema_missing_id)
Esempio n. 12
0
def test_constructor():
    table = Table()
    assert list(table.schema.keys()) == []
    assert table.rows == []
Esempio n. 13
0
def test_encode():
    table = Table()
    expected = {"rows": [], "cols": []}
    result = table.encode()
    assert json.loads(result) == expected
Esempio n. 14
0
def test_dictionary_interface():
    table = Table(options={'foo':'bar'})
    expected = dict(rows=[], cols=[], p={'foo':'bar'})
    assert dict(table) == expected
Esempio n. 15
0
def test_invalid_row():
    table = Table(valid_schema)
    with pytest.raises(ValueError):
        table.append([1, 2, 3])
Esempio n. 16
0
def test_options():
    table = Table()
    table.options = dict(bar='baz')
    assert table.options == {'bar':'baz'}
Esempio n. 17
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':[]}