예제 #1
0
def test_particle_list_dimensionless_particles():
    """
    Test that a `ParticleList` cannot be instantiated with a
    `DimensionlessParticle`.
    """
    with pytest.raises(TypeError):
        ParticleList([DimensionlessParticle()])
예제 #2
0
class TestPickling:
    """
    Test that different objects in `plasmapy.particles` can be pickled.
    """

    xfail = pytest.mark.xfail(reason="see issue #1011")

    @pytest.mark.parametrize(
        "instance",
        [
            CustomParticle(mass=1 * u.kg, charge=1 * u.C),
            DimensionlessParticle(mass=5, charge=5),
            pytest.param(Particle("p+"), marks=xfail),
            pytest.param(IonicFraction("p+", 0.1, 1e9 * u.m**-3), marks=xfail),
            pytest.param(IonizationState("H", [0.5, 0.5]), marks=xfail),
            pytest.param(IonizationStateCollection({"H": [0.5, 0.5]}),
                         marks=xfail),
        ],
    )
    def test_pickling(self, instance, tmp_path):
        """
        Test that different objects contained within `plasmapy.particles`
        can be pickled and unpickled.
        """
        filename = tmp_path / "pickled_particles.p"
        with open(filename, "wb") as pickle_file:
            pickle.dump(instance, pickle_file)

        with open(filename, "rb") as pickle_file:
            loaded_particle = pickle.load(pickle_file)

        assert str(instance) == str(loaded_particle)
예제 #3
0
from typing import Dict

from plasmapy.particles import alpha, electron, neutron, proton
from plasmapy.particles.atomic import atomic_number
from plasmapy.particles.exceptions import ChargeError, InvalidParticleError
from plasmapy.particles.nuclear import nuclear_reaction_energy
from plasmapy.particles.particle_class import (
    CustomParticle,
    DimensionlessParticle,
    Particle,
    ParticleLike,
)
from plasmapy.particles.particle_collections import ionic_levels, ParticleList

custom_particle = CustomParticle(mass=1e-25 * u.kg, charge=1e-18 * u.C)
dimensionless_particle = DimensionlessParticle(mass=1.25, charge=1.58)

attributes = [
    "charge",
    "half_life",
    "charge_number",
    "mass",
    "mass_energy",
]


@pytest.fixture
def various_particles():
    """A sample `ParticleList` with several different valid particles."""
    return ParticleList([
        "H",