예제 #1
0
def test_TableBundle_iterator():
    """ Verify that iterator is functioning as expected
    """
    bundle = TableBundle(parse_blocks(cell_rows, to="pdtable"))
    count = 0
    seen = {}
    for tab in bundle:
        assert type(tab) is Table
        seen[tab.name] = tab
        count += 1
    assert count == 2
    assert len(seen) == 2
    assert seen["foo"] is not None
    assert seen["infs"] is not None

    """ Verify that we can iterate other types than pdtable
    """
    bundle = TableBundle(parse_blocks(cell_rows, to="cellgrid"))
    count = 0
    for tab in bundle:
        assert type(tab) is list
        assert tab[0][0] in {"**foo", "**infs"}
        count += 1
    assert count == 2
    assert bundle["foo"] is not None
    assert bundle["infs"] is not None

    bundle = TableBundle(parse_blocks(cell_rows, to="jsondata"))
    count = 0
    for tab in bundle:
        assert type(tab) is dict
        assert tab["name"] in {"foo", "infs"}
        count += 1
    assert count == 2
    assert bundle["foo"] is not None
    assert bundle["infs"] is not None
예제 #2
0
def test_TableBundle_in_operator():
    bundle = TableBundle(parse_blocks(cell_rows))
    assert "foo" in bundle
    assert "qux" not in bundle
예제 #3
0
def test_bundle_from_csv():

    bundle = TableBundle(parse_blocks(cell_rows), as_dataframe=True)

    assert bundle.foo.column.values[0] == "bar"
예제 #4
0
def test_TableBundle_getitem():
    """ Verify that unique() is functioning as expected
    """
    bundle1 = TableBundle(parse_blocks(cell_rows))
    # bundle1 now contains one 'foo' and one 'infs'
    assert len(bundle1) == 2

    with pytest.raises(LookupError):
        tab = bundle1["-not there-"]

    # verify getitem
    with pytest.raises(TypeError):
        tab = bundle1[bundle1]

    # hashed
    tab = bundle1["foo"]
    assert tab.name == "foo"

    tab = bundle1["infs"]
    assert tab.name == "infs"

    # indexed
    tab = bundle1[0]
    assert tab.name == "foo"

    tab = bundle1[1]
    assert tab.name == "infs"

    with pytest.raises(IndexError):
        tab = bundle1[2]

    cells2 = []
    cells2.extend(cell_rows)
    cells2.extend([])
    cells2.extend(cell_rows)

    bundle2 = TableBundle(parse_blocks(cells2))
    # bundle2 now contains two 'foo' and two 'infs'
    assert len(bundle2) == 4

    with pytest.raises(LookupError):
        tab = bundle2["-not there-"]

    with pytest.raises(LookupError):
        tab = bundle2["foo"]

    with pytest.raises(LookupError):
        tab = bundle2["infs"]

    # indexed
    tab = bundle2[0]
    assert tab.name == "foo"

    tab = bundle2[1]
    assert tab.name == "infs"

    tab = bundle2[2]
    assert tab.name == "foo"

    tab = bundle2[3]
    assert tab.name == "infs"

    with pytest.raises(IndexError):
        tab = bundle2[4]