Source code for ewoksxrdct.tests.test_create_nxxrdct

import h5py
import pytest
import numpy as np

from ewoksxrdct.tasks.create_nxxrdct import CreateNxxrdct
from pathlib import Path


[docs] @pytest.mark.parametrize("Task", [CreateNxxrdct]) def test_create_nxxrdct_task_outputs(Task, tmp_path): title = "test create_nxxrdct" test_file = str(tmp_path / "test_file.hdf5") beam_incident_energy = 60.0 sample_name = "sample-test" rotation_angle = np.linspace(0, 180, 181) detector_data = np.zeros((181, 256, 256)) detector_count_time = 0.1 inputs = { "title": title, "nx_path": test_file, "beam_incident_energy": beam_incident_energy, "sample_name": sample_name, "sample_rotation_angle": rotation_angle, "detector_data": detector_data, "detector_count_time": detector_count_time, } task = Task(inputs=inputs) task.execute() assert task.outputs.nx_path == test_file assert Path(test_file).is_file() # Test that the outputted file content is as expected with h5py.File(test_file, "r") as h5: data = h5["entry"] assert data["title"][()].decode() == title assert data["beam/incident_energy"][()] == beam_incident_energy assert data["sample/name"][()].decode() == sample_name np.testing.assert_allclose(data["sample/rotation_angle"][()], rotation_angle) np.testing.assert_allclose(data["instrument/detector/data"][()], detector_data) assert data["instrument/detector/count_time"][()] == detector_count_time