def table(data: TableDataT, *, title: str, target: IO = None, tty: bool = None, **kwargs: Any) -> Table: """Create suitable :pypi:`terminaltables` table for target. Arguments: data (Sequence[Sequence[str]]): Table data. target (IO): Target should be the destination output file for your table, and defaults to :data:`sys.stdout`. ANSI codes will be used if the target has a controlling terminal, but not otherwise, which is why it's important to pass the correct output file. """ if target is None: target = sys.stdout if tty is None: tty = isatty(target) if tty is None: tty = False return _get_best_table_type(tty)(data, title=title, **kwargs)
def test_isatty(): m = Mock() m.isatty.return_value = True assert isatty(m) m.isatty.side_effect = AttributeError() assert not isatty(m)