コード例 #1
0
ファイル: test_api.py プロジェクト: bamishr/Python_Learning
def test_consolidate_InlineData():
    data = alt.InlineData(values=[{
        "a": 1,
        "b": 1
    }, {
        "a": 2,
        "b": 2
    }],
                          format={"type": "csv"})
    chart = alt.Chart(data).mark_point()

    with alt.data_transformers.enable(consolidate_datasets=False):
        dct = chart.to_dict()
    assert dct["data"]["format"] == data.format
    assert dct["data"]["values"] == data.values

    with alt.data_transformers.enable(consolidate_datasets=True):
        dct = chart.to_dict()
    assert dct["data"]["format"] == data.format
    assert list(dct["datasets"].values())[0] == data.values

    data = alt.InlineData(values=[], name="runtime_data")
    chart = alt.Chart(data).mark_point()

    with alt.data_transformers.enable(consolidate_datasets=False):
        dct = chart.to_dict()
    assert dct["data"] == data.to_dict()

    with alt.data_transformers.enable(consolidate_datasets=True):
        dct = chart.to_dict()
    assert dct["data"] == data.to_dict()
コード例 #2
0
def test_consolidate_InlineData():
    data = alt.InlineData(
        values=[{'a': 1, 'b': 1}, {'a': 2, 'b': 2}],
        format={'type': 'csv'}
    )
    chart = alt.Chart(data).mark_point()

    with alt.data_transformers.enable(consolidate_datasets=False):
        dct = chart.to_dict()
    assert dct['data']['format'] == data.format
    assert dct['data']['values'] == data.values

    with alt.data_transformers.enable(consolidate_datasets=True):
        dct = chart.to_dict()
    assert dct['data']['format'] == data.format
    assert list(dct['datasets'].values())[0] == data.values

    data = alt.InlineData(
        values=[],
        name='runtime_data'
    )
    chart = alt.Chart(data).mark_point()

    with alt.data_transformers.enable(consolidate_datasets=False):
        dct = chart.to_dict()
    assert dct['data'] == data.to_dict()

    with alt.data_transformers.enable(consolidate_datasets=True):
        dct = chart.to_dict()
    assert dct['data'] == data.to_dict()