def test_drop(): td = TabularData(["col1", "col2", "col3"]) td.append(["foo", "bar", "baz"]) assert list(td) == [["foo", "bar", "baz"]] td.drop("col2") assert td.keys() == ["col1", "col3"] assert list(td) == [["foo", "baz"]]
def test_fill_value(): td = TabularData(["col-1", "col-2", "col-3"], fill_value="?") td.append(["foo"]) assert list(td) == [["foo", "?", "?"]] td.extend( [ ["bar"], ["foobar", "foobar2"], ["f", "fo", "foo", "foob", "fooba", "foobar"], ] ) assert list(td) == [ ["foo", "?", "?"], ["bar", "?", "?"], ["foobar", "foobar2", "?"], ["f", "fo", "foo"], ] td.insert(1, ["lorem"]) assert td[1] == ["lorem", "?", "?"] td[0] = ["lorem", "ipsum"] assert td[0] == ["lorem", "ipsum", "?"] td[1:2] = [["f", "fo"]] assert td[1:2] == [["f", "fo", "?"]] td.add_column("col-4") assert td.keys() == ["col-1", "col-2", "col-3", "col-4"] assert td[0][3] == "?"
def test_list_operations(): td = TabularData(["col1", "col2", "col3"]) td.append(["1", "2", "3"]) assert list(td) == [["1", "2", "3"]] td.extend((["11", "12", "13"], ["21", "22", "23"])) assert list(td) == [ ["1", "2", "3"], ["11", "12", "13"], ["21", "22", "23"], ] td.insert(1, ["01", "02", "03"]) assert list(td) == [ ["1", "2", "3"], ["01", "02", "03"], ["11", "12", "13"], ["21", "22", "23"], ] assert td.shape == (3, 4) assert len(td) == 4 assert td[1] == ["01", "02", "03"] assert td[1:] == [ ["01", "02", "03"], ["11", "12", "13"], ["21", "22", "23"], ] assert td[::-1] == [ ["21", "22", "23"], ["11", "12", "13"], ["01", "02", "03"], ["1", "2", "3"], ] del td[1] assert list(td) == [ ["1", "2", "3"], ["11", "12", "13"], ["21", "22", "23"], ] assert td.shape == (3, 3) td[1:3] = [["51", "52", "53"], ["61", "62", "63"]] assert list(td) == [ ["1", "2", "3"], ["51", "52", "53"], ["61", "62", "63"], ] td[1] = ["41", "42", "43"] assert td[1] == ["41", "42", "43"] del td[1:3] assert td.shape == (3, 1) assert td.to_csv() == "col1,col2,col3\r\n1,2,3\r\n"
def test_protected(): td = TabularData(["col1", "col2", "col3", "other"]) td.append(["foo", "bar", "baz", "other_val"]) td.protect("col1", "col2") td.drop("col1", "col2", "col3", "other") assert td.keys() == ["col1", "col2"] assert list(td) == [["foo", "bar"]] td.unprotect("col2") td.drop("col1", "col2") assert td.keys() == ["col1"] assert list(td) == [["foo"]]
def _add_row( self, name: str, all_status: List[Dict], td: TabularData, ): if not all_status: row = [name, None, "offline"] td.append(row) for i, status in enumerate(all_status, start=1): row = [name, f"num_{i}", "running" if status else "offline"] for field in self.SHOWN_FIELD: value = str(status.get(field, "")) row.append(value) td.append(row)