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

# Coverage for soxspipe/recipes/tests/test_soxs_mbias.py : 0%

## 108 statements 0 run 108 missing 0 excluded

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

1 from __future__ import print_function

2 from builtins import str

3 import os

4 import unittest

5 import shutil

6 import unittest

7 import yaml

8 from soxspipe.utKit import utKit

9 from fundamentals import tools

10 from os.path import expanduser

11 home = expanduser("~")

12

13 packageDirectory = utKit("").get_project_root()

14 settingsFile = packageDirectory + "/test_settings.yaml"

15# settingsFile = home + "/.config/soxspipe.recipes/soxspipe.recipes.yaml"

16 su = tools(

17 arguments={"settingsFile": settingsFile},

18 docString=__doc__,

19 logLevel="DEBUG",

20 options_first=False,

21 projectName=None,

22 defaultSettingsFile=False

23)

24 arguments, settings, log, dbConn = su.setup()

25

26# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE

27 moduleDirectory = os.path.dirname(__file__)

28 utKit = utKit(moduleDirectory)

29 log, dbConn, pathToInputDir, pathToOutputDir = utKit.setupModule()

30 utKit.tearDownModule()

31

32 try:

33 shutil.rmtree(pathToOutputDir)

34 except:

35 pass

36# COPY INPUT TO OUTPUT DIR

37 shutil.copytree(pathToInputDir, pathToOutputDir)

38

39# Recursively create missing directories

40 if not os.path.exists(pathToOutputDir):

41 os.makedirs(pathToOutputDir)

42

43# xt-setup-unit-testing-files-and-folders

44

45

46 class test_mbias(unittest.TestCase):

47

48 def test_mbias_from_directory_function(self):

49 directory = settings["test-data-root"] + \

50 "/xshooter-mbias/uvb/1x1/fast_read"

51

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}`")

60

61 def test_mbias_from_sof_function(self):

62 sofPath = "~/xshooter-pipeline-data/unittest_data/xshooter-mbias/sof/bias_uvb_1x1.sof"

63

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}`")

74

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)

83

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)

89

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}`")

100

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)

109

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)

115

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}`")

124

125 def test_mbias_mixed_image_type_exception(self):

126

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))

140

141 def test_mbias_wrong_image_type_exception(self):

142

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))

156

157 def test_mbias_mixed_binning_exception(self):

158

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))

172

173 def test_mbias_function_exception(self):

174

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))

187

188 # x-print-testpage-for-pessto-marshall-web-object

189

190 # x-class-to-test-named-worker-function