test_mci_sim.py 5.96 KB
Newer Older
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
1
"""
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
2
3
4
Identifier:     mci_sim/tests/test_mci_sim.py
Name:           test_mci_sim.py
Description:    Test mci sim.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
5
6
7
8
9
10
11
12
13
14
Author:         Zhaojun Yan
Created:        2024-04-09
Modified-History:
    2024-04-09, Zhaojun Yan, created

"""

import unittest
import os
import sys
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
15
import faulthandler
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
16
from csst_mci_sim import csst_mci_sim
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
17

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
18

Yan Zhaojun's avatar
update  
Yan Zhaojun committed
19
class TestDemoFunction(unittest.TestCase):
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
20
    def test_mci_sim_1(self):
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
21
22
23
        """
        Aim
        ---
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
24
        Test mci sim function: EXDF case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
25
26
27
28
29
30
31
32
33
34

        Criteria
        --------
        Pass if the demo function returns `1`.

        Details
        -------
        The demo function returns the length of the input argument list.
        This case aims to test whether the demo function returns `1` if input is `None`.
        """
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
35
        faulthandler.enable()
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
36

Yan Zhaojun's avatar
update  
Yan Zhaojun committed
37
        # demo function test
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
38
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'], 'mci_sim/')
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
39
        print(dir_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
40

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
41
        # 获取当前工作目录
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
42
        # current_path = os.getcwd()
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
43
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
44

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
45
        configfile = './csst_mci_sim/mci_data/mci_C10.config'
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
46

Yan Zhaojun's avatar
test    
Yan Zhaojun committed
47
        sourcein = 'EXDF'
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
48
        print(configfile)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
49
50
51
52
53
54
55
56

        debug = True

        result_path = dir_path + 'mci_sim_result/'

        csst_mci_sim.runMCIsim(sourcein,  configfile,
                               dir_path, result_path, debug, 1)

Yan Zhaojun's avatar
update  
Yan Zhaojun committed
57
        self.assertEqual(
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
58
            1, 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
59
            "case 1: EXDF sim passes.",
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
60
        )
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
61
    ############################################
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
62

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
63
64
65
66
67
    def test_mci_sim_2(self):
        """
        Aim
        ---
        Test mci sim function: STAR case.
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
68

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
69
70
71
        Criteria
        --------
        Pass if the demo function returns `1`.
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
72

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
73
74
75
76
77
78
        Details
        -------
        The demo function returns the length of the input argument list.
        This case aims to test whether the demo function returns `1` if input is `None`.
        """
        faulthandler.enable()
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
79

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
80
        # demo function test
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
81
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'], 'mci_sim/')
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
82
        print(dir_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
83

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
84
        # 获取当前工作目录
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
85
        # current_path = os.getcwd()
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
86
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
87

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
88
        configfile = './csst_mci_sim/mci_data/mci_C10.config'
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
89

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
90
91
        sourcein = 'STAR'
        print(configfile)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
92
93
94
95
96
97
98
99

        debug = True

        result_path = dir_path + 'mci_sim_result/'

        csst_mci_sim.runMCIsim(sourcein,  configfile,
                               dir_path, result_path, debug, 1)

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
100
        self.assertEqual(
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
101
            1, 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
102
            "case 2: STAR sim passes.",
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
103
104
        )

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
105
106
107
108
109
110
    #########################################################
    def test_mci_sim_3(self):
        """
        Aim
        ---
        Test mci sim function: BIAS case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
111

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
112
113
114
        Criteria
        --------
        Pass if the demo function returns `1`.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
115

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
116
117
118
119
120
121
        Details
        -------
        The demo function returns the length of the input argument list.
        This case aims to test whether the demo function returns `1` if input is `None`.
        """
        faulthandler.enable()
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
122

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
123
        # demo function test
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
124
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'], 'mci_sim/')
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
125
        print(dir_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
126

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
127
        # 获取当前工作目录
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
128
        # current_path = os.getcwd()
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
129
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
130

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
131
        configfile = './csst_mci_sim/mci_data/mci_C10.config'
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
132

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
133
134
        sourcein = 'BIAS'
        print(configfile)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
135
136
137
138
139
140
141
142

        debug = True

        result_path = dir_path + 'mci_sim_result/'

        csst_mci_sim.runMCIsim(sourcein,  configfile,
                               dir_path, result_path, debug, 1)

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
143
        self.assertEqual(
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
144
            1, 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
145
146
147
            "case 3: BIAS sim passes.",
        )
    #########################################################
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
148

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
149
150
151
152
153
    def test_mci_sim_4(self):
        """
        Aim
        ---
        Test mci sim function: DARK case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
154

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
155
156
157
        Criteria
        --------
        Pass if the demo function returns `1`.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
158

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
159
160
161
162
163
164
        Details
        -------
        The demo function returns the length of the input argument list.
        This case aims to test whether the demo function returns `1` if input is `None`.
        """
        faulthandler.enable()
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
165

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
166
        # demo function test
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
167
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'], 'mci_sim/')
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
168
        print(dir_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
169

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
170
        # 获取当前工作目录
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
171
        # current_path = os.getcwd()
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
172
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
173

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
174
        configfile = './csst_mci_sim/mci_data/mci_C10.config'
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
175

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
176
177
        sourcein = 'DARK'
        print(configfile)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
178
179
180
181
182
183
184
185

        debug = True

        result_path = dir_path + 'mci_sim_result/'

        csst_mci_sim.runMCIsim(sourcein,  configfile,
                               dir_path, result_path, debug, 1)

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
186
        self.assertEqual(
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
187
            1, 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
188
            "case 4: DARK sim passes.",
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
189
190
        )

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
191
192
193
194
195
196
    #########################################################
    def test_mci_sim_5(self):
        """
        Aim
        ---
        Test mci sim function: FLAT case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
197

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
198
199
200
        Criteria
        --------
        Pass if the demo function returns `1`.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
201

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
202
203
204
205
206
207
        Details
        -------
        The demo function returns the length of the input argument list.
        This case aims to test whether the demo function returns `1` if input is `None`.
        """
        faulthandler.enable()
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
208

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
209
        # demo function test
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
210
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'], 'mci_sim/')
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
211
        print(dir_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
212

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
213
        # 获取当前工作目录
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
214
        # current_path = os.getcwd()
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
215
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
216

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
217
        configfile = './csst_mci_sim/mci_data/mci_C10.config'
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
218
219
        sourcein = 'FLAT'
        print(configfile)
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
220
221
222
223
224
225
226
227

        debug = True

        result_path = dir_path + 'mci_sim_result/'

        csst_mci_sim.runMCIsim(sourcein,  configfile,
                               dir_path, result_path, debug, 1)

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
228
        self.assertEqual(
Yan Zhaojun's avatar
update    
Yan Zhaojun committed
229
            1, 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
230
231
            "case 5: FLAT sim passes.",
        )
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
232

Yan Zhaojun's avatar
update  
Yan Zhaojun committed
233

Yan Zhaojun's avatar
update    
Yan Zhaojun committed
234
# ############################################################################