Commit d0134717 authored by GZhao's avatar GZhao
Browse files

update unit test case

parent 05c74432
Pipeline #4519 passed with stage
in 0 seconds
...@@ -61,8 +61,8 @@ class TestEMCCD(unittest.TestCase): ...@@ -61,8 +61,8 @@ class TestEMCCD(unittest.TestCase):
self.assertAlmostEqual(emgain, 1.23, places=2) self.assertAlmostEqual(emgain, 1.23, places=2)
if __name__ == '__main__': # if __name__ == '__main__':
unittest.main() # unittest.main()
# from CpicImgSim.camera import CPIC_VIS_EMCCD # from CpicImgSim.camera import CPIC_VIS_EMCCD
# emccd = CPIC_VIS_EMCCD() # emccd = CPIC_VIS_EMCCD()
# emccd.emgain_fun(1023, -30) # emccd.emgain_fun(1023, -30)
......
...@@ -46,15 +46,6 @@ camera = CpicVisEmccd() ...@@ -46,15 +46,6 @@ camera = CpicVisEmccd()
import logging import logging
class TestIO(unittest.TestCase): 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): def test_obsid_parser(self):
self.assertRaises(ValueError, obsid_parser, '20190101') self.assertRaises(ValueError, obsid_parser, '20190101')
...@@ -88,6 +79,14 @@ class TestIO(unittest.TestCase): ...@@ -88,6 +79,14 @@ class TestIO(unittest.TestCase):
@mock.patch("os.makedirs") @mock.patch("os.makedirs")
@mock.patch("astropy.io.fits.writeto") @mock.patch("astropy.io.fits.writeto")
def test_write_fits(self, patch_fits, patch_mkdir): 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)) images = np.zeros((5, 10, 10))
yaml_str = """ yaml_str = """
obsid: 42012345678 obsid: 42012345678
...@@ -115,7 +114,11 @@ target: ...@@ -115,7 +114,11 @@ target:
parameters = yaml.load(yaml_str, Loader=yaml.FullLoader) parameters = yaml.load(yaml_str, Loader=yaml.FullLoader)
tmp_folder_path = 'test_folder_for_unit_test' tmp_folder_path = 'test_folder_for_unit_test'
io.save_fits_simple(images, parameters, output_folder=tmp_folder_path) 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] output_name = patch_fits.call_args[0][0]
self.assertEqual( self.assertEqual(
output_name[:len(tmp_folder_path)], tmp_folder_path) output_name[:len(tmp_folder_path)], tmp_folder_path)
......
...@@ -54,8 +54,8 @@ class TestOptics(unittest.TestCase): ...@@ -54,8 +54,8 @@ class TestOptics(unittest.TestCase):
self.assertIsInstance(bandpass, S.spectrum.SpectralElement) self.assertIsInstance(bandpass, S.spectrum.SpectralElement)
def test_which_focalpalne(self): # def test_which_focalpalne(self):
self.assertEqual(which_focalplane('f565'), 'vis') # self.assertEqual(which_focalplane('f565'), 'vis')
def test_ideal_focus_image(self): def test_ideal_focus_image(self):
targets = [ targets = [
......
...@@ -44,24 +44,19 @@ class TestTarget(unittest.TestCase): ...@@ -44,24 +44,19 @@ class TestTarget(unittest.TestCase):
self.assertEqual(old_planet.sp_model, 'bcc_planet') self.assertEqual(old_planet.sp_model, 'bcc_planet')
def test_bcc_class(self): def test_bcc_albedo_spectrum(self):
spectrum = AlbedoCat(90, 1, 0) spectrum = AlbedoCat(90, 1, 0)
self.assertIsInstance(spectrum, S.spectrum.SpectralElement) 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) spectrum = bcc_spectrum(0.5, 0.5)
self.assertIsInstance(spectrum, S.spectrum.SpectralElement) self.assertIsInstance(spectrum, S.spectrum.SpectralElement)
self.assertEqual(spectrum.waveunits.name, 'angstrom') self.assertEqual(spectrum.waveunits.name, 'angstrom')
# import matplotlib.pyplot as plt # import matplotlib.pyplot as plt
# plt.plot(spectrum.wave, spectrum.throughput) # plt.plot(spectrum.wave, spectrum.throughput)
# plt.xlabel(spectrum.waveunits)
# plt.show() # plt.show()
def test_hybrid_albedo_spectrum(self): def test_hybrid_albedo_spectrum(self):
planet = hybrid_albedo_spectrum(0.5, 1) planet = hybrid_albedo_spectrum(0.5, 1)
self.assertIsInstance(planet, S.spectrum.SpectralElement) self.assertIsInstance(planet, S.spectrum.SpectralElement)
...@@ -144,7 +139,7 @@ class TestTarget(unittest.TestCase): ...@@ -144,7 +139,7 @@ class TestTarget(unittest.TestCase):
self.assertRaises(FileExistsError, detect_template_path, 'demo_5_35.yaml') self.assertRaises(FileExistsError, detect_template_path, 'demo_5_35.yaml')
def test_template_file_load(self): def test_target_file_load(self):
t0 = target_file_load({0:0}) t0 = target_file_load({0:0})
self.assertEqual(t0[0], 0) self.assertEqual(t0[0], 0)
...@@ -228,9 +223,3 @@ class TestTarget(unittest.TestCase): ...@@ -228,9 +223,3 @@ class TestTarget(unittest.TestCase):
spectrums = spectrum_generator(template_star) spectrums = spectrum_generator(template_star)
self.assertEqual(len(spectrums), 1) self.assertEqual(len(spectrums), 1)
if __name__ == '__main__':
unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment