converting tableprint from a module to a package

This commit is contained in:
Niru Maheswaranathan
2017-05-25 15:02:14 -07:00
parent d7596f611f
commit 6e94c9e99c
10 changed files with 177 additions and 148 deletions

View File

@@ -5,6 +5,7 @@ import pytest
def test_borders():
"""Tests printing of the top and bottom borders"""
# top
assert top(5, width=2, style='round') == '╭──┬──┬──┬──┬──╮'
@@ -16,11 +17,12 @@ def test_borders():
def test_row():
"""Tests printing of a single row of data"""
# valid
assert row("abc", width=3, style='round') == '│ a│ b│ c│'
assert row([1, 2, 3], width=3, style='clean') == ' 1 2 3 '
# invalid
with pytest.raises(ValueError) as context:
with pytest.raises(ValueError):
row([{}])

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from tableprint import table, banner, dataframe, hr
from tableprint import table, banner, dataframe, hrule
from io import StringIO
import numpy as np
@@ -23,6 +23,7 @@ def test_frame():
def __init__(self, data, headers):
self.data = data
self.columns = headers
def __array__(self):
return self.data
@@ -44,8 +45,8 @@ def test_banner():
assert output.getvalue() == '╒═╕\n│!│\n╘═╛\n'
def test_hr():
def test_hrule():
output = hr(1, width=11)
output = hrule(1, width=11)
assert len(output) == 11
assert '───────────'

View File

@@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from tableprint import humantime, _format_line, LineStyle
from tableprint import humantime, LineStyle
from tableprint.utils import format_line
import pytest
def test_format_line():
# using ASCII
assert _format_line(['foo', 'bar'], LineStyle('(', '_', '+', ')')) == '(foo+bar)'
assert _format_line("abc", LineStyle('[', '*', '.', ']')) == '[a.b.c]'
assert _format_line(["_"], LineStyle('o', '', '!', 'o')) == 'o_o'
assert _format_line([], LineStyle(':', '', '', ')')) == ':)'
assert format_line(['foo', 'bar'], LineStyle('(', '_', '+', ')')) == '(foo+bar)'
assert format_line("abc", LineStyle('[', '*', '.', ']')) == '[a.b.c]'
assert format_line(["_"], LineStyle('o', '', '!', 'o')) == 'o_o'
assert format_line([], LineStyle(':', '', '', ')')) == ':)'
# using unicode
assert _format_line(['.', '.', '.'], LineStyle('', '_', '', '')) == '★...☆'
assert _format_line("☚☛", LineStyle('', '*', '', '')) == '♪☚♩☛♫'
assert format_line(['.', '.', '.'], LineStyle('', '_', '', '')) == '★...☆'
assert format_line("☚☛", LineStyle('', '*', '', '')) == '♪☚♩☛♫'
def test_humantime():