Coverage for soxspipe/commonutils/tests/test_sof_of_files.py: 0%

# Coverage for soxspipe/commonutils/tests/test_sof_of_files.py : 0%

## 83 statements 0 run 83 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("", dbConn=False).get_project_root()

14 settingsFile = packageDirectory + "/test_settings.yaml"

15# settingsFile = home + "/.config/soxspipe/soxspipe.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_set_of_files(unittest.TestCase):

47

48 def test01_set_of_files_function(self):

49 directory = settings["test-data-root"] + "/xshooter-mbias/vis"

50 other_output = settings[

51 "reduced-data-root"].replace("reduced", "other_output")

52

53 sofPath = other_output + "/test.sof"

54 from soxspipe.commonutils import set_of_files

55 sof = set_of_files(

56 log=log,

57 settings=settings

58 )

59 sofFile = sof._generate_sof_file_from_directory(

60 directory=directory, sofPath=sofPath)

61 print("sof file written to %(sofPath)s" % locals())

62

63 def test_sof_to_collection_from_directory_function(self):

64 directory = settings["test-data-root"] + "/xshooter-mbias/vis"

65 other_output = settings[

66 "reduced-data-root"].replace("reduced", "other_output")

67

68 sofPath = other_output + "/test.sof"

69 from soxspipe.commonutils import set_of_files

70 sof = set_of_files(

71 log=log,

72 settings=settings,

73 inputFrames=directory

74 )

75 sofFile, supplementaryInput = sof.get()

76 print(sofFile.summary)

77

78 def test_sof_to_collection_from_sof_file_function(self):

79 directory = settings["test-data-root"] + "/xshooter-mbias/vis"

80 other_output = settings[

81 "reduced-data-root"].replace("reduced", "other_output")

82

83 sofPath = other_output + "/test.sof"

84 from soxspipe.commonutils import set_of_files

85 sof = set_of_files(

86 log=log,

87 settings=settings,

88 inputFrames=sofPath

89 )

90 sofFile, supplementaryInput = sof.get()

91 print(sofFile.summary)

92

93 def test_sof_to_collection_from_list_of_fits_files_function(self):

94 directory = settings["test-data-root"] + "/xshooter-mbias/vis"

95 # MAKE RELATIVE HOME PATH ABSOLUTE

96 from os.path import expanduser

97 home = expanduser("~")

98 if directory[0] == "~":

99 directory = directory.replace("~", home)

100

101 fileList = []

102 for d in os.listdir(directory):

103 filename = os.path.join(directory, d)

104 if os.path.isfile(filename) and ".fits" in d:

105 fileList.append(filename)

106

107 from soxspipe.commonutils import set_of_files

108 sof = set_of_files(

109 log=log,

110 settings=settings,

111 inputFrames=fileList

112 )

113 sofFile, supplementaryInput = sof.get()

114 print(sofFile.summary)

115

116 def test_validate_sof_frames_function(self):

117 directory = settings["test-data-root"] + "/xshooter-mbias/vis"

118 other_output = settings[

119 "reduced-data-root"].replace("reduced", "other_output")

120 sofPath = other_output + "/test.sof"

121 from soxspipe.commonutils import set_of_files

122 sof = set_of_files(

123 log=log,

124 settings=settings

125 )

126 sofFile = sof._generate_sof_file_from_directory(

127 directory=directory, sofPath=sofPath)

128

129 print("sof file written to %(sofPath)s" % locals())

130

131 def test_set_of_files_function_exception(self):

132

133 from soxspipe.commonutils import set_of_files

134 try:

135 this = set_of_files(

136 log=log,

137 settings=settings,

138 fakeKey="break the code"

139 )

140 this.get()

141 assert False

142 except Exception as e:

143 assert True

144 print(str(e))

145

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

147

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