Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-sims
csst_cpic_sim
Commits
d0134717
Commit
d0134717
authored
May 13, 2024
by
GZhao
Browse files
update unit test case
parent
05c74432
Pipeline
#4519
passed with stage
in 0 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
tests/test_camera.py
View file @
d0134717
...
...
@@ -61,8 +61,8 @@ class TestEMCCD(unittest.TestCase):
self
.
assertAlmostEqual
(
emgain
,
1.23
,
places
=
2
)
if
__name__
==
'__main__'
:
unittest
.
main
()
#
if __name__ == '__main__':
#
unittest.main()
# from CpicImgSim.camera import CPIC_VIS_EMCCD
# emccd = CPIC_VIS_EMCCD()
# emccd.emgain_fun(1023, -30)
...
...
tests/test_io.py
View file @
d0134717
...
...
@@ -46,15 +46,6 @@ camera = CpicVisEmccd()
import
logging
class
TestIO
(
unittest
.
TestCase
):
@
mock
.
patch
(
"os.makedirs"
)
def
test_set_log
(
self
,
patch
):
log
=
set_up_logger
(
config
[
'log_dir'
])
self
.
assertIsInstance
(
log
,
logging
.
Logger
)
self
.
assertRaises
(
FileNotFoundError
,
set_up_logger
,
'new folder'
)
patch
.
assert_called_once_with
(
'new folder'
)
def
test_obsid_parser
(
self
):
self
.
assertRaises
(
ValueError
,
obsid_parser
,
'20190101'
)
...
...
@@ -88,6 +79,14 @@ class TestIO(unittest.TestCase):
@
mock
.
patch
(
"os.makedirs"
)
@
mock
.
patch
(
"astropy.io.fits.writeto"
)
def
test_write_fits
(
self
,
patch_fits
,
patch_mkdir
):
log
=
set_up_logger
(
config
[
'log_dir'
])
self
.
assertIsInstance
(
log
,
logging
.
Logger
)
self
.
assertRaises
(
FileNotFoundError
,
set_up_logger
,
'new folder'
)
patch_mkdir
.
assert_called_once_with
(
'new folder'
)
images
=
np
.
zeros
((
5
,
10
,
10
))
yaml_str
=
"""
obsid: 42012345678
...
...
@@ -115,7 +114,11 @@ target:
parameters
=
yaml
.
load
(
yaml_str
,
Loader
=
yaml
.
FullLoader
)
tmp_folder_path
=
'test_folder_for_unit_test'
io
.
save_fits_simple
(
images
,
parameters
,
output_folder
=
tmp_folder_path
)
patch_mkdir
.
assert_called_once_with
(
tmp_folder_path
)
# patch_mkdir.assert_called_twice()
dirname
=
patch_mkdir
.
call_args
[
0
][
0
]
self
.
assertEqual
(
dirname
,
tmp_folder_path
)
# patch_mkdir.assert_called_once_with(tmp_folder_path)
output_name
=
patch_fits
.
call_args
[
0
][
0
]
self
.
assertEqual
(
output_name
[:
len
(
tmp_folder_path
)],
tmp_folder_path
)
...
...
tests/test_optics.py
View file @
d0134717
...
...
@@ -54,8 +54,8 @@ class TestOptics(unittest.TestCase):
self
.
assertIsInstance
(
bandpass
,
S
.
spectrum
.
SpectralElement
)
def
test_which_focalpalne
(
self
):
self
.
assertEqual
(
which_focalplane
(
'f565'
),
'vis'
)
#
def test_which_focalpalne(self):
#
self.assertEqual(which_focalplane('f565'), 'vis')
def
test_ideal_focus_image
(
self
):
targets
=
[
...
...
tests/test_target.py
View file @
d0134717
...
...
@@ -44,24 +44,19 @@ class TestTarget(unittest.TestCase):
self
.
assertEqual
(
old_planet
.
sp_model
,
'bcc_planet'
)
def
test_bcc_
class
(
self
):
def
test_bcc_
albedo_spectrum
(
self
):
spectrum
=
AlbedoCat
(
90
,
1
,
0
)
self
.
assertIsInstance
(
spectrum
,
S
.
spectrum
.
SpectralElement
)
# import matplotlib.pyplot as plt
# plt.plot(spectrum.wave, spectrum.throughput)
# plt.show()
def
test_bcc_func
(
self
):
spectrum
=
bcc_spectrum
(
0.5
,
0.5
)
self
.
assertIsInstance
(
spectrum
,
S
.
spectrum
.
SpectralElement
)
self
.
assertEqual
(
spectrum
.
waveunits
.
name
,
'angstrom'
)
# import matplotlib.pyplot as plt
# plt.plot(spectrum.wave, spectrum.throughput)
# plt.xlabel(spectrum.waveunits)
# plt.show()
def
test_hybrid_albedo_spectrum
(
self
):
planet
=
hybrid_albedo_spectrum
(
0.5
,
1
)
self
.
assertIsInstance
(
planet
,
S
.
spectrum
.
SpectralElement
)
...
...
@@ -144,7 +139,7 @@ class TestTarget(unittest.TestCase):
self
.
assertRaises
(
FileExistsError
,
detect_template_path
,
'demo_5_35.yaml'
)
def
test_t
emplate
_file_load
(
self
):
def
test_t
arget
_file_load
(
self
):
t0
=
target_file_load
({
0
:
0
})
self
.
assertEqual
(
t0
[
0
],
0
)
...
...
@@ -228,9 +223,3 @@ class TestTarget(unittest.TestCase):
spectrums
=
spectrum_generator
(
template_star
)
self
.
assertEqual
(
len
(
spectrums
),
1
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment