コード例 #1
0
def test_table_api_to_from_bytes():
    data = {"foo": "bar", "hello": "world", "abc": 123}
    table = Table(name="table", data=data)
    table_bytes = table.to_bytes()
    new_table = Table().from_bytes(table_bytes)
    assert new_table.name == "table"
    assert len(new_table) == 3
    assert new_table["foo"] == "bar"
    assert new_table[get_string_id("foo")] == "bar"
    new_table2 = Table(data={"def": 456})
    new_table2.from_bytes(table_bytes)
    assert len(new_table2) == 3
    assert "def" not in new_table2
コード例 #2
0
def test_table_api():
    table = Table(name="table")
    assert table.name == "table"
    assert len(table) == 0
    assert "abc" not in table
    data = {"foo": "bar", "hello": "world"}
    table = Table(name="table", data=data)
    assert len(table) == len(data)
    assert "foo" in table
    assert get_string_id("foo") in table
    assert table["foo"] == "bar"
    assert table[get_string_id("foo")] == "bar"
    assert table.get("foo") == "bar"
    assert table.get("abc") is None
    table["abc"] = 123
    assert table["abc"] == 123
    assert table[get_string_id("abc")] == 123
    table.set("def", 456)
    assert table["def"] == 456
    assert table[get_string_id("def")] == 456
コード例 #3
0
def lemmatizer():
    lookup = Table(data={"dogs": "dog", "boxen": "box", "mice": "mouse"})
    return Lemmatizer(lookup=lookup)