Skip to content

Commit c70c076

Browse files
authored
Add docs for testing module (#2070)
1 parent 861953e commit c70c076

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

CHANGES

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Pint Changelog
44
0.25.0 (unreleased)
55
-------------------
66

7-
- Nothing changed yet
7+
- Add docs to the functions in ``pint.testing`` (PR #2070)
88

99

1010
0.24.4 (2024-11-07)
@@ -32,7 +32,7 @@ Pint Changelog
3232

3333

3434
0.24.1 (2024-06-24)
35-
-----------------
35+
-------------------
3636

3737
- Fix custom formatter needing the registry object. (PR #2011)
3838
- Support python 3.9 following difficulties installing with NumPy 2. (PR #2019)

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"sphinx_design",
4646
]
4747

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

docs/ecosystem.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Pint integrations:
1313

1414

1515
Packages using pint:
16-
------------------
16+
--------------------
1717

1818
- `fluids <https://github.com/CalebBell/fluids>`_ Practical fluid dynamics calculations
1919
- `ht <https://github.com/CalebBell/ht/>`_ Practical heat transfer calculations

pint/testing.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
pint.testing
3+
~~~~~~~~~~~~
4+
5+
Functions for testing whether pint quantities are equal.
6+
7+
:copyright: 2016 by Pint Authors, see AUTHORS for more details..
8+
:license: BSD, see LICENSE for more details.
9+
"""
10+
111
from __future__ import annotations
212

313
import math
@@ -35,6 +45,25 @@ def _get_comparable_magnitudes(first, second, msg):
3545

3646

3747
def assert_equal(first, second, msg: str | None = None) -> None:
48+
"""
49+
Assert that two quantities are equal
50+
51+
Parameters
52+
----------
53+
first
54+
First quantity to compare
55+
56+
second
57+
Second quantity to compare
58+
59+
msg
60+
If supplied, message to show if the two quantities aren't equal.
61+
62+
Raises
63+
------
64+
AssertionError
65+
The two quantities are not equal.
66+
"""
3867
if msg is None:
3968
msg = f"Comparing {first!r} and {second!r}. "
4069

@@ -60,6 +89,33 @@ def assert_equal(first, second, msg: str | None = None) -> None:
6089
def assert_allclose(
6190
first, second, rtol: float = 1e-07, atol: float = 0, msg: str | None = None
6291
) -> None:
92+
"""
93+
Assert that two quantities are all close
94+
95+
Unlike numpy, this uses a symmetric check of closeness.
96+
97+
Parameters
98+
----------
99+
first
100+
First quantity to compare
101+
102+
second
103+
Second quantity to compare
104+
105+
rtol
106+
Relative tolerance to use when checking for closeness.
107+
108+
atol
109+
Absolute tolerance to use when checking for closeness.
110+
111+
msg
112+
If supplied, message to show if the two quantities aren't equal.
113+
114+
Raises
115+
------
116+
AssertionError
117+
The two quantities are not close to within the supplied tolerance.
118+
"""
63119
if msg is None:
64120
try:
65121
msg = f"Comparing {first!r} and {second!r}. "

0 commit comments

Comments
 (0)