Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import pytest
import numpy as np
from pathlib import Path
from unittest.mock import MagicMock, patch
# Importing symbols from loader module
from rq_controller.common import PyProjection, PyProjectionGeometry, PyRegionOfIntrest, PyVolume
import pyometiff
from rq_controller.common.io.rq_json import RqJsonLoader
class MockOMETIFFReader:
def __init__(self, data):
self.data = data
def read(self):
return self.data, None, None
@pytest.fixture
def rq_json_loader() -> RqJsonLoader:
return RqJsonLoader()
@pytest.fixture
def mock_load_json():
# Mocking the load_json method to avoid actual file operations
with patch.object(RqJsonLoader, 'load_json') as mock:
mock.return_value = {
'focal_spot_mm': np.array([1.0, 1.1, 1.2]),
'detector_postion_mm': np.array([2.0, 2.1, 2.2]),
'detector_orientation_quad': np.array([3.0, 3.1, 3.2]),
'frame_id': 'frame1',
'focal_spot_orientation_quad': np.array([4.0, 4.1, 4.2]),
'detector_heigth_mm': 5.0,
'detector_width_mm': 6.0,
'voltage_kv': 7.0,
'current_ua': 8.0,
'exposure_time_ms': 9.0,
'center_points_mm': [10.0, 11.0, 12.0],
'dimensions_mm': [13.0, 14.0, 15.0],
'resolution_mm': [16.0, 17.0, 18.0]
}
yield mock
def test_initialization(rq_json_loader):
assert rq_json_loader.porjection_geometry_suffix == '.geom-json'
assert rq_json_loader.projection_suffix == '.tif'
assert rq_json_loader.region_of_intrest_suffix == '.roi-json'
assert rq_json_loader.volume_suffix == '.ome.tiff'
def test_load_projection_geometry(rq_json_loader, mock_load_json):
load_path = Path('/fake/path.tif')
projection_geometry = rq_json_loader.load_projection_geometry(load_path)
assert isinstance(projection_geometry, PyProjectionGeometry)
# Add more assertions as needed based on your implementation
def test_load_projection(rq_json_loader, mock_load_json):
load_path = Path('/fake/path.tif')
projection = rq_json_loader.load_projection(load_path)
assert isinstance(projection, PyProjection)
# Add more assertions as needed based on your implementation
def test_load_region_of_intrest(rq_json_loader, mock_load_json):
load_path = Path('/fake/path.roi-json')
region_of_intrest = rq_json_loader.load_region_of_intrest(load_path)
assert isinstance(region_of_intrest, PyRegionOfIntrest)
# Add more assertions as needed based on your implementation
def test_load_volume(rq_json_loader, mock_load_json):
load_path = Path('/fake/path.ome.tiff')
with patch('pyometiff.OMETIFFReader', MockOMETIFFReader):
volume = rq_json_loader.load_volume(load_path)
assert isinstance(volume, PyVolume)
# Add more assertions as needed based on your implementation
def test_load_projection_geometry_raises_not_implemented(rq_json_loader):
load_path = Path('/fake/path.tif')
with pytest.raises(NotImplementedError):
rq_json_loader.load_projection_geometry(load_path)
def test_load_projection_raises_not_implemented(rq_json_loader):
load_path = Path('/fake/path.tif')
with pytest.raises(NotImplementedError):
rq_json_loader.load_projection(load_path)
def test_load_region_of_intrest_raises_not_implemented(rq_json_loader):
load_path = Path('/fake/path.roi-json')
with pytest.raises(NotImplementedError):
rq_json_loader.load_region_of_intrest(load_path)
def test_load_volume_raises_not_implemented(rq_json_loader):
load_path = Path('/fake/path.ome.tiff')
with pytest.raises(NotImplementedError):
rq_json_loader.load_volume(load_path)
def test_load_json(rq_json_loader):
load_path = Path('/fake/path.json')
data_dict = {
'focal_spot_mm': np.array([1.0]),
'detector_postion_mm': np.array([2.0]),
'detector_orientation_quad': np.array([3.0]),
'frame_id': 'frame1',
'focal_spot_orientation_quad': np.array([4.0])
}
with patch('builtins.open', MagicMock(return_value=MagicMock(spec=open))):
with patch('json.load', MagicMock(return_value=data_dict)):
result = rq_json_loader.load_json(load_path)
assert result == data_dict
def test_load_json_file_not_found(rq_json_loader):
load_path = Path('/fake/path.json')
with pytest.raises(FileNotFoundError):
rq_json_loader.load_json(load_path)
def test_load_volume_invalid_dtype(rq_json_loader, mock_load_json):
load_path = Path('/fake/path.ome.tiff')
with patch('pyometiff.OMETIFFReader', MockOMETIFFReader):
with pytest.raises(ValueError):
rq_json_loader.load_volume(load_path)