def test_custom_particles_from_json_string( cls, kwargs, json_string, expected_exception ): """Test the attributes of dimensionless and custom particles generated from JSON representation""" if expected_exception is None: instance = cls(**kwargs) instance_from_json = json_loads_particle(json_string) assert u.isclose( instance.mass, instance_from_json.mass, equal_nan=True ), pytest.fail( f"Expected a mass value of {instance.mass}\n" f"Received a mass value of {instance_from_json.mass}" ) assert u.isclose( instance.charge, instance_from_json.charge, equal_nan=True ), pytest.fail( f"Expected a charge value of {instance.charge}\n" f"Received a charge value of {instance_from_json.charge}" ) else: with pytest.raises(expected_exception): instance_from_json = json_loads_particle(json_string) pytest.fail( f"{cls.__name__} with ({json_string})" f" did not raise: {expected_exception.__name__}." )
def test_particles_from_json_string(cls, kwargs, json_string, expected_exception): """Test the attributes of Particle objects created from JSON representation.""" if expected_exception is None: instance = cls(**kwargs) instance_from_json = json_loads_particle(json_string) expected_particle = instance.symbol actual_particle = instance_from_json.symbol assert expected_particle == actual_particle, pytest.fail( f"Expected {expected_particle}\nGot {actual_particle}") else: with pytest.raises(expected_exception): instance_from_json = json_loads_particle(json_string) pytest.fail(f"{cls.__name__} with ({json_string})" f" did not raise: {expected_exception.__name__}.")