From d4319baf5eaf16cdd97f9e91785e47038381cd28 2014-02-04 20:20:40 From: Jonathan Frederic Date: 2014-02-04 20:20:40 Subject: [PATCH] Added 18 more citation tests Thanks @jakobgager for the tests- http://nbviewer.ipython.org/gist/jakobgager/6859103 --- diff --git a/IPython/nbconvert/filters/tests/test_citation.py b/IPython/nbconvert/filters/tests/test_citation.py index 9f2e685..22e83a5 100644 --- a/IPython/nbconvert/filters/tests/test_citation.py +++ b/IPython/nbconvert/filters/tests/test_citation.py @@ -17,7 +17,7 @@ from nose.tools import assert_equal # Tests #----------------------------------------------------------------------------- -test_md = """ +test_md = {""" # My Heading Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue @@ -32,9 +32,7 @@ relations like 1<2 & 4>5.

* One Jonathan. * Two Matthias. * Three Paul. -""" - -test_md_parsed = """ +""": """ # My Heading Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus ac magna non augue @@ -49,13 +47,106 @@ relations like 1<2 & 4>5.

* One \cite{jdfreder}. * Two \cite{carreau}. * Three \cite{ivanov}. -""" +""", + +# No citations +r"""The quick brown fox jumps over the lazy dog.""": +r"""The quick brown fox jumps over the lazy dog.""", + +# Simple inline +r"""Foo Text bar""": +r"""Foo \cite{asdf} bar""", + +# Multiline +r"""Text +Foo""": +r"""\cite{ewqr}Foo""", + +# Nested tags +r"""
Text
Bar""": +r"""
\cite{Foo}
Bar""", + +# Including Maths +r"""Foo $3*2*1$
Text
Bar""": +r"""Foo $3*2*1$ \cite{Foo} Bar""", + +# Missing end tag +r"""Test Foo""": +r"""\cite{asdf}""", + +r"""Test Foo""": +r"""\cite{asdf}""", + +r"""Test Foo""": +r"""\cite{asdf}""", + +# Multiple arguments +r"""Test Foo""": +r"""\cite{asdf} Foo""", + +# Wrong capitalization +r"""Test Foo""": +r"""\cite{asdf} Foo""", + +r"""Test Foo""": +r"""\cite{asdf} Foo""", + +# Wrong end tag +r""" ksjfs sdf ds """: +r"""\cite{wer}""", + +r"""""": +r"""\cite{wer}""", + +# Invalid tag names +r""" """: +r""" \cite{wer}""", + +# Non-nested tags +r"""

Test Foo

""": +r"""

\cite{asdf}Test Foo

""", + +# LXML errors +r"""Foo +\begin{eqnarray} +1 & bar1 \\ +3 & 4 \\ +\end{eqnarray}""": +r"""Foo +\begin{eqnarray} +1 & \cite{bar} \\ +3 & 4 \\ +\end{eqnarray}""", + +r""" +1<2 is true, but 3>4 is false. + +$1<2$ is true, but $3>4$ is false. + +1<2 it is even worse if it is alone in a line.""": +r""" +1<2 is true, but 3>4 is false. + +$1<2$ is true, but $3>4$ is false. + +1<2 it is even worse if it is alone in a line.""", + +r""" +1 < 2 is true, but 3 > 4 is false + +$1 < 2$ is true, but $3 > 4$ is false + +1 < 2 it is even worse if it is alone in a line. +""": +r""" +1 < 2 is true, but 3 > 4 is false + +$1 < 2$ is true, but $3 > 4$ is false + +1 < 2 it is even worse if it is alone in a line. +"""} def test_citation2latex(): """Are citations parsed properly?""" - try: - from lxml import html #analysis:ignore - except ImportError: - assert_equal(test_md, citation2latex(test_md)) - else: - assert_equal(test_md_parsed, citation2latex(test_md)) + for input, output in test_md.items(): + yield (assert_equal, citation2latex(input), output)