mirror of
https://github.com/kennethreitz/tablib.git
synced 2026-06-05 06:56:13 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user