def test_TableBundle_from_file():
    """ Verify that TableBundle can be generated from top level API methods: read_csv, read_excel
    """
    input_file = input_dir() / "bundle.csv"
    bundle = TableBundle(read_csv(input_file), as_dataframe=True)
    assert bundle is not None
    assert len(bundle) == 3
    assert isinstance(bundle[0], TableDataFrame)

    assert bundle.unique("spelling_numbers").spelling[1] == "six"
    assert bundle[1].spelling[0] == "one"
    assert len(bundle.all("places_to_go")) == 2

    bundle = TableBundle(read_csv(input_file), as_dataframe=False)
    assert bundle is not None
    assert len(bundle) == 3
    assert isinstance(bundle[1], Table)
    assert bundle.spelling_numbers["spelling"].values[0] == "one"
    assert len(bundle.all("places_to_go")) == 2

    input_file = input_dir() / "bundle.xlsx"
    bundle = TableBundle(read_excel(input_file), as_dataframe=False)
    assert bundle is not None
    assert len(bundle) == 3
    assert isinstance(bundle[1], Table)
    assert bundle.spelling_numbers["spelling"].values[0] == "one"
    assert len(bundle.all("places_to_go")) == 2

    bundle = TableBundle(read_excel(input_file), as_dataframe=True)
    assert bundle is not None
    assert len(bundle) == 3
    assert isinstance(bundle[0], TableDataFrame)

    assert bundle.unique("spelling_numbers").spelling[1] == "six"
    assert bundle[1].spelling[0] == "one"
    assert len(bundle.all("places_to_go")) == 2
Пример #2
0
def test_TableBundle_all():
    """ Verify that all() is functioning as expected
    """
    bundle1 = TableBundle(parse_blocks(cell_rows))
    # bundle1 now contains one 'foo' and one 'infs'
    assert len(bundle1) == 2

    lst = bundle1.all("-not there-")
    assert len(lst) == 0

    lst = bundle1.all("foo")
    assert len(lst) == 1
    for tab in lst:
        assert tab.name == "foo"

    lst = bundle1.all("infs")
    assert len(lst) == 1
    for tab in lst:
        assert tab.name == "infs"

    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

    lst = bundle2.all("-not there-")
    assert len(lst) == 0

    lst = bundle2.all("foo")
    assert len(lst) == 2
    for tab in lst:
        assert tab.name == "foo"

    lst = bundle2.all("infs")
    assert len(lst) == 2
    for tab in lst:
        assert tab.name == "infs"