Coverage for soxspipe/recipes/tests/test_mbias.py : 89%

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"] + "/xshooter-bias/uvb/1x1"
51 # utKit.refresh_database() # reset database to database found in
52 # soxspipe.recipes/test/input
53 from soxspipe.recipes import mbias
54 this = mbias(
55 log=log,
56 settings=settings,
57 inputFrames=directory
58 )
60 def test_mbias_from_sof_function(self):
61 sofPath = "~/xshooter-pipeline-data/raw_data/xshooter-bias/sof/bias_uvb_1x1.sof"
63 # utKit.refresh_database() # reset database to database found in
64 # soxspipe.recipes/test/input
65 from soxspipe.recipes import mbias
66 this = mbias(
67 log=log,
68 settings=settings,
69 inputFrames=sofPath
70 )
72 def test_mbias_from_list_of_fits_function(self):
73 directory = settings["test-data-root"] + "/xshooter-bias/uvb/1x1"
74 # MAKE RELATIVE HOME PATH ABSOLUTE
75 from os.path import expanduser
76 home = expanduser("~")
77 if directory[0] == "~":
78 directory = directory.replace("~", home)
80 fileList = []
81 for d in os.listdir(directory):
82 filename = os.path.join(directory, d)
83 if os.path.isfile(filename) and ".fits" in d:
84 fileList.append(filename)
86 # utKit.refresh_database() # reset database to database found in
87 # soxspipe.recipes/test/input
88 from soxspipe.recipes import mbias
89 this = mbias(
90 log=log,
91 settings=settings,
92 inputFrames=fileList
93 )
95 def test_produce_product_function(self):
96 directory = settings["test-data-root"] + "/xshooter-bias/uvb/1x1"
97 # MAKE RELATIVE HOME PATH ABSOLUTE
98 from os.path import expanduser
99 home = expanduser("~")
100 if directory[0] == "~":
101 directory = directory.replace("~", home)
103 fileList = []
104 for d in os.listdir(directory):
105 filename = os.path.join(directory, d)
106 if os.path.isfile(filename) and ".fits" in d:
107 fileList.append(filename)
109 from soxspipe.recipes import mbias
110 this = mbias(
111 log=log,
112 settings=settings,
113 inputFrames=fileList
114 )
115 this.produce_product()
117 def test_mbias_mixed_image_type_exception(self):
119 directory = settings["test-data-root"] + "/xshooter-lingain/vis"
120 try:
121 from soxspipe.recipes import mbias
122 this = mbias(
123 log=log,
124 settings=settings,
125 inputFrames=directory
126 )
127 this.get()
128 assert False
129 except Exception as e:
130 assert True
131 print(str(e))
133 def test_mbias_wrong_image_type_exception(self):
135 directory = settings["test-data-root"] + "/xshooter-darks/vis"
136 try:
137 from soxspipe.recipes import mbias
138 this = mbias(
139 log=log,
140 settings=settings,
141 inputFrames=directory
142 )
143 this.get()
144 assert False
145 except Exception as e:
146 assert True
147 print(str(e))
149 def test_mbias_mixed_binning_exception(self):
151 directory = settings["test-data-root"] + "/xshooter-bias/vis"
152 try:
153 from soxspipe.recipes import mbias
154 this = mbias(
155 log=log,
156 settings=settings,
157 inputFrames=directory
158 )
159 this.get()
160 assert False
161 except Exception as e:
162 assert True
163 print(str(e))
165 def test_mbias_function_exception(self):
167 from soxspipe.recipes import mbias
168 try:
169 this = mbias(
170 log=log,
171 settings=settings,
172 fakeKey="break the code"
173 )
174 this.get()
175 assert False
176 except Exception as e:
177 assert True
178 print(str(e))
180 # x-print-testpage-for-pessto-marshall-web-object
182 # x-class-to-test-named-worker-function