def test_signal_last_dictionary(d): """It returns last element for dictionary""" *_, last = d for is_last_element, var in core.signal_last(d.items()): if is_last_element: key, value = var assert key == last
def test_signal_last_truth(d): """It returns True for last element""" dict_len = len(d) for i, (is_last_element, var) in enumerate(core.signal_last(d.items()), start=1): if i != dict_len: assert is_last_element == False if i == dict_len: assert is_last_element == True
def print_table(decoded: list, header: str = "Prediction summary", print: bool = True) -> Table: """Prints table summary of predicted labels""" table = Table(show_header=True, title=header) table.add_column("Class", ) table.add_column("Count") table.add_column("Percentage") total = len(decoded) frequencies = itertoolz.frequencies(decoded) for is_last_element, var in core.signal_last(frequencies.items()): key, value = var count = value percentage = round((count / total) * 100, 2) if is_last_element: table.add_row(key, str(count), f"{percentage}", end_section=True) table.add_row("Total", str(total), "") else: table.add_row(key, str(count), f"{percentage}") if print: console.print(table) return table
def test_signal_last_raises_value_error_with_no_length(): """It raises value error when no length""" with pytest.raises(ValueError): items: List[Any] = [] for i in core.signal_last(items): print(i)
def test_signal_last(l): """It returns last element in list when `is""" *_, last = l for is_last_element, var in core.signal_last(l): if is_last_element: assert var == last