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

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

## 101 statements 90 run 11 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"] + "/xshooter-bias/uvb/1x1"

50

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 )

59

60 def test_mbias_from_sof_function(self):

61 sofPath = "~/xshooter-pipeline-data/raw_data/xshooter-bias/sof/bias_uvb_1x1.sof"

62

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 )

71

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)

79

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)

85

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 )

94

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)

102

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)

108

109 from soxspipe.recipes import mbias

110 this = mbias(

111 log=log,

112 settings=settings,

113 inputFrames=fileList

114 )

115 this.produce_product()

116

117 def test_mbias_mixed_image_type_exception(self):

118

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

132

133 def test_mbias_wrong_image_type_exception(self):

134

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

148

149 def test_mbias_mixed_binning_exception(self):

150

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

164

165 def test_mbias_function_exception(self):

166

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

179

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

181

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