fusion-energy / paramak

Create parametric 3D fusion reactor CAD and neutronics models
https://paramak.readthedocs.io/en/main/
MIT License
58 stars 17 forks source link

more concise tests with pytest.raises #276

Open shimwell opened 1 year ago

shimwell commented 1 year ago

We have lots of tests that have a nested function def and then assert the function call raises an error, for example

https://github.com/fusion-energy/paramak/blob/8862e29f3761d06dac5fd368160c26face82b900/tests/tests_units/test_shape.py#L64-L76

however this test could be shortened to by using pytest.raises

def test_graveyard_error_when_no_offset_or_size(self):
    """Attempts to make a shape with a graveyard_size that is an int
    which should raise a ValueError"""

    with pytest.raises(ValueError):
        test_shape = paramak.RotateStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            graveyard_size=None,
            graveyard_offset=None,
        )
        test_shape.make_graveyard()