diff options
| author | Kenneth Reitz <me@kennethreitz.org> | 2016-02-07 06:08:23 -0500 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.org> | 2016-02-07 06:08:23 -0500 |
| commit | 32cbc36fc181dcdb551325529a3c582a6acb30bd (patch) | |
| tree | f8ff6fbd0c3b69c288e63118ff0bcbe8e860aff7 /test_tablib.py | |
| parent | 8bded88559552241d2a5e6d735f97eb4d69175fb (diff) | |
| parent | 79dc4524a05e7a89b0e65e9d5b78fa6a56652848 (diff) | |
| download | tablib-32cbc36fc181dcdb551325529a3c582a6acb30bd.tar.gz | |
Merge branch 'latex-export' of https://github.com/mloesch/tablib into develop
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): |
