Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tests using pytest #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions test_autocti/extract/two_d/serial/test_serial_prescan.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
import numpy as np
import pytest

import autocti as ac


def test__region_list_from(serial_array, serial_masked_array):
extract = ac.Extract2DSerialPrescan(serial_prescan=(0, 3, 1, 4))
@pytest.fixture(name="extract")
def make_extract():
return ac.Extract2DSerialPrescan(serial_prescan=(0, 3, 1, 4))

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(0, 1))

assert (prescan_list[0] == np.array([[1.0], [1.0], [1.0]])).all()
@pytest.mark.parametrize(
"pixels, array",
[
((0, 1), [[1.0], [1.0], [1.0]]),
((1, 2), [[2.0], [2.0], [2.0]]),
((2, 3), [[3.0], [3.0], [3.0]]),
((-1, 1), [[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]),
((0, 2), [[1.0, 2.0], [1.0, 2.0], [1.0, 2.0]]),
((1, 4), [[2.0, 3.0, 4.0], [2.0, 3.0, 4.0], [2.0, 3.0, 4.0]]),
]
)
def test_region_list_serial_array(extract, serial_array, pixels, array):
prescan_list = extract.array_2d_list_from(array=serial_array, pixels=pixels)

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(1, 2))
assert (prescan_list[0] == np.array(array)).all()

assert (prescan_list[0] == np.array([[2.0], [2.0], [2.0]])).all()

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(2, 3))

assert (prescan_list[0] == np.array([[3.0], [3.0], [3.0]])).all()

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(-1, 1))

assert (prescan_list[0] == np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]])).all()

extract = ac.Extract2DSerialPrescan(serial_prescan=(0, 3, 1, 5))

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(0, 2))

assert (prescan_list[0] == np.array([[1.0, 2.0], [1.0, 2.0], [1.0, 2.0]])).all()

prescan_list = extract.array_2d_list_from(array=serial_array, pixels=(1, 4))

assert (
prescan_list[0] == np.array([[2.0, 3.0, 4.0], [2.0, 3.0, 4.0], [2.0, 3.0, 4.0]])
).all()

def test_region_list_serial_masked_array(extract, serial_masked_array):
prescan_list = extract.array_2d_list_from(array=serial_masked_array, pixels=(0, 3))

assert (
(prescan_list[0].mask)
== np.array(
[[False, False, False], [False, True, False], [False, False, False]]
)
(prescan_list[0].mask)
== np.array(
[[False, False, False], [False, True, False], [False, False, False]]
)
).all()