diff options
| author | Mathias Loesch <m.loesch83@gmail.com> | 2014-08-27 21:08:48 +0200 |
|---|---|---|
| committer | Mathias Loesch <m.loesch83@gmail.com> | 2015-06-04 09:26:35 +0200 |
| commit | 79dc4524a05e7a89b0e65e9d5b78fa6a56652848 (patch) | |
| tree | 668b89398b84172a6a3cea91ef547c136b3e810c /test_tablib.py | |
| parent | a785d77901f307ef499621753b078743e2fabb81 (diff) | |
| download | tablib-79dc4524a05e7a89b0e65e9d5b78fa6a56652848.tar.gz | |
Added LaTeX table export format
Diffstat (limited to 'test_tablib.py')
| -rwxr-xr-x | test_tablib.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test_tablib.py b/test_tablib.py index a1f581c..9c37b8e 100755 --- a/test_tablib.py +++ b/test_tablib.py @@ -319,6 +319,67 @@ class TablibTestCase(unittest.TestCase): self.assertEqual(html, d.html) + def test_latex_export(self): + """LaTeX export""" + + expected = """\ +% Note: add \\usepackage{booktabs} to your preamble +% +\\begin{table}[!htbp] + \\centering + \\caption{Founders} + \\begin{tabular}{lrr} + \\toprule + first\\_name & last\\_name & gpa \\\\ + \\cmidrule(r){1-1} \\cmidrule(lr){2-2} \\cmidrule(l){3-3} + John & Adams & 90 \\\\ + George & Washington & 67 \\\\ + Thomas & Jefferson & 50 \\\\ + \\bottomrule + \\end{tabular} +\\end{table} +""" + output = self.founders.latex + self.assertEqual(output, expected) + + + def test_latex_export_empty_dataset(self): + self.assertTrue(tablib.Dataset().latex is not None) + + + def test_latex_export_no_headers(self): + d = tablib.Dataset() + d.append(('one', 'two', 'three')) + self.assertTrue('one' in d.latex) + + + def test_latex_export_caption(self): + d = tablib.Dataset() + d.append(('one', 'two', 'three')) + self.assertFalse('caption' in d.latex) + + d.title = 'Title' + self.assertTrue('\\caption{Title}' in d.latex) + + + def test_latex_export_none_values(self): + headers = ['foo', None, 'bar'] + d = tablib.Dataset(['foo', None, 'bar'], headers=headers) + output = d.latex + self.assertTrue('foo' in output) + self.assertFalse('None' in output) + + + def test_latex_escaping(self): + d = tablib.Dataset(['~', '^']) + output = d.latex + + self.assertFalse('~' in output) + self.assertTrue('textasciitilde' in output) + self.assertFalse('^' in output) + self.assertTrue('textasciicircum' in output) + + def test_unicode_append(self): """Passes in a single unicode character and exports.""" @@ -338,6 +399,7 @@ class TablibTestCase(unittest.TestCase): data.xlsx data.ods data.html + data.latex def test_book_export_no_exceptions(self): |
