summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorClark Willison <clarkgwillison@gmail.com>2020-07-11 21:45:08 -0700
committerClark Willison <clarkgwillison@gmail.com>2020-07-11 21:58:55 -0700
commit1da80f4bb98f197809e00d142364ebf218dddf8a (patch)
tree37e7e7c7b92446d4d039b1a2f3c3a4d2c84313aa /docs
parentc7edd2e3dbda51aae632b8cfd7d0e700cb85ee84 (diff)
downloadpint-1da80f4bb98f197809e00d142364ebf218dddf8a.tar.gz
skip doctests that rely on missing dependencies
some configurations in Travis skip optional dependencies, which causes the doctests that rely on them to fail. This fixes that by checking for those dependencies and skipping the affected doctests with :skipif:
Diffstat (limited to 'docs')
-rw-r--r--docs/conf.py17
-rw-r--r--docs/measurement.rst12
-rw-r--r--docs/serialization.rst1
-rw-r--r--docs/tutorial.rst1
4 files changed, 24 insertions, 7 deletions
diff --git a/docs/conf.py b/docs/conf.py
index 924b825..6a720be 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -321,3 +321,20 @@ epub_copyright = copyright
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"http://docs.python.org/": None}
+
+# -- Doctest configuration -----------------------------------------------------
+
+# fill a dictionary with package names that may be missing
+# this is checked by :skipif: clauses in certain doctests that rely
+# on optional dependencies
+doctest_global_setup = """
+from importlib.util import find_spec
+
+not_installed = {
+ pkg_name: find_spec(pkg_name) is None
+ for pkg_name in [
+ 'uncertainties',
+ 'serialize',
+ ]
+}
+"""
diff --git a/docs/measurement.rst b/docs/measurement.rst
index 78e8008..88596c7 100644
--- a/docs/measurement.rst
+++ b/docs/measurement.rst
@@ -7,6 +7,7 @@ Using Measurements
Measurements are the combination of two quantities: the mean value and the error (or uncertainty). The easiest ways to generate a measurement object is from a quantity using the `plus_minus` operator.
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> import numpy as np
>>> from pint import UnitRegistry
@@ -15,16 +16,10 @@ Measurements are the combination of two quantities: the mean value and the error
>>> print(book_length)
(20.0 +/- 2.0) centimeter
-.. testsetup:: *
-
- import numpy as np
- from pint import UnitRegistry
- ureg = UnitRegistry()
- Q_ = ureg.Quantity
-
You can inspect the mean value, the absolute error and the relative error:
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> print(book_length.value)
20.0 centimeter
@@ -36,6 +31,7 @@ You can inspect the mean value, the absolute error and the relative error:
You can also create a Measurement object giving the relative error:
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> book_length = (20. * ureg.centimeter).plus_minus(.1, relative=True)
>>> print(book_length)
@@ -44,6 +40,7 @@ You can also create a Measurement object giving the relative error:
Measurements support the same formatting codes as Quantity. For example, to pretty print a measurement with 2 decimal positions:
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> print('{:.02fP}'.format(book_length))
(20.00 ± 2.00) centimeter
@@ -52,6 +49,7 @@ Measurements support the same formatting codes as Quantity. For example, to pret
Mathematical operations with Measurements, return new measurements following the `Propagation of uncertainty`_ rules.
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> print(2 * book_length)
(40 +/- 4) centimeter
diff --git a/docs/serialization.rst b/docs/serialization.rst
index aa48728..01fed50 100644
--- a/docs/serialization.rst
+++ b/docs/serialization.rst
@@ -98,6 +98,7 @@ numerical type such as `numpy.ndarray`).
Using the serialize_ package you can load and read from multiple formats:
.. doctest::
+ :skipif: not_installed['serialize']
>>> from serialize import dump, load, register_class
>>> register_class(ureg.Quantity, ureg.Quantity.to_tuple, ureg.Quantity.from_tuple)
diff --git a/docs/tutorial.rst b/docs/tutorial.rst
index b49c564..d2d18e9 100644
--- a/docs/tutorial.rst
+++ b/docs/tutorial.rst
@@ -393,6 +393,7 @@ syntax'_ for custom float representations. For example, scientific notation:
Pint also supports the LaTeX siunitx package:
.. doctest::
+ :skipif: not_installed['uncertainties']
>>> accel = 1.3 * ureg['meter/second**2']
>>> # siunitx Latex print