Coverage for soxspipe/commonutils/tests/test_sof_util.py : 92%

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_sof_util(unittest.TestCase):
48 def test01_sof_util_function(self):
49 directory = settings["test-data-root"] + "/xshooter-bias/vis"
50 other_output = settings[
51 "reduced-data-root"].replace("reduced", "other_output")
53 sofPath = other_output + "/test.sof"
54 from soxspipe.commonutils import sof_util
55 sof = sof_util(
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_function(self):
64 directory = settings["test-data-root"] + "/xshooter-bias/vis"
65 other_output = settings[
66 "reduced-data-root"].replace("reduced", "other_output")
68 sofPath = other_output + "/test.sof"
69 from soxspipe.commonutils import sof_util
70 sof = sof_util(
71 log=log,
72 settings=settings
73 )
74 sofFile = sof.generate_sof_file_from_directory(
75 directory=directory, sofPath=sofPath)
76 print("sof file written to %(sofPath)s" % locals())
78 def test_validate_sof_frames_function(self):
79 directory = settings["test-data-root"] + "/xshooter-bias/vis"
80 other_output = settings[
81 "reduced-data-root"].replace("reduced", "other_output")
82 sofPath = other_output + "/test.sof"
83 from soxspipe.commonutils import sof_util
84 sof = sof_util(
85 log=log,
86 settings=settings
87 )
88 sofFile = sof.generate_sof_file_from_directory(
89 directory=directory, sofPath=sofPath)
91 print("sof file written to %(sofPath)s" % locals())
93 def test_sof_util_function_exception(self):
95 from soxspipe.commonutils import sof_util
96 try:
97 this = sof_util(
98 log=log,
99 settings=settings,
100 fakeKey="break the code"
101 )
102 this.get()
103 assert False
104 except Exception as e:
105 assert True
106 print(str(e))
108 # x-print-testpage-for-pessto-marshall-web-object
110 # x-class-to-test-named-worker-function