mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-11 06:47:14 +02:00
This commit is contained in:
29
python/tests/conftest.py
Normal file
29
python/tests/conftest.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption(
|
||||
"--files", action="store_true", default=False, help="run slow tests"
|
||||
)
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
config.addinivalue_line("markers", "files: mark test as needing image files to run")
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(config, items):
|
||||
if config.getoption("--files"):
|
||||
return
|
||||
skip = pytest.mark.skip(reason="need --files option to run")
|
||||
for item in items:
|
||||
if "files" in item.keywords:
|
||||
item.add_marker(skip)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_data_path():
|
||||
return Path(os.environ["AARE_TEST_DATA"])
|
||||
|
92
python/tests/test_jungfrau_dat_files.py
Normal file
92
python/tests/test_jungfrau_dat_files.py
Normal file
@ -0,0 +1,92 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
from aare import JungfrauDataFile
|
||||
|
||||
@pytest.mark.files
|
||||
def test_jfungfrau_dat_read_number_of_frames(test_data_path):
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 24
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 53
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as dat_file:
|
||||
assert dat_file.total_frames == 113
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_jfungfrau_dat_read_number_of_file(test_data_path):
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 4
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 7
|
||||
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as dat_file:
|
||||
assert dat_file.n_files == 7
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_module(test_data_path):
|
||||
"""
|
||||
Read all frames from the series of .dat files. Compare to canned data in npz format.
|
||||
"""
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF500k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
#Sanity check
|
||||
n_frames = 24
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 512, 1024)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF500k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_half_module(test_data_path):
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF250k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
n_frames = 53
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 256, 1024)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF250k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
||||
|
||||
|
||||
@pytest.mark.files
|
||||
def test_read_single_chip(test_data_path):
|
||||
|
||||
# Read all frames from the .dat file
|
||||
with JungfrauDataFile(test_data_path / "dat/AldoJF65k_000000.dat") as f:
|
||||
header, data = f.read()
|
||||
|
||||
n_frames = 113
|
||||
assert header.size == n_frames
|
||||
assert data.shape == (n_frames, 256, 256)
|
||||
|
||||
# Read reference data using numpy
|
||||
with np.load(test_data_path / "dat/AldoJF65k.npz") as f:
|
||||
ref_header = f["headers"]
|
||||
ref_data = f["frames"]
|
||||
|
||||
# Check that the data is the same
|
||||
assert np.all(ref_header == header)
|
||||
assert np.all(ref_data == data)
|
Reference in New Issue
Block a user