Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running doctests using doctest-plus #4117

Merged
merged 22 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
eef52fb
Adding doctest using doctest-plus
prady0t May 29, 2024
1144cb8
Skipping failing tests
prady0t May 29, 2024
1f84179
Merge branch 'develop' into using-doctestplus
kratman May 29, 2024
8863623
Merge branch 'develop' into using-doctestplus
agriyakhetarpal May 30, 2024
b282bb7
Merge branch 'develop' into using-doctestplus
kratman May 30, 2024
d38e2d8
Merge branch 'develop' into using-doctestplus
kratman May 31, 2024
22f6463
Merge branch 'develop' into using-doctestplus
kratman May 31, 2024
e6e7877
Update run-tests.py
prady0t Jun 1, 2024
74730b7
style: pre-commit fixes
pre-commit-ci[bot] Jun 1, 2024
f943852
Merge branch 'develop' into using-doctestplus
kratman Jun 3, 2024
67688d1
Merge branch 'develop' into using-doctestplus
kratman Jun 3, 2024
18893f1
Removing unrelated subprocess
prady0t Jun 5, 2024
cc64fe4
Merge remote-tracking branch 'origin/using-doctestplus' into using-do…
prady0t Jun 5, 2024
06eaf89
style: pre-commit fixes
pre-commit-ci[bot] Jun 5, 2024
3538515
Merge branch 'develop' into using-doctestplus
arjxn-py Jun 5, 2024
e95a4a9
Update docs/source/user_guide/installation/index.rst
prady0t Jun 5, 2024
8284100
Update docs/source/user_guide/installation/index.rst
prady0t Jun 5, 2024
b8286b6
Update pybamm/parameters/parameter_sets.py
prady0t Jun 5, 2024
aa93df1
Merge branch 'develop' into using-doctestplus
agriyakhetarpal Jun 5, 2024
c3be511
Fixing doctest directive
prady0t Jun 6, 2024
0a0b2f0
Merge branch 'develop' into using-doctestplus
prady0t Jun 6, 2024
c20d315
Merge branch 'develop' into using-doctestplus
agriyakhetarpal Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
extensions = [
# Sphinx extensions
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.mathjax",
"sphinx.ext.viewcode",
Expand All @@ -73,10 +72,6 @@
napoleon_use_rtype = True
napoleon_google_docstring = False

doctest_global_setup = """
from docs import *
import pybamm
"""

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
5 changes: 3 additions & 2 deletions docs/source/user_guide/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ Dependency
`pre-commit <https://pre-commit.com/index.html>`__ \- dev For managing and maintaining multi-language pre-commit hooks.
`ruff <https://beta.ruff.rs/docs/>`__ \- dev For code formatting.
`nox <https://nox.thea.codes/en/stable/>`__ \- dev For running testing sessions in multiple environments.
`coverage <https://coverage.readthedocs.io/en/>`__ \- dev For calculating coverage of tests.
`pytest-cov <https://pytest-cov.readthedocs.io/en/latest/>`__ \- dev For calculating coverage of tests.
prady0t marked this conversation as resolved.
Show resolved Hide resolved
`parameterized <https://github.com/wolever/parameterized>`__ \- dev For test parameterization.
`pytest <https://docs.pytest.org/en/stable/>`__ 6.0.0 dev For running Jupyter notebooks tests.
`pytest <https://docs.pytest.org/en/stable/>`__ 6.0.0 dev For running Unit, Integration and Jupyter notebooks tests.
prady0t marked this conversation as resolved.
Show resolved Hide resolved
`pytest-doctestplus <https://github.com/scientific-python/pytest-doctestplus>`__ \- dev For running doctests.
`pytest-xdist <https://pytest-xdist.readthedocs.io/en/latest/>`__ \- dev For running tests in parallel across distributed workers.
`nbmake <https://github.com/treebeardtech/nbmake/>`__ \- dev A ``pytest`` plugin for executing Jupyter notebooks.
================================================================================ ================== ================== =============================================================
Expand Down
8 changes: 4 additions & 4 deletions pybamm/expression_tree/operations/latexify.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class Latexify:
>>> model = pybamm.lithium_ion.SPM()

This will returns all model equations in png
>>> model.latexify("equations.png")
>>> model.latexify("equations.png") # doctest: +SKIP

This will return all the model equations in latex
>>> model.latexify()
>>> model.latexify() # doctest: +SKIP

This will return the list of all the model equations
>>> model.latexify(newline=False)
>>> model.latexify(newline=False) # doctest: +SKIP

This will return first five model equations
>>> model.latexify(newline=False)[1:5]
>>> model.latexify(newline=False)[1:5] # doctest: +SKIP
"""

def __init__(self, model, filename: str | None = None, newline: bool = True):
Expand Down
8 changes: 4 additions & 4 deletions pybamm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,16 +1345,16 @@ def latexify(self, filename=None, newline=True, output_variables=None):
>>> model = pybamm.lithium_ion.SPM()

This will returns all model equations in png
>>> model.latexify("equations.png")
>>> model.latexify("equations.png") # doctest: +SKIP

This will return all the model equations in latex
>>> model.latexify()
>>> model.latexify() # doctest: +SKIP

This will return the list of all the model equations
>>> model.latexify(newline=False)
>>> model.latexify(newline=False) # doctest: +SKIP

This will return first five model equations
>>> model.latexify(newline=False)[1:5]
>>> model.latexify(newline=False)[1:5] # doctest: +SKIP
"""
from pybamm.expression_tree.operations.latexify import Latexify

Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/lithium_metal/dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Doyle-Fuller-Newman (DFN) Model
#
import pybamm
from ..lithium_ion.dfn import DFN as LithiumIonDFN
from pybamm.models.full_battery_models.lithium_ion.dfn import DFN as LithiumIonDFN
arjxn-py marked this conversation as resolved.
Show resolved Hide resolved


class DFN(LithiumIonDFN):
Expand Down
1 change: 1 addition & 0 deletions pybamm/parameters/parameter_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ParameterSets(Mapping):

.. doctest::
prady0t marked this conversation as resolved.
Show resolved Hide resolved

>>> import pybamm
>>> list(pybamm.parameter_sets)
['Ai2020', 'Chen2020', ...]

Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ dev = [
"nox",
# For coverage
"pytest-cov",
# For doctest
"pytest-doctestplus",
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
# For test parameterization
"parameterized>=0.9",
# For testing Jupyter notebooks
Expand Down
24 changes: 6 additions & 18 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# (see https://github.com/pints-team/pints)
#
import os
import shutil
import pybamm
import sys
import argparse
Expand Down Expand Up @@ -61,32 +60,21 @@ def run_doc_tests():
Checks if the documentation can be built, runs any doctests (currently not
used).
"""
print("Checking if docs can be built.")
print("Checking for doctests.")
try:
subprocess.run(
[
"sphinx-build",
"-j",
"auto",
"-b",
"doctest",
"docs",
"docs/build/html",
"-W",
"--keep-going",
f"{sys.executable}",
"-m",
"pytest",
"--doctest-plus",
"pybamm",
],
check=True,
)
except subprocess.CalledProcessError as e:
prady0t marked this conversation as resolved.
Show resolved Hide resolved
print(f"FAILED with exit code {e.returncode}")
sys.exit(e.returncode)
finally:
# Regardless of whether the doctests pass or fail, attempt to remove the built files.
print("Deleting built files.")
try:
shutil.rmtree("docs/build/html/.doctrees/")
except Exception as e:
print(f"Error deleting built files: {e}")


def run_scripts(executable="python"):
Expand Down
Loading