test_mci_sim.py 6.32 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
class TestDemoFunction(unittest.TestCase):
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
19
    def test_mci_sim_1(self):
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
20
        
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
36
        faulthandler.enable()
        
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
37
        # demo function test
Yan Zhaojun's avatar
test    
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
test    
Yan Zhaojun committed
40
 
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
41
42
43
        # 获取当前工作目录
        # current_path = os.getcwd()         
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
44
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
45
        configfile = './csst_mci_sim/mci_data/mci_all_9K.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
debug    
Yan Zhaojun committed
49
50
        
        debug=True
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
51
52
        
        result_path = dir_path +'mci_sim_result/'
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
53
                
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
54
        csst_mci_sim.runMCIsim(sourcein,  configfile, dir_path, result_path, debug, 1)
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
55
        
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
56
        self.assertEqual(
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
57
            1 , 1,
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
58
            "case 1: EXDF sim passes.",
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
59
        )
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
60
61
    ############################################
    def test_mci_sim_2(self):
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
62
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
63
64
65
66
        """
        Aim
        ---
        Test mci sim function: STAR case.
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
67
    
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
68
69
70
        Criteria
        --------
        Pass if the demo function returns `1`.
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
71
    
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
72
73
74
75
76
77
78
79
80
81
        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()
        
        # demo function test
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
        print(dir_path)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
82
    
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
83
84
85
        # 获取当前工作目录
        # current_path = os.getcwd()         
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
86
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
87
        configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
88
      
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
89
90
        sourcein = 'STAR'
        print(configfile)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
91
                
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
92
        debug=True
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
93
                
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
94
95
96
        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
97
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
98
99
100
101
        self.assertEqual(
            1 , 1,
            "case 2: STAR sim passes.",
        )  
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
102
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
103
104
    #########################################################
    def test_mci_sim_3(self):
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
105
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
106
107
108
109
        """
        Aim
        ---
        Test mci sim function: BIAS case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
110

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

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
115
116
117
118
119
120
121
122
123
124
        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()
        
        # demo function test
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
        print(dir_path)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
125
 
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
126
127
128
        # 获取当前工作目录
        # current_path = os.getcwd()         
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
129
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
130
        configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
131
      
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
132
133
        sourcein = 'BIAS'
        print(configfile)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
134
                
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
135
        debug=True
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
136
                
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
137
138
139
        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
140
141
142
143
144
145
146
147
148
149
150
151
        
        self.assertEqual(
            1 , 1,
            "case 3: BIAS sim passes.",
        )
    #########################################################
    def test_mci_sim_4(self):
        
        """
        Aim
        ---
        Test mci sim function: DARK case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
152

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

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
157
158
159
160
161
162
163
164
165
166
        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()
        
        # demo function test
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
        print(dir_path)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
167
 
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
168
169
170
        # 获取当前工作目录
        # current_path = os.getcwd()         
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
171
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
172
        configfile = './csst_mci_sim/mci_data/mci_all_9K.config'
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
173
      
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
174
175
        sourcein = 'DARK'
        print(configfile)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
176
                
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
177
        debug=True
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
178
                
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
179
180
181
        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
182
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
183
184
185
186
        self.assertEqual(
            1 , 1,
            "case 4: DARK sim passes.",
        ) 
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
187
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
188
189
    #########################################################
    def test_mci_sim_5(self):
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
190
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
191
192
193
194
        """
        Aim
        ---
        Test mci sim function: FLAT case.
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
195

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

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
200
201
202
203
204
205
206
207
208
209
        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()
        
        # demo function test
        dir_path = os.path.join(os.environ['UNIT_TEST_DATA_ROOT'],'mci_sim/')
        print(dir_path)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
210
 
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
211
212
213
        # 获取当前工作目录
        # current_path = os.getcwd()         
        # print("当前路径:", current_path)
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
214
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
215
216
217
        configfile = './csst_mci_sim/mci_data/mci_all_9K.config'      
        sourcein = 'FLAT'
        print(configfile)
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
218
                
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
219
        debug=True
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
220
                
Yan Zhaojun's avatar
test    
Yan Zhaojun committed
221
222
223
        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
224
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
225
226
227
228
        self.assertEqual(
            1 , 1,
            "case 5: FLAT sim passes.",
        )
Yan Zhaojun's avatar
update  
Yan Zhaojun committed
229
230
        
        
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
231
# ############################################################################
Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
232

Yan Zhaojun's avatar
update  
Yan Zhaojun committed
233

Yan Zhaojun's avatar
debug    
Yan Zhaojun committed
234