Skip to content

Commit

Permalink
Remove test helper functionality from public API (PlasmaPy#2114)
Browse files Browse the repository at this point in the history
* Mark plasmapy.tests.helpers as private

* pytest_helpers -> _pytest_helpers

* Remove stub files for pytest helpers

* Add changelog entry

* Add second changelog entry

* Update name of file

* Fix reST links

* Update reST links in changelog

* Update import organization

* Fix reST link

* Update ruff ignore links

* Remove api_static page for conftest

* Fix pyproject.toml

* Update changelog entries
  • Loading branch information
namurphy authored May 12, 2023
1 parent b73652c commit fa09634
Show file tree
Hide file tree
Showing 37 changed files with 49 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .sourcery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ignore:
- vendor
- docs/plasmapy_sphinx
- braginskii.py
- helpers.py
- _helpers.py

github:
labels: [No changelog entry needed]
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ Backwards Incompatible Changes
and migrated the dispersion functionality (`dispersionfunction.py`) from
`plasmapy.formulary` to `plasmapy.dispersion`. (`#910 <https://github.com/plasmapy/plasmapy/pull/910>`__)
- Removed default values for the `ion` and `particle` arguments of functions contained in ``plasmapy.formulary.parameters``, in accordance with issue [#453](https://github.com/PlasmaPy/PlasmaPy/issues/453), and updated all relevant calls to modified functionality. (`#911 <https://github.com/plasmapy/plasmapy/pull/911>`__)
- Moved test helper exceptions from `plasmapy.utils.pytest_helpers` to `plasmapy.tests.helpers`. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Moved test helper exceptions from ``plasmapy.utils.pytest_helpers`` to ``plasmapy.tests.helpers``. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Update ``plasmapy.formulary.parameters.mass_density`` so it calculates the mass
density for a specific particle from a given number density. Original function
calculated the total mass density (ion + electron). (`#957 <https://github.com/plasmapy/plasmapy/pull/957>`__)
Expand Down Expand Up @@ -1556,7 +1556,7 @@ Backwards Incompatible Changes
- Create simulation subpackage; move Species particle tracker there; rename to particletracker (`#665 <https://github.com/plasmapy/plasmapy/pull/665>`__)
- Changed `plasmapy.classes.Species` to `plasmapy.simulation.ParticleTracker` (`#668 <https://github.com/plasmapy/plasmapy/pull/668>`__)
- Move pytest helper functionality from `plasmapy.utils` to
`~plasmapy.utils.pytest_helpers` (`#674 <https://github.com/plasmapy/plasmapy/pull/674>`__)
``plasmapy.utils.pytest_helpers`` (`#674 <https://github.com/plasmapy/plasmapy/pull/674>`__)
- Move `plasmapy.physics`, `plasmapy.mathematics` and `plasmapy.transport` into the common `plasmapy.formulary` subpackage (`#692 <https://github.com/plasmapy/plasmapy/pull/692>`__)
- Change `ClassicalTransport` methods into attributes (`#705 <https://github.com/plasmapy/plasmapy/pull/705>`__)

Expand Down
3 changes: 3 additions & 0 deletions changelog/2114.breaking.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed ``plasmapy.tests.helpers`` from PlasmaPy's public API. It is
still available as ``plasmapy.tests._helpers``, but might be removed in
the future.
3 changes: 3 additions & 0 deletions changelog/2114.breaking.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Removed ``plasmapy.utils.pytest_helpers`` from PlasmaPy's public API. It is
still available as ``plasmapy.utils._pytest_helpers``, but might be removed in
the future.
8 changes: 0 additions & 8 deletions docs/api_static/plasmapy.conftest.rst

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api_static/plasmapy.tests.helpers.exceptions.rst

This file was deleted.

8 changes: 0 additions & 8 deletions docs/api_static/plasmapy.tests.helpers.rst

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions docs/utils/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ API
.. automodapi:: plasmapy.utils.code_repr
:include-heading:

.. automodapi:: plasmapy.utils.pytest_helpers
:include-heading:

.. automodapi:: plasmapy.utils.calculator
:include-heading:

Expand Down
4 changes: 2 additions & 2 deletions docs/whatsnew/0.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Backwards Incompatible Changes
and migrated the dispersion functionality (:file:`dispersionfunction.py`) from
`plasmapy.formulary` to `plasmapy.dispersion`. (`#910 <https://github.com/plasmapy/plasmapy/pull/910>`__)
- Removed default values for the ``ion`` and ``particle`` arguments of functions contained in ``plasmapy.formulary.parameters``, in accordance with issue [#453](https://github.com/PlasmaPy/PlasmaPy/issues/453), and updated all relevant calls to modified functionality. (`#911 <https://github.com/plasmapy/plasmapy/pull/911>`__)
- Moved test helper exceptions from `plasmapy.utils.pytest_helpers` to `plasmapy.tests.helpers`. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Moved test helper exceptions from ``plasmapy.utils.pytest_helpers`` to ``plasmapy.tests.helpers``. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Updated ``plasmapy.formulary.parameters.mass_density`` so it calculates the mass
density for a specific particle from a given number density. Original function
calculated the total mass density (ion + electron). (`#957 <https://github.com/plasmapy/plasmapy/pull/957>`__)
Expand All @@ -42,7 +42,7 @@ Features
functions are designed to wrap together an analytical function, a curve fitter,
uncertainty propagation, and a root solver to make curve fitting a little less
painful. (`#908 <https://github.com/plasmapy/plasmapy/pull/908>`__)
- Created a new subpackage, `plasmapy.tests.helpers`, to contain test helper functionality. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Created a new subpackage, ``plasmapy.tests.helpers``, to contain test helper functionality. (`#919 <https://github.com/plasmapy/plasmapy/pull/919>`__)
- Create decorator `~plasmapy.utils.decorators.helpers.modify_docstring`, which allows
for programmatically prepending and/or appending a docstring. (`#943 <https://github.com/plasmapy/plasmapy/pull/943>`__)

Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/collisions/tests/test_coulomb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from plasmapy.formulary.collisions.coulomb import Coulomb_logarithm
from plasmapy.utils import exceptions
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import CouplingWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


class Test_Coulomb_logarithm:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/collisions/tests/test_dimensionless.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Knudsen_number,
)
from plasmapy.utils import exceptions
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import CouplingWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


class Test_coupling_parameter:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/collisions/tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
)
from plasmapy.particles import Particle
from plasmapy.utils import exceptions
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import CouplingWarning, PhysicsError
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


class TestSingleParticleCollisionFrequencies:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/collisions/tests/test_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from plasmapy.formulary.collisions import coulomb, lengths
from plasmapy.utils import exceptions
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import CouplingWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


class Test_impact_parameter_perp:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/collisions/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from plasmapy.formulary.collisions.misc import mobility, Spitzer_resistivity
from plasmapy.utils import exceptions
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import CouplingWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


class Test_Spitzer_resistivity:
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_dimensionless.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from plasmapy.particles import Particle
from plasmapy.utils import RelativityWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray

Z = 1

Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
wuh_,
)
from plasmapy.particles.exceptions import InvalidParticleError
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray

