forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustment_test.py
104 lines (86 loc) · 4.26 KB
/
adjustment_test.py
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
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
from sans.common.enums import (SANSFacility, SANSInstrument)
from sans.state.StateObjects.StateAdjustment import (StateAdjustment, get_adjustment_builder)
from sans.state.StateObjects.StateCalculateTransmission import StateCalculateTransmission
from sans.state.StateObjects.StateData import (get_data_builder)
from sans.state.StateObjects.StateNormalizeToMonitor import StateNormalizeToMonitor
from sans.state.StateObjects.StateWavelengthAndPixelAdjustment import StateWavelengthAndPixelAdjustment
from sans.test_helper.file_information_mock import SANSFileInformationMock
# ----------------------------------------------------------------------------------------------------------------------
# State
# ----------------------------------------------------------------------------------------------------------------------
class MockStateNormalizeToMonitor(StateNormalizeToMonitor):
def validate(self):
pass
class MockStateCalculateTransmission(StateCalculateTransmission):
def validate(self):
pass
class MockStateWavelengthAndPixelAdjustment(StateWavelengthAndPixelAdjustment):
def validate(self):
pass
class StateReductionTest(unittest.TestCase):
def test_that_raises_when_calculate_transmission_is_not_set(self):
state = StateAdjustment()
state.normalize_to_monitor = MockStateNormalizeToMonitor()
state.wavelength_and_pixel_adjustment = MockStateWavelengthAndPixelAdjustment()
self.assertRaises(ValueError, state.validate)
state.calculate_transmission = MockStateCalculateTransmission()
try:
state.validate()
except ValueError:
self.fail()
def test_that_raises_when_normalize_to_monitor_is_not_set(self):
state = StateAdjustment()
state.calculate_transmission = MockStateCalculateTransmission()
state.wavelength_and_pixel_adjustment = MockStateWavelengthAndPixelAdjustment()
self.assertRaises(ValueError, state.validate)
state.normalize_to_monitor = MockStateNormalizeToMonitor()
try:
state.validate()
except ValueError:
self.fail()
def test_that_raises_when_wavelength_and_pixel_adjustment_is_not_set(self):
state = StateAdjustment()
state.calculate_transmission = MockStateCalculateTransmission()
state.normalize_to_monitor = MockStateNormalizeToMonitor()
self.assertRaises(ValueError, state.validate)
state.wavelength_and_pixel_adjustment = MockStateWavelengthAndPixelAdjustment()
try:
state.validate()
except ValueError:
self.fail()
# ----------------------------------------------------------------------------------------------------------------------
# Builder
# ----------------------------------------------------------------------------------------------------------------------
class StateAdjustmentBuilderTest(unittest.TestCase):
def test_that_reduction_state_can_be_built(self):
# Arrange
facility = SANSFacility.ISIS
file_information = SANSFileInformationMock(instrument=SANSInstrument.LOQ, run_number=74044)
data_builder = get_data_builder(facility, file_information)
data_builder.set_sample_scatter("LOQ74044")
data_info = data_builder.build()
# Act
builder = get_adjustment_builder(data_info)
self.assertTrue(builder)
builder.set_calculate_transmission(MockStateCalculateTransmission())
builder.set_normalize_to_monitor(MockStateNormalizeToMonitor())
builder.set_wavelength_and_pixel_adjustment(MockStateWavelengthAndPixelAdjustment())
builder.set_wide_angle_correction(False)
state = builder.build()
# # Assert
self.assertTrue(not state.wide_angle_correction)
try:
state.validate()
is_valid = True
except ValueError:
is_valid = False
self.assertTrue(is_valid)
if __name__ == '__main__':
unittest.main()