Skip to content

Commit 908c96c

Browse files
committed
Refined report subpackage
1 parent afc5773 commit 908c96c

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/tinyscript/report/base.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ def output(f):
1313
@wraps(f)
1414
def _wrapper(self, *args, **kwargs):
1515
from os.path import exists, splitext
16-
if 'text' in kwargs:
17-
kwargs.pop('text', None)
18-
warn("'text' keyword has been deprecated, please use 'save_to_file' instead", DeprecationWarning)
1916
s2f = kwargs.pop('save_to_file', False)
2017
r = f(self, *args, **kwargs)
2118
if not s2f or r is None:
@@ -27,8 +24,6 @@ def _wrapper(self, *args, **kwargs):
2724
elif f.__name__ == "yaml":
2825
from yaml import dump
2926
r = dump(r, indent=kwargs.get('indent', 2), width=kwargs.get('width', 0))
30-
if not isinstance(r, str):
31-
raise TypeError("got report data in an unknown format (%s) ; should be str" % type(r).__name__)
3227
filename = "{}.{}".format(self.filename, f.__name__)
3328
while exists(filename):
3429
name, ext = splitext(filename)
@@ -89,7 +84,7 @@ def html(self, indent=4):
8984
return ""
9085

9186
@output
92-
def json(self):
87+
def json(self, indent=2):
9388
return {self.name: self.data}
9489

9590
@output
@@ -103,7 +98,7 @@ def xml(self, indent=2):
10398

10499
@output
105100
def yaml(self, indent=2):
106-
return self.json(indent=indent, save_to_file=False)
101+
return self.json(indent=indent)
107102

108103
@staticmethod
109104
def format_data(data, fmt):

src/tinyscript/report/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def html(self, indent=4):
171171
return s + ">"
172172

173173
@output
174-
def json(self):
174+
def json(self, indent=2):
175175
return {}
176176

177177
@output
@@ -263,7 +263,7 @@ def html(self, indent=4):
263263
return nl.join(r)
264264

265265
@output
266-
def json(self, orient="split"):
266+
def json(self, indent=2, orient="split"):
267267
d = {}
268268
if len(self.data) > 0:
269269
ch = (self.column_headers[1:] if self.row_headers else self.column_headers) if self.column_headers else \

tests/test_report.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
from utils import *
88

99

10+
FORMATS = ["csv", "html", "json", "md", "pdf", "rst", "xml", "yaml"]
11+
12+
1013
class TestReport(TestCase):
1114
def __try_formats(self, element):
12-
for fmt in ["csv", "html", "json", "md", "rst", "xml"]:
15+
for fmt in FORMATS:
16+
if fmt == "pdf":
17+
continue
1318
self.assertIsNotNone(getattr(element, fmt)())
1419

1520
def test_report_text_elements(self):
@@ -49,7 +54,7 @@ def test_report_methods(self):
4954
r.extend(l)
5055
r.append("Free text")
5156
self.__try_formats(r)
52-
for fmt in ["csv", "json", "md", "pdf", "rst", "xml", "yaml"]:
57+
for fmt in FORMATS:
5358
getattr(r, fmt)(save_to_file=True)
5459
remove("report.%s" % fmt)
5560
r.clear()
@@ -68,12 +73,12 @@ def test_report_file_generation(self):
6873
remove("report-3.html")
6974
r.append(List("item1", "item2"))
7075
self.assertIsInstance(r.json(data_only=False), dict)
71-
for fmt in ["csv", "json", "md", "pdf", "rst", "xml", "yaml"]:
76+
for fmt in FORMATS:
7277
getattr(r, fmt)()
7378
r.pop()
7479
r.append(Table([["item1", "item2"]], column_headers=["h1", "h2"]))
7580
self.assertIsInstance(r.json(), dict)
76-
for fmt in ["csv", "json", "md", "pdf", "rst", "xml", "yaml"]:
81+
for fmt in FORMATS:
7782
getattr(r, fmt)(save_to_file=True)
7883
remove("report.%s" % fmt)
7984

@@ -99,6 +104,6 @@ def test_report_table(self):
99104
getattr(t, fmt)()
100105
r = Report()
101106
r.append(t)
102-
for fmt in ["csv", "json", "md", "pdf", "rst", "xml", "yaml"]:
107+
for fmt in FORMATS:
103108
getattr(r, fmt)()
104109

0 commit comments

Comments
 (0)