Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] read_data returns correct result when there's only one category #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions data/single_category.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Example Data Set 5 with 3 Categories
@ Boys
2007,183.32
2008,231.23
2009,16.43
2010,50.21
2011,508.97
2012,212.05
2014,30.0
12 changes: 6 additions & 6 deletions termgraph/termgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,18 +613,18 @@ def read_data(args):
line = line.strip()
if line:
if not line.startswith("#"):
if line.find(DELIM) > 0:
cols = line.split(DELIM)
else:
cols = line.split()

# Line contains categories.
if line.startswith("@"):
if line.startswith('@'):
cols = line.split(DELIM)
cols[0] = cols[0].replace("@ ", "")
categories = cols

# Line contains label and values.
else:
if line.find(DELIM) > 0:
cols = line.split(DELIM)
else:
cols = line.split()
labels.append(cols[0].strip())
data_points = []
for i in range(1, len(cols)):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_termgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,22 @@ def test_read_data_returns_correct_results(self):
[30.0, 20.0]]
assert colors == []

def test_read_data_single_category(self):
args = {'filename': 'data/single_category.dat', 'title': None, 'width': 50,
'format': '{:<5.2f}', 'suffix': '', 'no_labels': False,
'color': None, 'vertical': False, 'stacked': False,
'different_scale': False, 'calendar': False, 'start_dt': None,
'custom_tick': '', 'delim': '', 'verbose': False,
'version': False}
categories, labels, data, colors = tg.read_data(args)
assert categories == ['Boys']
assert labels == ['2007', '2008', '2009', '2010',
'2011', '2012', '2014']
assert data == [[183.32], [231.23], [16.43],
[50.21], [508.97], [212.05],
[30.0]]
assert colors == []

def test_read_data_with_title_prints_title(self):
with patch('sys.stdout', new=StringIO()) as output:
args = {'filename': 'data/ex4.dat', 'title': 'spaghetti', 'width': 50,
Expand Down Expand Up @@ -569,3 +585,4 @@ def test_calendar_heatmap_without_start_date_prints_correctly(self):
tg.calendar_heatmap(data, labels, args)
output = output.getvalue().strip()
assert output == 'Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep \nMon: \x1b[94m▒\x1b[0m\x1b[94m▒\x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nTue: \x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nWed: \x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nThu: \x1b[94m▓\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nFri: \x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nSat: \x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m█\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\nSun: \x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m▒\x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m\x1b[94m \x1b[0m'