Z = 1
ion = "p"
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from plasmapy.formulary.speeds import thermal_speed
from plasmapy.particles.exceptions import InvalidParticleError
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray

Z = 1
n_i = 5e19 * u.m**-3
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ub_,
)
from plasmapy.particles import Particle
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray

B = 1.0 * u.T
B_arr = np.array([0.001, 0.002]) * u.T
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_plasma_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from plasmapy.formulary.frequencies import plasma_frequency, plasma_frequency_lite, wp_
from plasmapy.particles import Particle
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_speeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from plasmapy.formulary.speeds import Alfven_speed, cs_, ion_sound_speed, va_
from plasmapy.particles import Particle
from plasmapy.particles.exceptions import InvalidParticleError
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import (
PhysicsError,
PhysicsWarning,
RelativityError,
RelativityWarning,
)
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray

Z = 1

Expand Down
2 changes: 1 addition & 1 deletion plasmapy/formulary/tests/test_thermal_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
)
from plasmapy.particles import Particle
from plasmapy.particles.exceptions import InvalidParticleError
from plasmapy.utils._pytest_helpers import assert_can_handle_nparray
from plasmapy.utils.exceptions import RelativityError, RelativityWarning
from plasmapy.utils.pytest_helpers import assert_can_handle_nparray


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/particles/tests/test_atomic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)
from plasmapy.particles.particle_class import Particle
from plasmapy.particles.symbols import atomic_symbol, element_name, isotope_symbol
from plasmapy.utils.pytest_helpers import run_test
from plasmapy.utils._pytest_helpers import run_test

