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

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("", dbConn=False).get_project_root()
14settingsFile = packageDirectory + "/test_settings.yaml"
15# settingsFile = home + "/.config/soxspipe/soxspipe.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_set_of_files(unittest.TestCase):
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")
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())
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")
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)
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")
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)
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)
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)
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)
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)
129 print("sof file written to %(sofPath)s" % locals())
131 def test_set_of_files_function_exception(self):
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))
146 # x-print-testpage-for-pessto-marshall-web-object
148 # x-class-to-test-named-worker-function