test_data_manager.py 2.21 KB
Newer Older
BO ZHANG's avatar
BO ZHANG committed
1
2
3
4
5
6
7
8
"""
Identifier:     KSC-SJ4-tests/test_data_manager.py
Name:           test_data_manager.py
Description:    data manager unit test
Author:         Bo Zhang
Created:        2022-09-13
Modified-History:
    2022-09-13, Bo Zhang, created
9
    2022-09-29, Bo Zhang, added test for CsstMbiDataManager
10
    2022-10-28, Bo Zhang, deleted unit test for CsstMsDataManager
BO ZHANG's avatar
BO ZHANG committed
11
"""
12
import os
BO ZHANG's avatar
BO ZHANG committed
13
import unittest
BO ZHANG's avatar
tweaks    
BO ZHANG committed
14

15
from csst_common.data_manager import CsstMsDataManager
16
from csst_common.params import CSST_PARAMS as CP
BO ZHANG's avatar
tweaks    
BO ZHANG committed
17

BO ZHANG's avatar
BO ZHANG committed
18
dir_unittest = "/nfsdata/share/pipeline-unittest/csst_common"
BO ZHANG's avatar
BO ZHANG committed
19

BO ZHANG's avatar
BO ZHANG committed
20

BO ZHANG's avatar
BO ZHANG committed
21
22
class TestCsstMsDataManager(unittest.TestCase):
    def setUp(self) -> None:
23
        self.dm_mbi = CsstMsDataManager.quickstart(
BO ZHANG's avatar
BO ZHANG committed
24
            ver_sim="C6.2", datatype="mbi", dir_l1=dir_unittest, exposure_id=100)
25
        self.dm_sls = CsstMsDataManager.quickstart(
BO ZHANG's avatar
BO ZHANG committed
26
            ver_sim="C6.2", datatype="sls", dir_l1=dir_unittest, exposure_id=100)
27
28
        self.dm_mbi.target_detectors = None
        self.dm_sls.target_detectors = None
BO ZHANG's avatar
BO ZHANG committed
29
30

    def test_mbi_data_existence(self):
BO ZHANG's avatar
BO ZHANG committed
31
        self.assertTrue(self.dm_mbi.target_detectors == CP["mbi"]["detectors"])
BO ZHANG's avatar
BO ZHANG committed
32
33
34
35
36
37
38
39
        self.assertTrue(os.path.exists(self.dm_mbi.l0_detector(6)))
        self.assertTrue(os.path.exists(self.dm_mbi.l0_log(6)))
        self.assertTrue(os.path.exists(self.dm_mbi.l0_cat(6)))
        self.assertTrue(os.path.exists(self.dm_mbi.l0_crs(6)))
        self.assertTrue(isinstance(self.dm_mbi.l1_detector(6, post="img.fits"), str))
        self.assertTrue(isinstance(self.dm_mbi.l1_file(name="some_file.ext", comment="a demo file"), str))

    def test_sls_data_existence(self):
BO ZHANG's avatar
BO ZHANG committed
40
        self.assertTrue(self.dm_sls.target_detectors == CP["sls"]["detectors"])
BO ZHANG's avatar
tweaks    
BO ZHANG committed
41
42
43
44
45
        self.assertTrue(os.path.exists(self.dm_sls.l0_detector(1)))
        self.assertTrue(os.path.exists(self.dm_sls.l0_log(1)))
        self.assertTrue(os.path.exists(self.dm_sls.l0_cat(1)))
        self.assertTrue(os.path.exists(self.dm_sls.l0_crs(1)))
        self.assertTrue(isinstance(self.dm_sls.l1_detector(1, post="flt.fits"), str))
BO ZHANG's avatar
BO ZHANG committed
46
        self.assertTrue(isinstance(self.dm_sls.l1_file(name="some_file.ext", comment="a demo file"), str))
BO ZHANG's avatar
tweaks    
BO ZHANG committed
47

BO ZHANG's avatar
BO ZHANG committed
48
49
50
    # DFS is not always available
    # def test_dfs_is_available(self):
    #     self.assertTrue(self.dm_mbi.dfs_is_available())