|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +from pylatex import Document, Section, Tabular, MultiColumn, StandAloneGraphic |
| 4 | + |
| 5 | +# This file contains function that test several Tabular related functionality. |
| 6 | + |
| 7 | +def test_tabular_can_add_row_passing_many_arguments(sample_logo_path): |
| 8 | + """ |
| 9 | + Test that Tabular can add a row as described in the function body: |
| 10 | + The first method is to pass the content of each cell as a separate argument. |
| 11 | +
|
| 12 | + Returns |
| 13 | + ------- |
| 14 | + None. |
| 15 | +
|
| 16 | + """ |
| 17 | + doc = Document() |
| 18 | + |
| 19 | + with doc.create(Section('Can Add Row Passing Many Arguments')): |
| 20 | + with doc.create(Tabular("|c|c|", booktabs=True)) as table: |
| 21 | + |
| 22 | + mc1 = MultiColumn(1, align='l', data=StandAloneGraphic( |
| 23 | + filename=sample_logo_path)) |
| 24 | + mc2 = MultiColumn(1, align='l', data=StandAloneGraphic( |
| 25 | + filename=sample_logo_path)) |
| 26 | + |
| 27 | + |
| 28 | + table.add_row(mc1, mc2) |
| 29 | + doc.generate_pdf(clean_tex=False) |
| 30 | + |
| 31 | + |
| 32 | +def test_tabular_can_add_row_passing_iterable(sample_logo_path): |
| 33 | + """ |
| 34 | + Test that Tabular can add a row as described in the function body: |
| 35 | + The second method |
| 36 | + is to pass a single argument that is an iterable that contains each |
| 37 | + contents. |
| 38 | +
|
| 39 | + Returns |
| 40 | + ------- |
| 41 | + None. |
| 42 | +
|
| 43 | + """ |
| 44 | + doc = Document() |
| 45 | + |
| 46 | + with doc.create(Section('Can Add Row Passing Iterable')): |
| 47 | + with doc.create(Tabular("|c|c|", booktabs=True)) as table: |
| 48 | + multi_columns_array = [ |
| 49 | + MultiColumn(1, align='l', data=StandAloneGraphic( |
| 50 | + filename=sample_logo_path)), |
| 51 | + MultiColumn(1, align='l', data=StandAloneGraphic( |
| 52 | + filename=sample_logo_path)) |
| 53 | + ] |
| 54 | + |
| 55 | + table.add_row(multi_columns_array) |
| 56 | + doc.generate_pdf() |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + |
| 60 | + import os.path as osp |
| 61 | + |
| 62 | + sample_logo_path = osp.abspath(osp.join( |
| 63 | + __file__[0:-15], "..", "examples", "sample-logo.png")) |
| 64 | + |
| 65 | + test_tabular_can_add_row_passing_many_arguments( |
| 66 | + sample_logo_path=sample_logo_path) |
| 67 | + test_tabular_can_add_row_passing_iterable( |
| 68 | + sample_logo_path=sample_logo_path) |
| 69 | + |
0 commit comments