Skip to content

Commit

Permalink
Function (w/ tests) for checking that resolution specification is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Aug 2, 2022
1 parent 373752e commit 5a58a2f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
14 changes: 14 additions & 0 deletions stimuli/utils/sizes.py
Expand Up @@ -5,6 +5,20 @@
Ppd = namedtuple("Ppd", "vertical horizontal")


class ResolutionError(ValueError):
pass


def valid_resolution(shape, visual_size, ppd):
shape = validate_shape(shape)
ppd = validate_ppd(ppd)
visual_size = validate_visual_size(visual_size)

calculated = shape_from_visual_size_ppd(visual_size=visual_size, ppd=ppd)
if calculated != shape:
raise ResolutionError(f"Invalid resolution; {visual_size},{shape},{ppd}")


def visual_size_from_shape_ppd(shape, ppd):
shape = validate_shape(shape)
ppd = validate_ppd(ppd)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_resolve.py
@@ -0,0 +1,39 @@
import pytest
from stimuli.utils import sizes


@pytest.mark.parametrize(
"shape, visual_size, ppd",
(
((1024, 1024), (32, 32), (32, 32)),
((1024, 1024), (32, 16), (32, 64)),
((512, 1024), (16, 64), (32, 16)),
((500, 400), (20, 40), (25, 10)),
(1024, (32, 32), (32, 32)),
((1024, 1024), 32, (32, 32)),
((1024, 1024), (32, 32), 32),
),
)
def test_pass_valid_resolution(shape, visual_size, ppd):
sizes.valid_resolution(shape=shape, visual_size=visual_size, ppd=ppd)


@pytest.mark.parametrize(
"shape, visual_size, ppd",
(
((1024, 1024), (32, 32), (16, 16)),
((1024, 1024), (32, 16), (32, 32)),
((512, 1024), (32, 32), (32, 32)),
((500, 400), (20, 20), (25, 10)),
(1024, (32, 16), (32, 32)),
((1024, 512), 32, (32, 30)),
((1024, 512), (32, 32), 32),
),
)
def test_raises_valid_resolution(shape, visual_size, ppd):
with pytest.raises(ValueError) as e_info:
sizes.valid_resolution(shape=shape, visual_size=visual_size, ppd=ppd)


def test_resolve():
pass

0 comments on commit 5a58a2f

Please sign in to comment.