def test_table_answer_element_deser():
    """Check proper deserialization for a valid table answer."""
    answer = {
        "answerElements": [{
            "metadata": {
                "columnMetadata": [
                    {
                        "name": "col1",
                        "schema": "String"
                    },
                    {
                        "name": "col2",
                        "schema": "String"
                    },
                ]
            },
            "rows": [{
                "col1": "value1",
                "col2": "value2"
            }],
        }]
    }
    table = TableAnswer(answer)

    assert len(table.metadata.column_metadata) == 2
    assert table.metadata.column_metadata[0].name == "col1"
    assert len(table.rows) == 1
    assert table.rows[0].get("col1") == "value1"
    assert table.rows[0].get("col2") == "value2"
    assert not table.frame().empty
def test_table_answer_immutable_lists():
    answer = {
        "answerElements": [{
            "metadata": {
                "columnMetadata": [{
                    "name": "col1",
                    "schema": "List<String>"
                }]
            },
            "rows": [{
                "col1": ["e1", "e2", "e3"]
            }],
        }]
    }

    table = TableAnswer(answer)
    assert isinstance(table.frame().loc[0]["col1"], ListWrapper)
Exemple #3
0
def test_table_answer_element_deser_no_rows():
    """Check deserialization creates empty table when no rows are present."""
    answer = {
        "answerElements": [{
            "metadata": {
                "columnMetadata": [{
                    "name": "col1",
                    "schema": "Node"
                }]
            }
        }]
    }
    table = TableAnswer(answer)

    assert len(table.metadata.column_metadata) == 1
    assert table.metadata.column_metadata[0].name == "col1"
    assert len(table.rows) == 0
    assert table.frame().empty