improve arg checking
This commit is contained in:
parent
526b9e1666
commit
15c2cf8351
3 changed files with 90 additions and 40 deletions
|
|
@ -2,7 +2,7 @@ import pytest
|
|||
import numpy
|
||||
from numpy.testing import assert_allclose #, assert_array_equal
|
||||
|
||||
from .. import Grid, Extent, GridError, Plane
|
||||
from .. import Grid, Extent, GridError, Plane, Slab
|
||||
|
||||
|
||||
def test_draw_oncenter_2x2() -> None:
|
||||
|
|
@ -194,3 +194,35 @@ def test_sampled_visualization_helpers_do_not_error() -> None:
|
|||
|
||||
pyplot.close(fig_slice)
|
||||
pyplot.close(fig_edges)
|
||||
|
||||
|
||||
def test_grid_constructor_rejects_invalid_coordinate_count() -> None:
|
||||
with pytest.raises(GridError):
|
||||
Grid([[0, 1], [0, 1]], shifts=[[0, 0, 0]])
|
||||
|
||||
with pytest.raises(GridError):
|
||||
Grid([[0, 1], [0, 1], [0, 1], [0, 1]], shifts=[[0, 0, 0]])
|
||||
|
||||
|
||||
def test_grid_constructor_rejects_invalid_periodic_length() -> None:
|
||||
with pytest.raises(GridError):
|
||||
Grid([[0, 1], [0, 1], [0, 1]], shifts=[[0, 0, 0]], periodic=[True, False])
|
||||
|
||||
|
||||
def test_extent_and_slab_reject_inverted_geometry() -> None:
|
||||
with pytest.raises(GridError):
|
||||
Extent(center=0, min=1)
|
||||
|
||||
with pytest.raises(GridError):
|
||||
Extent(min=2, max=1)
|
||||
|
||||
with pytest.raises(GridError):
|
||||
Slab(axis='z', center=1, max=0)
|
||||
|
||||
|
||||
def test_extent_accepts_scalar_like_inputs() -> None:
|
||||
extent = Extent(min=numpy.array([1.0]), span=numpy.array([4.0]))
|
||||
|
||||
assert_allclose([extent.center, extent.span, extent.min, extent.max], [3.0, 4.0, 1.0, 5.0])
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue