|
1 | 1 | # Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
|
2 | 2 | # SPDX - License - Identifier: GPL-3.0-or-later
|
3 | 3 | from __future__ import annotations
|
4 |
| -from functools import partial |
5 | 4 |
|
| 5 | +import unittest |
| 6 | +from functools import partial |
6 | 7 | from unittest import mock
|
| 8 | + |
7 | 9 | import numpy as np
|
8 | 10 | import numpy.testing as npt
|
9 | 11 |
|
|
12 | 14 | from ..monitor_normalisation import MonitorNormalisation
|
13 | 15 |
|
14 | 16 |
|
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) |
0 commit comments