summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorRoss Barnowski <rossbar@berkeley.edu>2020-04-21 16:52:57 -0700
committerRoss Barnowski <rossbar@berkeley.edu>2020-04-21 16:52:57 -0700
commit95c14c271f69333ce3e405ddeae1fa99024d0060 (patch)
treea1004d684ee24fe531b7f993a159251a82fb8e0d /numpy
parent8dfaa4a5e0ca329e16a853d5982ea5af5d044b47 (diff)
downloadnumpy-95c14c271f69333ce3e405ddeae1fa99024d0060.tar.gz
MAINT,TST: Move _repr_latex tests to test_printing.
Organizational refactoring - the tests for the polynomial _repr_latex method were originally defined in test_classes.py. Based on the descriptions of the various test files, it is a better fit in test_printing.py. Updated docstring to reflect that _repr_latex is used in Jupyter environments, not IPython terminals (by default).
Diffstat (limited to 'numpy')
-rw-r--r--numpy/polynomial/tests/test_classes.py50
-rw-r--r--numpy/polynomial/tests/test_printing.py49
2 files changed, 49 insertions, 50 deletions
diff --git a/numpy/polynomial/tests/test_classes.py b/numpy/polynomial/tests/test_classes.py
index e9f256cf8..8e71a1945 100644
--- a/numpy/polynomial/tests/test_classes.py
+++ b/numpy/polynomial/tests/test_classes.py
@@ -570,56 +570,6 @@ def test_ufunc_override(Poly):
assert_raises(TypeError, np.add, x, p)
-
-class TestLatexRepr:
- """Test the latex repr used by ipython """
-
- def as_latex(self, obj):
- # right now we ignore the formatting of scalars in our tests, since
- # it makes them too verbose. Ideally, the formatting of scalars will
- # be fixed such that tests below continue to pass
- obj._repr_latex_scalar = lambda x: str(x)
- try:
- return obj._repr_latex_()
- finally:
- del obj._repr_latex_scalar
-
- def test_simple_polynomial(self):
- # default input
- p = Polynomial([1, 2, 3])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0 + 2.0\,x + 3.0\,x^{2}$')
-
- # translated input
- p = Polynomial([1, 2, 3], domain=[-2, 0])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0 + 2.0\,\left(1.0 + x\right) + 3.0\,\left(1.0 + x\right)^{2}$')
-
- # scaled input
- p = Polynomial([1, 2, 3], domain=[-0.5, 0.5])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0 + 2.0\,\left(2.0x\right) + 3.0\,\left(2.0x\right)^{2}$')
-
- # affine input
- p = Polynomial([1, 2, 3], domain=[-1, 0])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0 + 2.0\,\left(1.0 + 2.0x\right) + 3.0\,\left(1.0 + 2.0x\right)^{2}$')
-
- def test_basis_func(self):
- p = Chebyshev([1, 2, 3])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0\,{T}_{0}(x) + 2.0\,{T}_{1}(x) + 3.0\,{T}_{2}(x)$')
- # affine input - check no surplus parens are added
- p = Chebyshev([1, 2, 3], domain=[-1, 0])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0\,{T}_{0}(1.0 + 2.0x) + 2.0\,{T}_{1}(1.0 + 2.0x) + 3.0\,{T}_{2}(1.0 + 2.0x)$')
-
- def test_multichar_basis_func(self):
- p = HermiteE([1, 2, 3])
- assert_equal(self.as_latex(p),
- r'$x \mapsto 1.0\,{He}_{0}(x) + 2.0\,{He}_{1}(x) + 3.0\,{He}_{2}(x)$')
-
-
#
# Test class method that only exists for some classes
#
diff --git a/numpy/polynomial/tests/test_printing.py b/numpy/polynomial/tests/test_printing.py
index 049d3af2f..bbd5502af 100644
--- a/numpy/polynomial/tests/test_printing.py
+++ b/numpy/polynomial/tests/test_printing.py
@@ -64,3 +64,52 @@ class TestRepr:
res = repr(poly.Laguerre([0, 1]))
tgt = 'Laguerre([0., 1.], domain=[0, 1], window=[0, 1])'
assert_equal(res, tgt)
+
+
+class TestLatexRepr:
+ """Test the latex repr used by Jupyter"""
+
+ def as_latex(self, obj):
+ # right now we ignore the formatting of scalars in our tests, since
+ # it makes them too verbose. Ideally, the formatting of scalars will
+ # be fixed such that tests below continue to pass
+ obj._repr_latex_scalar = lambda x: str(x)
+ try:
+ return obj._repr_latex_()
+ finally:
+ del obj._repr_latex_scalar
+
+ def test_simple_polynomial(self):
+ # default input
+ p = poly.Polynomial([1, 2, 3])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0 + 2.0\,x + 3.0\,x^{2}$')
+
+ # translated input
+ p = poly.Polynomial([1, 2, 3], domain=[-2, 0])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0 + 2.0\,\left(1.0 + x\right) + 3.0\,\left(1.0 + x\right)^{2}$')
+
+ # scaled input
+ p = poly.Polynomial([1, 2, 3], domain=[-0.5, 0.5])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0 + 2.0\,\left(2.0x\right) + 3.0\,\left(2.0x\right)^{2}$')
+
+ # affine input
+ p = poly.Polynomial([1, 2, 3], domain=[-1, 0])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0 + 2.0\,\left(1.0 + 2.0x\right) + 3.0\,\left(1.0 + 2.0x\right)^{2}$')
+
+ def test_basis_func(self):
+ p = poly.Chebyshev([1, 2, 3])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0\,{T}_{0}(x) + 2.0\,{T}_{1}(x) + 3.0\,{T}_{2}(x)$')
+ # affine input - check no surplus parens are added
+ p = poly.Chebyshev([1, 2, 3], domain=[-1, 0])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0\,{T}_{0}(1.0 + 2.0x) + 2.0\,{T}_{1}(1.0 + 2.0x) + 3.0\,{T}_{2}(1.0 + 2.0x)$')
+
+ def test_multichar_basis_func(self):
+ p = poly.HermiteE([1, 2, 3])
+ assert_equal(self.as_latex(p),
+ r'$x \mapsto 1.0\,{He}_{0}(x) + 2.0\,{He}_{1}(x) + 3.0\,{He}_{2}(x)$')