def test_custom_particles_from_json_file(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) test_file_object = io.StringIO(json_string) instance_from_json = json_load_particle(test_file_object) 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): test_file_object = io.StringIO(json_string) instance_from_json = json_load_particle(test_file_object) pytest.fail( f"{cls.__name__} with ({json_string})" f" did not raise: {expected_exception.__name__}." )
def test_particles_from_json_file(cls, kwargs, json_string, expected_exception): """Test the attributes of Particle objects created from JSON representation.""" if expected_exception is None: instance = cls(**kwargs) test_file_object = io.StringIO(json_string) test_file_object.seek(0, io.SEEK_SET) instance_from_json = json_load_particle(test_file_object) 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): test_file_object = io.StringIO(json_string) instance_from_json = json_load_particle(test_file_object) pytest.fail(f"{cls.__name__} with ({json_string})" f" did not raise: {expected_exception.__name__}.")