Skip to content

Commit df980db

Browse files
authored
Refactor MonitorNormalisation tests (#2820)
2 parents 83071e3 + 23ed40a commit df980db

File tree

2 files changed

+50
-57
lines changed

2 files changed

+50
-57
lines changed
Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
22
# SPDX - License - Identifier: GPL-3.0-or-later
33
from __future__ import annotations
4-
from functools import partial
54

5+
import unittest
6+
from functools import partial
67
from unittest import mock
8+
79
import numpy as np
810
import numpy.testing as npt
911

@@ -12,56 +14,50 @@
1214
from ..monitor_normalisation import MonitorNormalisation
1315

1416

15-
def test_one_projection():
16-
images = generate_images((1, 1, 1))
17-
images._log_file = mock.Mock()
18-
images._log_file.counts = mock.Mock(return_value=Counts(np.sin(np.linspace(0, 1, images.num_projections))))
19-
npt.assert_raises(RuntimeError, MonitorNormalisation.filter_func, images)
20-
21-
22-
def test_no_counts():
23-
images = generate_images((2, 2, 2))
24-
images._log_file = mock.Mock()
25-
images._log_file.counts = mock.Mock(return_value=None)
26-
npt.assert_raises(RuntimeError, MonitorNormalisation.filter_func, images)
27-
28-
29-
def test_execute():
30-
images = generate_images()
31-
images._log_file = mock.Mock()
32-
images._log_file.counts = mock.Mock(return_value=Counts(np.sin(np.linspace(0, 1, images.num_projections))))
33-
34-
original = images.copy()
35-
MonitorNormalisation.filter_func(images)
36-
images._log_file.counts.assert_called_once()
37-
assert_not_equals(original.data, images.data)
38-
39-
40-
def test_execute2():
41-
"""
42-
Test that the counts are correctly divided by the value at counts[0].
43-
44-
In this test that will make all the counts equal to 1, and the data will remain unchanged
45-
"""
46-
images = generate_images()
47-
images._log_file = mock.Mock()
48-
images._log_file.counts = mock.Mock(return_value=Counts(np.full((10, ), 10)))
49-
50-
original = images.copy()
51-
MonitorNormalisation.filter_func(images)
52-
images._log_file.counts.assert_called_once()
53-
npt.assert_equal(original.data, images.data)
54-
55-
56-
def test_register_gui():
57-
assert MonitorNormalisation.register_gui(None, None, None) == {}
58-
59-
60-
def test_execute_wrapper():
61-
wrapper = MonitorNormalisation.execute_wrapper()
62-
assert wrapper is not None
63-
assert isinstance(wrapper, partial)
64-
65-
66-
def test_validate_execute_kwargs():
67-
assert MonitorNormalisation.validate_execute_kwargs({}) is True
17+
class MonitorNormalisationTest(unittest.TestCase):
18+
19+
def test_one_projection(self):
20+
images = generate_images((1, 1, 1))
21+
images._log_file = mock.Mock()
22+
images._log_file.counts = mock.Mock(return_value=Counts(np.sin(np.linspace(0, 1, images.num_projections))))
23+
self.assertRaises(RuntimeError, MonitorNormalisation.filter_func, images)
24+
25+
def test_no_counts(self):
26+
images = generate_images((2, 2, 2))
27+
images._log_file = mock.Mock()
28+
images._log_file.counts = mock.Mock(return_value=None)
29+
self.assertRaises(RuntimeError, MonitorNormalisation.filter_func, images)
30+
31+
def test_execute(self):
32+
images = generate_images()
33+
images._log_file = mock.Mock()
34+
images._log_file.counts = mock.Mock(return_value=Counts(np.sin(np.linspace(0, 1, images.num_projections))))
35+
36+
original = images.copy()
37+
MonitorNormalisation.filter_func(images)
38+
images._log_file.counts.assert_called_once()
39+
self.assertEqual(original.data.shape, original.data.shape)
40+
assert_not_equals(original.data, images.data)
41+
42+
def test_execute2(self):
43+
"""
44+
Test that the counts are correctly divided by the value at counts[0].
45+
46+
In this test that will make all the counts equal to 1, and the data will remain unchanged
47+
"""
48+
images = generate_images()
49+
images._log_file = mock.Mock()
50+
images._log_file.counts = mock.Mock(return_value=Counts(np.full((10, ), 10)))
51+
52+
original = images.copy()
53+
MonitorNormalisation.filter_func(images)
54+
images._log_file.counts.assert_called_once()
55+
npt.assert_equal(original.data, images.data)
56+
57+
def test_register_gui(self):
58+
self.assertEqual(MonitorNormalisation.register_gui(None, None, None), {})
59+
60+
def test_execute_wrapper(self):
61+
wrapper = MonitorNormalisation.execute_wrapper()
62+
self.assertIsNotNone(wrapper)
63+
self.assertIsInstance(wrapper, partial)

mantidimaging/core/operations/overlap_correction/test/overlap_correction_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,3 @@ def test_execute_wrapper(self):
5555
wrapper = OverlapCorrection.execute_wrapper()
5656
assert wrapper is not None
5757
assert isinstance(wrapper, partial)
58-
59-
def test_validate_execute_kwargs(self):
60-
assert OverlapCorrection.validate_execute_kwargs({}) is True

0 commit comments

Comments
 (0)