-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_CILViewerBase.py
More file actions
87 lines (71 loc) · 3.55 KB
/
Copy pathtest_CILViewerBase.py
File metadata and controls
87 lines (71 loc) · 3.55 KB
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
# Copyright 2023 STFC, United Kingdom Research and Innovation
#
# Author 2023 Laura Murgatroyd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import unittest
from unittest import mock
import os
from ccpi.viewer.CILViewer import CILViewerBase
from vtkmodules.vtkRenderingCore import vtkGraphicsFactory
skip_test = False
print("skip_test is set to ", skip_test)
@unittest.skipIf(skip_test, "Skipping tests on GitHub Actions")
class CILViewerBaseTest(unittest.TestCase):
def setUp(self):
'''Creates an instance of the CIL viewer base class.'''
vgf = vtkGraphicsFactory()
vgf.SetOffScreenOnlyMode(True)
vgf.SetUseMesaClasses(True)
self.vgf = vgf
self.CILViewerBase_instance = CILViewerBase()
def test_setAxisLabels(self):
'''Edits the labels in the axes widget and checks they have been set correctly.
The test is performed with overwrite flag set to default, True, or False.'''
labels = ['a', 'b', 'c']
self.CILViewerBase_instance.setAxisLabels(labels)
new_labels = self.CILViewerBase_instance.getCurrentAxisLabelsText()
self.assertEqual(new_labels, labels)
self.assertEqual(self.CILViewerBase_instance.axisLabelsText, labels)
labels_2 = ['c', 'd', 'e']
self.CILViewerBase_instance.setAxisLabels(labels_2, False)
new_labels = self.CILViewerBase_instance.getCurrentAxisLabelsText()
self.assertEqual(new_labels, labels_2)
self.assertEqual(self.CILViewerBase_instance.axisLabelsText, labels)
@unittest.skipIf(skip_test, "Skipping tests on GitHub Actions")
class CILViewer3DTest(unittest.TestCase):
def setUp(self):
vgf = vtkGraphicsFactory(off_screen_only_mode=True, use_mesa_classes=True)
self.cil_viewer = CILViewerBase()
def test_getSliceColorPercentiles_returns_correct_percentiles_when_slice_values_start_at_zero(self):
self.cil_viewer.getSliceMapRange = mock.MagicMock(return_value=[40, 50])
self.cil_viewer.getSliceMapWholeRange = mock.MagicMock(return_value=[0, 50])
expected_percentages = (80.0, 100.0)
actual_percentages = self.cil_viewer.getSliceColorPercentiles()
self.assertEqual(expected_percentages, actual_percentages)
def test_getSliceColorPercentiles_returns_correct_percentiles_when_slice_values_start_at_non_zero(self):
self.cil_viewer.getSliceMapRange = mock.MagicMock(return_value=[40, 50])
self.cil_viewer.getSliceMapWholeRange = mock.MagicMock(return_value=[10, 50])
expected_percentages = (75.0, 100.0)
actual_percentages = self.cil_viewer.getSliceColorPercentiles()
self.assertEqual(expected_percentages, actual_percentages)
def test_multiple_widgets_cant_be_saved_with_same_name(self):
widget1 = mock.MagicMock()
widget2 = mock.MagicMock()
widget_name = "widget1"
self.cil_viewer.addWidgetReference(widget1, widget_name)
with self.assertRaises(ValueError):
self.cil_viewer.addWidgetReference(widget2, widget_name)
if __name__ == '__main__':
unittest.main()