Implement feature new format: Cli. Generate adapter for tabulate. This close issue #340

* Implement feature new format: Cli. Generate adapter for  tabulate. This close issue #340

* Write respective tests.

* Correct name Clase Base Test

* Implement missing class method to export cli.

* Remove property headers in method export book Cli.

* Remove cli from list to test Iterable data books.
This commit is contained in:
Daniel Santos
2019-10-30 14:13:39 +01:00
committed by GitHub
parent 34fe72305e
commit c26159d48f
5 changed files with 37 additions and 1 deletions
+1
View File
@@ -9,6 +9,7 @@ install = [
'xlrd',
'xlwt',
'pyyaml',
'tabulate',
]
+8
View File
@@ -621,6 +621,14 @@ class Dataset:
"""
pass
@property
def cli():
"""A CLI table representation of the :class:`Dataset` object.
.. note:: This method can be used for export only.
"""
pass
@property
def jira():
"""A Jira table representation of the :class:`Dataset` object.
+2 -1
View File
@@ -14,6 +14,7 @@ from . import _tsv as tsv
from . import _xls as xls
from . import _xlsx as xlsx
from . import _yaml as yaml
from . import _cli as cli
# xlsx before as xls (xlrd) can also read xlsx
available = (json, xlsx, xls, yaml, csv, dbf, tsv, html, jira, latex, ods, df, rst)
available = (json, xlsx, xls, yaml, csv, dbf, tsv, html, jira, latex, ods, df, rst, cli)
+20
View File
@@ -0,0 +1,20 @@
""" Tablib - CLI Support
"""
from tabulate import tabulate
title = 'cli'
extensions = ('txt',)
DEFAULT_FORMAT = 'plain'
def export_set(dataset, **kwargs):
"""Returns CLI representation of Dataset."""
if( dataset.headers is not None ):
kwargs.setdefault('headers', dataset.headers)
kwargs.setdefault('tablefmt', DEFAULT_FORMAT)
return tabulate( dataset, **kwargs)
def export_book(dataset, **kwargs):
"""Returns CLI representation of Dataset."""
kwargs.setdefault('tablefmt', DEFAULT_FORMAT)
return tabulate( dataset, **kwargs)
+6
View File
@@ -1214,6 +1214,12 @@ class JiraTests(BaseTestCase):
def test_jira_export_empty_dataset(self):
self.assertTrue(tablib.Dataset().jira is not None)
class CliTests(BaseTestCase):
def test_cli_export(self):
self.assertEqual('a b c', tablib.Dataset(['a', 'b', 'c']).cli)
def test_cli_export_github(self):
self.assertEqual('|---|---|---|\n| a | b | c |', tablib.Dataset(['a','b','c']).export('cli',tablefmt='github'))
class DocTests(unittest.TestCase):