diff options
author | Martin Teichmann <martin.teichmann@xfel.eu> | 2017-12-05 09:39:23 +0100 |
---|---|---|
committer | Martin Teichmann <martin.teichmann@xfel.eu> | 2017-12-05 09:39:23 +0100 |
commit | 46c8ff45d503a0049e082c32c4032839018f3947 (patch) | |
tree | 0f7e266fb5fa7614e35eeea8614f88b4f573882b | |
parent | 46314e4e15d0ae080c0e539bb50bafa14f8845c1 (diff) | |
download | pint-46c8ff45d503a0049e082c32c4032839018f3947.tar.gz |
add tests for the IPython _repr_ methods
_repr_html_ and _repr_latex_ were untested
-rw-r--r-- | pint/testsuite/test_quantity.py | 9 | ||||
-rw-r--r-- | pint/testsuite/test_unit.py | 7 |
2 files changed, 16 insertions, 0 deletions
diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index 29ecfea..a05387b 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -166,6 +166,15 @@ class TestQuantity(QuantityTestCase): ureg.default_format = spec self.assertEqual('{0}'.format(x), result) + def test_ipython(self): + ureg = UnitRegistry() + x = 3.5 * ureg.Unit(UnitsContainer(meter=2, kilogram=1, second=-1)) + self.assertEqual(x._repr_html_(), + "3.5 kilogram meter<sup>2</sup>/second") + self.assertEqual(x._repr_latex_(), + r'$3.5\ \frac{\mathrm{kilogram} \cdot ' + r'\mathrm{meter}^{2}}{\mathrm{second}}$') + def test_to_base_units(self): x = self.Q_('1*inch') self.assertQuantityAlmostEqual(x.to_base_units(), self.Q_(0.0254, 'meter')) diff --git a/pint/testsuite/test_unit.py b/pint/testsuite/test_unit.py index 14555a8..599bb62 100644 --- a/pint/testsuite/test_unit.py +++ b/pint/testsuite/test_unit.py @@ -63,6 +63,13 @@ class TestUnit(QuantityTestCase): self.assertEqual('{0}'.format(x), result, 'Failed for {0}, {1}'.format(spec, result)) + def test_ipython(self): + ureg = UnitRegistry() + x = ureg.Unit(UnitsContainer(meter=2, kilogram=1, second=-1)) + self.assertEqual(x._repr_html_(), "kilogram meter<sup>2</sup>/second") + self.assertEqual(x._repr_latex_(), r'$\frac{\mathrm{kilogram} \cdot ' + r'\mathrm{meter}^{2}}{\mathrm{second}}$') + def test_unit_mul(self): x = self.U_('m') self.assertEqual(x*1, self.Q_(1, 'm')) |