test_common.py 1.7 KB
Newer Older
Wei Shoulin's avatar
Wei Shoulin committed
1
2
import unittest
import os
Wei Shoulin's avatar
Wei Shoulin committed
3
from csst_dfs_client import download_file, read_file, get_free_header
Wei Shoulin's avatar
Wei Shoulin committed
4
5
6
7
8

class CommonTestCase(unittest.TestCase):
    def setUp(self):
        pass

Wei Shoulin's avatar
plan    
Wei Shoulin committed
9
    def test_download_level0_file(self):
Wei Shoulin's avatar
Wei Shoulin committed
10
        bytes_data = download_file(file_path= "L2/MSC/094/auto/CSST-MSC-L2-MBI-CAT/254/CSST_MSC_MS_SCI_20310423084104_20310423084334_10109400638867_12_L2_V01_CATMIX.fits")
Wei Shoulin's avatar
plan    
Wei Shoulin committed
11
12
13
14
15
        # save the downloaded file to a local directory
        tmp_file_dir = os.environ.get("UNIT_TEST_DATA_ROOT", "/tmp")
        tmp_file_path = os.path.join(tmp_file_dir, "test_downloaded_file.fits")
        if os.path.exists(tmp_file_path):
            os.remove(tmp_file_path)
Wei Shoulin's avatar
Wei Shoulin committed
16

Wei Shoulin's avatar
plan    
Wei Shoulin committed
17
18
        with open(tmp_file_path, "wb") as f:
            f.write(bytes_data)
Wei Shoulin's avatar
Wei Shoulin committed
19
        
Wei Shoulin's avatar
plan    
Wei Shoulin committed
20
21
        assert os.path.exists(tmp_file_path)
        os.remove(tmp_file_path)
Wei Shoulin's avatar
Wei Shoulin committed
22
23

    def test_read_file(self):
Wei Shoulin's avatar
Wei Shoulin committed
24
        bytes_io = read_file(file_path= "L2/MSC/094/auto/CSST-MSC-L2-MBI-CAT/254/CSST_MSC_MS_SCI_20310423084104_20310423084334_10109400638867_12_L2_V01_CATMIX.fits")
Wei Shoulin's avatar
Wei Shoulin committed
25
26
27
28
29
30
31
32
33
34
35
        # save the downloaded file to a local directory
        tmp_file_dir = os.environ.get("UNIT_TEST_DATA_ROOT", "/tmp")
        tmp_file_path = os.path.join(tmp_file_dir, "test_downloaded_file.fits")
        if os.path.exists(tmp_file_path):
            os.remove(tmp_file_path)

        with open(tmp_file_path, "wb") as f:
            f.write(bytes_io.getvalue())
        
        assert os.path.exists(tmp_file_path)
        os.remove(tmp_file_path)
Wei Shoulin's avatar
Wei Shoulin committed
36
37

    def test_get_free_header(self):
Wei Shoulin's avatar
Wei Shoulin committed
38
        header_items = get_free_header(file_path= "L2/MSC/094/auto/CSST-MSC-L2-MBI-CAT/254/CSST_MSC_MS_SCI_20310423084104_20310423084334_10109400638867_12_L2_V01_CATMIX.fits")
Wei Shoulin's avatar
Wei Shoulin committed
39
        print(header_items)     
Wei Shoulin's avatar
Wei Shoulin committed
40