Coverage for soxspipe/commonutils/tests/test_create_dispersion_map.py : 95%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import print_function
2from builtins import str
3import os
4import unittest
5import shutil
6import unittest
7import yaml
8from soxspipe.utKit import utKit
9from fundamentals import tools
10from os.path import expanduser
11from astropy.nddata import CCDData
12from astropy import units as u
13home = expanduser("~")
15packageDirectory = utKit("").get_project_root()
16settingsFile = packageDirectory + "/test_settings.yaml"
17# settingsFile = home + \
18# "/git_repos/_misc_/settings/soxspipe/test_settings.yaml"
20su = tools(
21 arguments={"settingsFile": settingsFile},
22 docString=__doc__,
23 logLevel="DEBUG",
24 options_first=False,
25 projectName=None,
26 defaultSettingsFile=False
27)
28arguments, settings, log, dbConn = su.setup()
30# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA
31moduleDirectory = os.path.dirname(__file__)
32pathToInputDir = moduleDirectory + "/input/"
33pathToOutputDir = moduleDirectory + "/output/"
35try:
36 shutil.rmtree(pathToOutputDir)
37except:
38 pass
39# COPY INPUT TO OUTPUT DIR
40shutil.copytree(pathToInputDir, pathToOutputDir)
42# Recursively create missing directories
43if not os.path.exists(pathToOutputDir):
44 os.makedirs(pathToOutputDir)
47# xt-setup-unit-testing-files-and-folders
50class test_create_dispersion_map(unittest.TestCase):
52 def test_create_dispersion_map_single_nir_function(self):
53 frame = "~/xshooter-pipeline-data/unittest_data/xsh/create_dispersion_map/single_pinhole_NIR_calibrated.fits"
54 from os.path import expanduser
55 home = expanduser("~")
56 frame = frame.replace("~", home)
57 frame = CCDData.read(frame, hdu=0, unit=u.electron, hdu_uncertainty='ERRS',
58 hdu_mask='QUAL', hdu_flags='FLAGS', key_uncertainty_type='UTYPE')
60 from soxspipe.commonutils import create_dispersion_map
61 mapPath = create_dispersion_map(
62 log=log,
63 settings=settings,
64 pinholeFrame=frame
65 ).get()
66 print(mapPath)
68 def test_create_dispersion_map_multi_nir_function(self):
69 frame = "~/xshooter-pipeline-data/unittest_data/xsh/create_dispersion_map/20170818T173315_NIR_ARC_MULTIPIN.fits"
70 from os.path import expanduser
71 home = expanduser("~")
72 frame = frame.replace("~", home)
73 frame = CCDData.read(frame, hdu=0, unit=u.electron, hdu_uncertainty='ERRS',
74 hdu_mask='QUAL', hdu_flags='FLAGS', key_uncertainty_type='UTYPE')
76 from soxspipe.commonutils import create_dispersion_map
77 mapPath = create_dispersion_map(
78 log=log,
79 settings=settings,
80 pinholeFrame=frame,
81 firstGuessMap="~/xshooter-pipeline-data/unittest_data/xsh/create_dispersion_map/20170820T153602_NIR_DISP_MAP.csv"
82 ).get()
83 print(mapPath)
85 def test_create_dispersion_map_function_exception(self):
87 from soxspipe.commonutils import create_dispersion_map
88 try:
89 this = create_dispersion_map(
90 log=log,
91 settings=settings,
92 fakeKey="break the code"
93 )
94 this.get()
95 assert False
96 except Exception as e:
97 assert True
98 print(str(e))
100 # x-print-testpage-for-pessto-marshall-web-object
102 # x-class-to-test-named-worker-function