Skip to content

Commit

Permalink
Added support for empty input in table()
Browse files Browse the repository at this point in the history
  • Loading branch information
olegstepanov committed Feb 26, 2020
1 parent 6c05bb5 commit b91d973
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions neuromation/cli/formatters/ftable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def table(
aligns: Sequence[Align] = (),
max_width: Optional[int] = None,
) -> Iterator[str]:
if not rows:
return

# Columns widths calculation
if len(widths) < len(rows[0]):
Expand Down
3 changes: 0 additions & 3 deletions neuromation/cli/formatters/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,5 @@ def __call__(self, images: Iterable[RemoteImage]) -> Iterable[str]:

class LongImagesFormatter(BaseImagesFormatter):
def __call__(self, images: Iterable[RemoteImage]) -> Iterable[str]:
if not images:
return ()

rows = [[str(image), image.https_url] for image in images]
return table(rows)
4 changes: 4 additions & 0 deletions tests/cli/test_ftable.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def test_multiline(self) -> None:


class TestTable:
def test_empty(self) -> None:
result = list(table(()))
assert len(result) == 0

def test_simple(self) -> None:
rows = [["a", "Alpha"], ["b", "Bravo"]]
result = list(
Expand Down

0 comments on commit b91d973

Please sign in to comment.