Skip to content
Merged
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
14 changes: 12 additions & 2 deletions renga/models/_tabulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@
# limitations under the License.
"""Print a collection as a table."""

from datetime import datetime
from operator import attrgetter

from tabulate import tabulate as tblte


def tabulate(collection, headers, **kwargs):
def format_cell(cell, datetime_fmt=None):
"""Format a cell."""
if datetime_fmt and isinstance(cell, datetime):
return cell.strftime(datetime_fmt)
return cell


def tabulate(collection, headers, datetime_fmt='%Y-%m-%d %H:%M:%S',
**kwargs):
"""Pretty-print a collection."""
table = [attrgetter(*headers)(c) for c in collection]
table = [(format_cell(cell, datetime_fmt=datetime_fmt)
for cell in attrgetter(*headers)(c)) for c in collection]
return tblte(table, headers=[h.upper() for h in headers], **kwargs)
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_deployer(runner, deployer_responses):
result = runner.invoke(cli.cli, ['contexts', 'list'])
assert result.exit_code == 0
assert context_id in result.output
assert '1984-01-01 00:00:00+00:00' in result.output
assert '1984-01-01 00:00:00' in result.output

result = runner.invoke(cli.cli, ['contexts', 'run', context_id, 'docker'])
assert result.exit_code == 0
Expand All @@ -226,7 +226,7 @@ def test_deployer(runner, deployer_responses):
assert result.exit_code == 0
assert execution_id in result.output
assert 'running' in result.output
assert '1984-01-01 00:00:00+00:00' in result.output
assert '1984-01-01 00:00:00' in result.output

result = runner.invoke(cli.cli,
['executions', 'logs', context_id, execution_id])
Expand Down