Skip to content

Commit bade6ea

Browse files
fix output for empty array
1 parent 2e4ba81 commit bade6ea

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
jtbl changelog
22

3+
20230522 v1.5.2
4+
- Fix output for empty array
5+
36
20230228 v1.5.1
47
- Preserve long float formatting
58

jtbl/cli.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tabulate
88
import shutil
99

10-
__version__ = '1.5.1'
10+
__version__ = '1.5.2'
1111
SUCCESS, ERROR = True, False
1212

1313

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

173173
return SUCCESS, data
174174

175+
if data == []:
176+
return SUCCESS, ''
177+
178+
return ERROR, data
179+
175180

176181
def get_headers(data):
177182
"""scan the data and return a dictionary of all of the headers in order"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name='jtbl',
8-
version='1.5.1',
8+
version='1.5.2',
99
author='Kelly Brazil',
1010
author_email='[email protected]',
1111
description='A simple cli tool to print JSON and JSON Lines data as a table in the terminal.',

tests/test_make_table.py

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ def setUp(self):
99
self.SUCCESS, self.ERROR = True, False
1010
self.columns = 80
1111

12+
def test_empty_dict(self):
13+
stdin = {}
14+
expected = ''
15+
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))
16+
17+
def test_empty_list(self):
18+
stdin = []
19+
expected = ''
20+
self.assertEqual(jtbl.cli.make_table(data=stdin, columns=self.columns), (self.SUCCESS, expected))
21+
1222
def test_simple_key_value(self):
1323
stdin = [{"key": "value"}]
1424
expected = textwrap.dedent('''\

0 commit comments

Comments
 (0)