Skip to content

Commit

Permalink
fix output for empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjonbrazil committed May 22, 2023
1 parent 2e4ba81 commit bade6ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
jtbl changelog

20230522 v1.5.2
- Fix output for empty array

20230228 v1.5.1
- Preserve long float formatting

Expand Down
7 changes: 6 additions & 1 deletion jtbl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tabulate
import shutil

__version__ = '1.5.1'
__version__ = '1.5.2'
SUCCESS, ERROR = True, False


Expand Down Expand Up @@ -172,6 +172,11 @@ def check_data(data=None, columns=0):

return SUCCESS, data

if data == []:
return SUCCESS, ''

return ERROR, data


def get_headers(data):
"""scan the data and return a dictionary of all of the headers in order"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='jtbl',
version='1.5.1',
version='1.5.2',
author='Kelly Brazil',
author_email='[email protected]',
description='A simple cli tool to print JSON and JSON Lines data as a table in the terminal.',
Expand Down
10 changes: 10 additions & 0 deletions tests/test_make_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def setUp(self):
self.SUCCESS, self.ERROR = True, False
self.columns = 80

def test_empty_dict(self):
stdin = {}
expected = ''
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))

def test_empty_list(self):
stdin = []
expected = ''
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))

def test_simple_key_value(self):
stdin = [{"key": "value"}]
expected = textwrap.dedent('''\
Expand Down

0 comments on commit bade6ea

Please sign in to comment.