Skip to content

Commit

Permalink
Add docs for testing module
Browse files Browse the repository at this point in the history
  • Loading branch information
znichollscr committed Oct 27, 2024
1 parent 2839f6e commit f76baeb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pint Changelog


0.24.1 (2024-06-24)
-----------------
-------------------

- Fix custom formatter needing the registry object. (PR #2011)
- Support python 3.9 following difficulties installing with NumPy 2. (PR #2019)
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"sphinx_design",
]


# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
2 changes: 1 addition & 1 deletion docs/ecosystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pint integrations:


Packages using pint:
------------------
--------------------

- `fluids <https://github.com/CalebBell/fluids>`_ Practical fluid dynamics calculations
- `ht <https://github.com/CalebBell/ht/>`_ Practical heat transfer calculations
Expand Down
56 changes: 56 additions & 0 deletions pint/testing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
pint.testing
~~~~~~~~~~~~
Functions for testing whether pint quantities are equal.
:copyright: 2016 by Pint Authors, see AUTHORS for more details..
:license: BSD, see LICENSE for more details.
"""

from __future__ import annotations

import math
Expand Down Expand Up @@ -35,6 +45,25 @@ def _get_comparable_magnitudes(first, second, msg):


def assert_equal(first, second, msg: str | None = None) -> None:
"""
Assert that two quantities are equal
Parameters
----------
first
First quantity to compare
second
Second quantity to compare
msg
If supplied, message to show if the two quantities aren't equal.
Raises
------
AssertionError
The two quantities are not equal.
"""
if msg is None:
msg = f"Comparing {first!r} and {second!r}. "

Expand All @@ -60,6 +89,33 @@ def assert_equal(first, second, msg: str | None = None) -> None:
def assert_allclose(
first, second, rtol: float = 1e-07, atol: float = 0, msg: str | None = None
) -> None:
"""
Assert that two quantities are all close
Unlike numpy, this uses a symmetric check of closeness.
Parameters
----------
first
First quantity to compare
second
Second quantity to compare
rtol
Relative tolerance to use when checking for closeness.
atol
Absolute tolerance to use when checking for closeness.
msg
If supplied, message to show if the two quantities aren't equal.
Raises
------
AssertionError
The two quantities are not close to within the supplied tolerance.
"""
if msg is None:
try:
msg = f"Comparing {first!r} and {second!r}. "
Expand Down

0 comments on commit f76baeb

Please sign in to comment.