# function to be tested, argument(s), expected result/outcome

Expand Down
2 changes: 1 addition & 1 deletion plasmapy/particles/tests/test_nuclear.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
nuclear_binding_energy,
nuclear_reaction_energy,
)
from plasmapy.utils.pytest_helpers import run_test, run_test_equivalent_calls
from plasmapy.utils._pytest_helpers import run_test, run_test_equivalent_calls

test_nuclear_equivalent_calls_table = [
[nuclear_binding_energy, ["He-4", {}], ["alpha", {}], ["He", {"mass_numb": 4}]]
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/particles/tests/test_particle_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
valid_categories,
)
from plasmapy.utils import roman
from plasmapy.utils._pytest_helpers import run_test_equivalent_calls
from plasmapy.utils.code_repr import call_string
from plasmapy.utils.pytest_helpers import run_test_equivalent_calls

# (arg, kwargs, results_dict)
test_Particle_table = [
Expand Down
4 changes: 2 additions & 2 deletions plasmapy/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""PlasmaPy tests and test helpers."""
"""PlasmaPy tests and test _helpers."""

from plasmapy.tests import helpers
from plasmapy.tests import _helpers
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# requests that were each originally part of #728. The blank lines
# between the import statements will hopefully simplify automatic merging.

# from plasmapy.tests.helpers.actual import ActualTestOutcome
# from plasmapy.tests._helpers.actual import ActualTestOutcome

# from plasmapy.tests.helpers.cases import AttrTestCase, FunctionTestCase, MethodTestCase
# from plasmapy.tests._helpers.cases import AttrTestCase, FunctionTestCase, MethodTestCase

from plasmapy.tests.helpers.exceptions import (
from plasmapy.tests._helpers.exceptions import (
ExceptionMismatchFail,
InvalidTestError,
MissingExceptionFail,
Expand All @@ -35,14 +35,14 @@
WarningMismatchFail,
)

# from plasmapy.tests.helpers.expected import ExpectedTestOutcome
# from plasmapy.tests._helpers.expected import ExpectedTestOutcome

# from plasmapy.tests.helpers.inputs import (
# from plasmapy.tests._helpers.inputs import (
# AbstractTestInputs,
# ClassAttributeTestInputs,
# ClassMethodTestInputs,
# FunctionTestInputs,
# GenericClassTestInputs,
# )

# from plasmapy.tests.helpers.runner import test_runner
# from plasmapy.tests._helpers.runner import test_runner
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions plasmapy/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,3 @@
RelativityError,
RelativityWarning,
)

with contextlib.suppress(ModuleNotFoundError):
# pytest is not a hard dependency, so only import pytest_helpers if pytest
# is installed
from plasmapy.utils import pytest_helpers
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from plasmapy.utils.pytest_helpers.pytest_helpers import (
from plasmapy.utils._pytest_helpers.pytest_helpers import (
assert_can_handle_nparray,
run_test,
run_test_equivalent_calls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from typing import Any, Callable

from plasmapy.tests.helpers.exceptions import (
from plasmapy.tests._helpers.exceptions import (
InvalidTestError,
MissingExceptionFail,
MissingWarningFail,
Expand Down Expand Up @@ -113,22 +113,22 @@ def run_test( # noqa: C901
Raises
------
~plasmapy.tests.helpers.exceptions.UnexpectedResultFail
~plasmapy.tests._helpers.exceptions.UnexpectedResultFail
If the test returns a result that is different from the expected
result.
~plasmapy.tests.helpers.exceptions.TypeMismatchFail
~plasmapy.tests._helpers.exceptions.TypeMismatchFail
If the actual result is of a different type than the expected
result.
~plasmapy.tests.helpers.exceptions.UnexpectedExceptionFail
~plasmapy.tests._helpers.exceptions.UnexpectedExceptionFail
If an exception occurs when no exception or a different
exception is expected.
~plasmapy.tests.helpers.exceptions.MissingExceptionFail
~plasmapy.tests._helpers.exceptions.MissingExceptionFail
If no exception is raised when an exception is expected.
~plasmapy.tests.helpers.exceptions.MissingWarningFail
~plasmapy.tests._helpers.exceptions.MissingWarningFail
An expected warning is not issued.
~astropy.units.UnitsError
Expand Down Expand Up @@ -433,16 +433,16 @@ def run_test_equivalent_calls( # noqa: C901
Raises
------
~plasmapy.tests.helpers.exceptions.UnexpectedResultFail
~plasmapy.tests._helpers.exceptions.UnexpectedResultFail
If not all of the results are equivalent, or not all of the
results are of the same type and ``require_same_type`` evaluates
to `True`.
~plasmapy.tests.helpers.exceptions.UnexpectedExceptionFail
~plasmapy.tests._helpers.exceptions.UnexpectedExceptionFail
If an exception is raised whilst attempting to run one of the
test cases.
~plasmapy.tests.helpers.exceptions.InvalidTestError
~plasmapy.tests._helpers.exceptions.InvalidTestError
If there is an error associated with the inputs or the test is
set up incorrectly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from typing import Any

from plasmapy.particles import Particle
from plasmapy.tests.helpers import (
from plasmapy.tests._helpers import (
MissingExceptionFail,
MissingWarningFail,
TypeMismatchFail,
UnexpectedExceptionFail,
UnexpectedResultFail,
)
from plasmapy.utils._pytest_helpers import run_test, run_test_equivalent_calls
from plasmapy.utils.code_repr import call_string
from plasmapy.utils.exceptions import PlasmaPyError, PlasmaPyWarning
from plasmapy.utils.pytest_helpers import run_test, run_test_equivalent_calls


def generic_function(*args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion plasmapy/utils/tests/test_roman.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

from plasmapy.utils import roman
from plasmapy.utils.pytest_helpers import run_test
from plasmapy.utils._pytest_helpers import run_test

ints_and_roman_numerals = [
(1, "I"),
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ max-complexity = 10
"plasmapy/formulary/tests/test_distribution.py" = ["ARG005"]
"plasmapy/particles/tests/test_decorators.py" = ["ARG001", "ARG002"]
"plasmapy/plasma/sources/*.py" = ["D102"]
"plasmapy/utils/pytest_helpers/pytest_helpers.py" = ["BLE001", "PLR"]
"plasmapy/utils/pytest_helpers/tests/test_pytest_helpers.py" = ["BLE001", "TRY002"]
"plasmapy/utils/_pytest_helpers/pytest_helpers.py" = ["BLE001", "PLR"]
"plasmapy/utils/_pytest_helpers/tests/test_pytest_helpers.py" = ["BLE001", "TRY002"]
"setup.py" = ["D100"]
"test_*" = ["D100", "D101", "D102", "D103", "D104", "D209", "D400", "D401"]
"*/*/tests/__init__.py" = ["D104"]
Expand Down

0 comments on commit fa09634

Please sign in to comment.