This notebook executes the same test vectors as used by py.test, but runs in a notebook environment (i.e. the test coverage is idential)
IF vectors fail in pytest, THEN this notebook can be manually executed to see what the html differences LOOK like.
%load_ext autoreload
%autoreload 2
import os
import pprint
from difflib import Differ
from IPython.display import display, HTML
import add_parent_to_path
from ipy_table import VectorManager
pp = pprint.PrettyPrinter(indent=4)
def html_indent(html):
'''Return html wrapped by an indenting div'''
return '<div style="margin-left: 35px;">' + html + '</div>'
def chunkstring(string, length=80):
return list((string[0+i:length+i] for i in range(0, len(string), length)))
test_vectors = VectorManager(os.path.join('..', 'test', 'test_vectors.json'))
print('Loaded {} vectors.'.format(len(test_vectors.vectors)))
Loaded 26 vectors.
pass_count = 0
fail_count = 0
for index, vector in enumerate(test_vectors.vectors):
print('Running vector {}'.format(index))
print(' Description: {}'.format(vector['description']))
success = test_vectors.run_vector(vector)
if success:
print(' PASS')
pass_count += 1
else:
print(' FAIL')
print(' Vector:')
vector_pp = pp.pformat(vector)
print('\n'.join([' ' + ln for ln in vector_pp.splitlines()]))
differ = Differ()
print(' HTML Comparison:')
print('\n'.join(list(differ.compare(
chunkstring(vector['expected_html']),
chunkstring(vector['result_html'])))))
print(' Expected HTML:')
display(HTML(html_indent(vector['expected_html'])))
print(' Result HTML:')
display(HTML(html_indent(vector['result_html'])))
fail_count += 1
print('{} Passed'.format(pass_count))
print('{} Failed'.format(fail_count))
Running vector 0 Description: Default style PASS Running vector 1 Description: table.apply_theme(theme_name='basic') PASS Running vector 2 Description: table.apply_theme(theme_name='basic_left') PASS Running vector 3 Description: table.apply_theme(theme_name='basic_both') PASS Running vector 4 Description: table.set_cell_style(color='red', column=1, row=1) PASS Running vector 5 Description: table.set_row_style(color='lightGreen', row=0) PASS Running vector 6 Description: table.set_column_style(color='lightBlue', column=1) PASS Running vector 7 Description: table.set_global_style(color='Pink') PASS Running vector 8 Description: table.set_row_style(bold=True, row=1) PASS Running vector 9 Description: table.set_row_style(italic=True, row=1) PASS Running vector 10 Description: table.set_row_style(color='Orange', row=1) PASS Running vector 11 Description: Thick border, outer corners PASS Running vector 12 Description: table.set_row_style(thick_border='all', row=1) PASS Running vector 13 Description: No border, outer corners PASS Running vector 14 Description: table.set_row_style(no_border='all', row=1) PASS Running vector 15 Description: table.set_cell_style(column=0, row_span=3, row=0) PASS Running vector 16 Description: table.set_cell_style(column=1, column_span=2, row=1) PASS Running vector 17 Description: table.set_cell_style(column=0, width=100, row=0) PASS Running vector 18 Description: Alignment (right, center, and left) PASS Running vector 19 Description: Wrap PASS Running vector 20 Description: Float formatting PASS Running vector 21 Description: NumPy Compatibility PASS Running vector 22 Description: Tabulate, 4 columns, without wrap PASS Running vector 23 Description: Tabulate, 4 columns, with wrap PASS Running vector 24 Description: Tabulate, 5 columns, with wrap PASS Running vector 25 Description: Unicode PASS 26 Passed 0 Failed
test_vectors.show_all()
Vector 0: description: u'Default style' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22], [30, 31, 32], [40, 41, 42]] operations: (None) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
Vector 1: description: u"table.apply_theme(theme_name='basic')" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22], [30, 31, 32], [40, 41, 42]] operations: table.apply_theme(theme_name=u'basic') expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
Vector 2: description: u"table.apply_theme(theme_name='basic_left')" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22], [30, 31, 32], [40, 41, 42]] operations: table.apply_theme(theme_name=u'basic_left') expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
Vector 3: description: u"table.apply_theme(theme_name='basic_both')" data:[[u'', 1, 2], [10, 11, 12], [20, 21, 22], [30, 31, 32], [40, 41, 42]] operations: table.apply_theme(theme_name=u'basic_both') expected_html:
1 | 2 | |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
result_html:
1 | 2 | |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
Vector 4: description: u"table.set_cell_style(color='red', column=1, row=1)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(color=u'red', column=1, row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 5: description: u"table.set_row_style(color='lightGreen', row=0)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(color=u'lightGreen', row=0) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 6: description: u"table.set_column_style(color='lightBlue', column=1)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_column_style(color=u'lightBlue', column=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 7: description: u"table.set_global_style(color='Pink')" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_global_style(color=u'Pink') expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 8: description: u'table.set_row_style(bold=True, row=1)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(bold=True, row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 9: description: u'table.set_row_style(italic=True, row=1)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(italic=True, row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 10: description: u"table.set_row_style(color='Orange', row=1)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(color=u'Orange', row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 11: description: u'Thick border, outer corners' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(thick_border=u'left, top', column=0, row=0) table.set_cell_style(thick_border=u'bottom, right', column=2, row=2) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 12: description: u"table.set_row_style(thick_border='all', row=1)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(thick_border=u'all', row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 13: description: u'No border, outer corners' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(column=0, no_border=u'left, top', row=0) table.set_cell_style(column=2, no_border=u'bottom, right', row=2) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 14: description: u"table.set_row_style(no_border='all', row=1)" data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_row_style(no_border=u'all', row=1) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 15: description: u'table.set_cell_style(column=0, row_span=3, row=0)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(column=0, row_span=3, row=0) expected_html:
0 | 1 | 2 |
11 | 12 | |
21 | 22 |
result_html:
0 | 1 | 2 |
11 | 12 | |
21 | 22 |
Vector 16: description: u'table.set_cell_style(column=1, column_span=2, row=1)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(column=1, column_span=2, row=1) expected_html:
0 | 1 | 2 |
10 | 11 | |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | |
20 | 21 | 22 |
Vector 17: description: u'table.set_cell_style(column=0, width=100, row=0)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(column=0, width=100, row=0) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 18: description: u'Alignment (right, center, and left)' data:[[0, 1, 2], [10, 11, 12], [20, 21, 22]] operations: table.set_cell_style(column=0, width=100, row=0) table.set_cell_style(column=0, align=u'right', row=0) table.set_cell_style(column=0, align=u'center', row=1) table.set_cell_style(column=0, align=u'left', row=2) expected_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
result_html:
0 | 1 | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
Vector 19: description: u'Wrap' data:[ [u'This cell has wrap set', u'This cell does not have wrap set', 2], [10, 11, 12], [20, 21, 22], [30, 31, 32], [40, 41, 42]] operations: table.set_cell_style(wrap=True, width=50, column=0, row=0) table.set_cell_style(column=1, widph=50, row=0) expected_html:
This cell has wrap set | This cell does not have wrap set | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
result_html:
This cell has wrap set | This cell does not have wrap set | 2 |
10 | 11 | 12 |
20 | 21 | 22 |
30 | 31 | 32 |
40 | 41 | 42 |
Vector 20: description: u'Float formatting' data:[ [0.0, 1.0101, 2.0202, 3.0303], [10.100999999999999, 11.111099999999999, 12.1212, 13.131300000000001], [20.201999999999998, 21.2121, 22.222199999999997, 23.232300000000002]] operations: table.set_cell_style(column=0, float_format=u'%0.1f', row=0) table.set_cell_style(column=0, float_format=u'%0.6f', row=1) table.set_cell_style(column=0, float_format=u'$%0.2f', row=2) expected_html:
0.0 | 1.0101 | 2.0202 | 3.0303 |
10.101000 | 11.1111 | 12.1212 | 13.1313 |
$20.20 | 21.2121 | 22.2222 | 23.2323 |
result_html:
0.0 | 1.0101 | 2.0202 | 3.0303 |
10.101000 | 11.1111 | 12.1212 | 13.1313 |
$20.20 | 21.2121 | 22.2222 | 23.2323 |
Vector 21: description: u'NumPy Compatibility' data:[[1.23456789, 1.23456789, 1.2344, 1.23457, 1.2345678899999999, 1.23456789]] operations: table.set_row_style(float_format=u'%0.2f', row=0) expected_html:
1.23 | 1.23 | 1.23 | 1.23 | 1.23 | 1.23 |
result_html:
1.23 | 1.23 | 1.23 | 1.23 | 1.23 | 1.23 |
Vector 22: description: u'Tabulate, 4 columns, without wrap' data:[0, 1, 2, 3, 4, 5, 6, 7] operations: (None) expected_html:
0 | 1 | 2 | 3 |
4 | 5 | 6 | 7 |
result_html:
0 | 1 | 2 | 3 |
4 | 5 | 6 | 7 |
Vector 23: description: u'Tabulate, 4 columns, with wrap' data:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] operations: (None) expected_html:
0 | 1 | 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | 10 |
result_html:
0 | 1 | 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | 10 |
Vector 24: description: u'Tabulate, 5 columns, with wrap' data:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] operations: (None) expected_html:
0 | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 |
10 |
result_html:
0 | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 |
10 |
Vector 25: description: u'Unicode' data:[ [ u'Alpha:\u03b1', u'Beta:\u03b2', u'Gamma:\u03b3', u'Sigma:\u03c3', u'Pi:\u03c0']] operations: (None) expected_html:
Alpha:α | Beta:β | Gamma:γ | Sigma:σ | Pi:π |
result_html:
Alpha:α | Beta:β | Gamma:γ | Sigma:σ | Pi:π |