Newer
Older
# from CpicImgSim import observation_simulation, quick_run
from csst_cpic_sim.main import main, quick_run_v2, observation_simulation_from_config
from csst_cpic_sim.config import config
import os
test_dir = os.path.dirname(__file__)
cases = os.path.join(test_dir, 'testcases')
output = os.path.join(test_dir, 'test_output')
config['output'] = output
from unittest.mock import patch
# def test_help(self):
# main(argv = None)
def test_quick_run_cmdline(self):
clear_output()
main([
'quickrun',
'demo_0_20',
'0', '700', '1',
'-r', '30',
'-s', '19',
'-ec',
'-o', output
])
file = os.listdir(output)
self.assertEqual(len(file), 1)
self.assertEqual(file[0][:9], 'demo_0_20')
def test_quick_run_func(self):
clear_output()
quick_run_v2(
'', 'f661', 0, 20, 1, skybg=None, camera_effect=False, output=output
file = os.listdir(output)
self.assertEqual(len(file), 1)
self.assertEqual(file[0][:5], 'blank')
def test_full_run_func(self):
clear_output()
with open(cases+'/run_config.yaml', 'r') as fid:
text = fid.read()
text = text.replace('<output>', output)
with open(output+'/run_config_new.yaml', 'w') as fid:
fid.write(text)
observation_simulation_from_config(
os.path.join(cases, '05_sci.yaml'),
os.path.join(output, 'run_config_new.yaml')
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
file = os.listdir(output)
self.assertEqual(len(file), 4)
clear_output()
observation_simulation_from_config(
os.path.join(cases, '05_sci.yaml'),
None
)
file = os.listdir(output)
self.assertEqual(len(file), 1)
self.assertEqual(file[0][:5], 'SCI')
def test_full_run_cmdline(self):
clear_output()
main(['run', os.path.join(cases, '05_sci.yaml')])
file = os.listdir(output)
self.assertEqual(len(file), 1)
self.assertEqual(file[0][:5], 'SCI')
# def test_main(self):
# target_example = {
# 'name': 'test',
# 'cstar': {
# 'magnitude': 0,
# 'ra': '120d',
# 'dec': '40d',
# 'distance': 10,
# 'sptype': 'F0III',
# },
# }
# quick_run('', 10, 'f661', 1, 1, 30)
# quick_run('*2.4/10(3,5)/15(-4,2)', 21, 'f661', 1, 1, 30)
# # normal target
# observation_simulation(
# target=target_example,
# skybg=21,
# expt=1,
# nframe=1,
# band='f661',
# emgain=30,
# obsid=51012345678,
# )
# # bias-gain
# observation_simulation(
# target={},
# skybg=None,
# expt=1,
# nframe=1,
# band='f661',
# emgain=30,
# obsid=50112345678,
# )