Coverage for soxspipe/recipes/tests/test_soxs_mbias.py : 88%

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
11home = expanduser("~")
13packageDirectory = utKit("").get_project_root()
14settingsFile = packageDirectory + "/test_settings.yaml"
15# settingsFile = home + "/.config/soxspipe.recipes/soxspipe.recipes.yaml"
16su = tools(
17 arguments={"settingsFile": settingsFile},
18 docString=__doc__,
19 logLevel="DEBUG",
20 options_first=False,
21 projectName=None,
22 defaultSettingsFile=False
23)
24arguments, settings, log, dbConn = su.setup()
26# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE
27moduleDirectory = os.path.dirname(__file__)
28utKit = utKit(moduleDirectory)
29log, dbConn, pathToInputDir, pathToOutputDir = utKit.setupModule()
30utKit.tearDownModule()
32try:
33 shutil.rmtree(pathToOutputDir)
34except:
35 pass
36# COPY INPUT TO OUTPUT DIR
37shutil.copytree(pathToInputDir, pathToOutputDir)
39# Recursively create missing directories
40if not os.path.exists(pathToOutputDir):
41 os.makedirs(pathToOutputDir)
43# xt-setup-unit-testing-files-and-folders
46class test_mbias(unittest.TestCase):
48 def test_mbias_from_directory_function(self):
49 directory = settings["test-data-root"] + \
50 "/xshooter-mbias/uvb/1x1/fast_read"
52 from soxspipe.recipes import soxs_mbias
53 this = soxs_mbias(
54 log=log,
55 settings=settings,
56 inputFrames=directory
57 )
58 productPath = this.produce_product()
59 print(f"Here is the final product `{productPath}`")
61 def test_mbias_from_sof_function(self):
62 sofPath = "~/xshooter-pipeline-data/unittest_data/xsh/xshooter-mbias/sof/bias_uvb_1x1.sof"
64 # utKit.refresh_database() # reset database to database found in
65 # soxspipe.recipes/test/input
66 from soxspipe.recipes import soxs_mbias
67 this = soxs_mbias(
68 log=log,
69 settings=settings,
70 inputFrames=sofPath
71 )
72 productPath = this.produce_product()
73 print(f"Here is the final product `{productPath}`")
75 def test_mbias_from_list_of_fits_function(self):
76 directory = settings["test-data-root"] + \
77 "/xshooter-mbias/uvb/1x1/slow_read"
78 # MAKE RELATIVE HOME PATH ABSOLUTE
79 from os.path import expanduser
80 home = expanduser("~")
81 if directory[0] == "~":
82 directory = directory.replace("~", home)
84 fileList = []
85 for d in os.listdir(directory):
86 filename = os.path.join(directory, d)
87 if os.path.isfile(filename) and ".fits" in d:
88 fileList.append(filename)
90 # utKit.refresh_database() # reset database to database found in
91 # soxspipe.recipes/test/input
92 from soxspipe.recipes import soxs_mbias
93 this = soxs_mbias(
94 log=log,
95 settings=settings,
96 inputFrames=fileList
97 )
98 productPath = this.produce_product()
99 print(f"Here is the final product `{productPath}`")
101 def test_produce_product_function(self):
102 directory = settings["test-data-root"] + \
103 "/xshooter-mbias/uvb/1x1/fast_read"
104 # MAKE RELATIVE HOME PATH ABSOLUTE
105 from os.path import expanduser
106 home = expanduser("~")
107 if directory[0] == "~":
108 directory = directory.replace("~", home)
110 fileList = []
111 for d in os.listdir(directory):
112 filename = os.path.join(directory, d)
113 if os.path.isfile(filename) and ".fits" in d:
114 fileList.append(filename)
116 from soxspipe.recipes import soxs_mbias
117 this = soxs_mbias(
118 log=log,
119 settings=settings,
120 inputFrames=fileList
121 )
122 productPath = this.produce_product()
123 print(f"Here is the final product `{productPath}`")
125 def test_mbias_mixed_image_type_exception(self):
127 directory = settings["test-data-root"] + "/xshooter-lingain/vis"
128 try:
129 from soxspipe.recipes import soxs_mbias
130 this = soxs_mbias(
131 log=log,
132 settings=settings,
133 inputFrames=directory
134 )
135 this.get()
136 assert False
137 except Exception as e:
138 assert True
139 print(str(e))
141 def test_mbias_wrong_image_type_exception(self):
143 directory = settings["test-data-root"] + "/xshooter-mdark/vis"
144 try:
145 from soxspipe.recipes import soxs_mbias
146 this = soxs_mbias(
147 log=log,
148 settings=settings,
149 inputFrames=directory
150 )
151 this.get()
152 assert False
153 except Exception as e:
154 assert True
155 print(str(e))
157 def test_mbias_mixed_binning_exception(self):
159 directory = settings["test-data-root"] + "/xshooter-mbias/vis"
160 try:
161 from soxspipe.recipes import soxs_mbias
162 this = soxs_mbias(
163 log=log,
164 settings=settings,
165 inputFrames=directory
166 )
167 this.get()
168 assert False
169 except Exception as e:
170 assert True
171 print(str(e))
173 def test_mbias_function_exception(self):
175 from soxspipe.recipes import soxs_mbias
176 try:
177 this = soxs_mbias(
178 log=log,
179 settings=settings,
180 fakeKey="break the code"
181 )
182 this.get()
183 assert False
184 except Exception as e:
185 assert True
186 print(str(e))
188 # x-print-testpage-for-pessto-marshall-web-object
190 # x-class-to-test-named-worker-function