Coverage for transientNamer/tests/test_cl_utils.py : 35%

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 yaml
7from transientNamer.utKit import utKit
8from fundamentals import tools
9from os.path import expanduser
10from docopt import docopt
11from transientNamer import cl_utils
12doc = cl_utils.__doc__
13home = expanduser("~")
15packageDirectory = utKit("").get_project_root()
16settingsFile = packageDirectory + "/test_settings.yaml"
18su = tools(
19 arguments={"settingsFile": settingsFile},
20 docString=__doc__,
21 logLevel="DEBUG",
22 options_first=False,
23 projectName=None,
24 defaultSettingsFile=False
25)
26arguments, settings, log, dbConn = su.setup()
28# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA
29moduleDirectory = os.path.dirname(__file__)
30pathToInputDir = moduleDirectory + "/input/"
31pathToOutputDir = moduleDirectory + "/output/"
33try:
34 shutil.rmtree(pathToOutputDir)
35except:
36 pass
37# COPY INPUT TO OUTPUT DIR
38shutil.copytree(pathToInputDir, pathToOutputDir)
40# Recursively create missing directories
41if not os.path.exists(pathToOutputDir):
42 os.makedirs(pathToOutputDir)
44# transientNamer [-c] cone <ra> <dec> <arcsecRadius> [<render> | mysql <tableNamePrefix>] [-o directory]
45# transientNamer [-c] search <name> [<render> | mysql <tableNamePrefix>] [-o directory]
46# transientNamer [-c] new <discInLastDays> [<render> | mysql
47# <tableNamePrefix>] [-o directory]
50class test_cl_utils(unittest.TestCase):
52 def test_cone_search(self):
53 # TEST CL-OPTIONS
54 command = f"transientNamer cone 06:45:03.36 +35:44:29.8 5. -s {settingsFile}"
55 args = docopt(doc, command.split(" ")[1:])
56 cl_utils.main(args)
57 return
59 def test_cone_search_comments(self):
60 # TEST CL-OPTIONS
61 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5."
62 args = docopt(doc, command.split(" ")[1:])
63 cl_utils.main(args)
64 return
66 def test_cone_search_render(self):
67 # TEST CL-OPTIONS
68 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5. json"
69 args = docopt(doc, command.split(" ")[1:])
70 cl_utils.main(args)
72 # TEST CL-OPTIONS
73 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5. csv"
74 args = docopt(doc, command.split(" ")[1:])
75 cl_utils.main(args)
77 # TEST CL-OPTIONS
78 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5. table"
79 args = docopt(doc, command.split(" ")[1:])
80 cl_utils.main(args)
82 # TEST CL-OPTIONS
83 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5. markdown"
84 args = docopt(doc, command.split(" ")[1:])
85 cl_utils.main(args)
87 # TEST CL-OPTIONS
88 command = "transientNamer -c cone 06:45:03.36 +35:44:29.8 5. yaml"
89 args = docopt(doc, command.split(" ")[1:])
90 cl_utils.main(args)
91 return
93 def test_cone_search_mysql(self):
94 # TEST CL-OPTIONS
95 command = "transientNamer cone 06:45:03.36 +35:44:29.8 5. mysql test_table"
96 args = docopt(doc, command.split(" ")[1:])
97 cl_utils.main(args)
98 return
100 def test_cone_search_mysql_to_file(self):
101 # TEST CL-OPTIONS
102 thisDir = pathToOutputDir
103 command = "transientNamer cone 06:45:03.36 +35:44:29.8 5. mysql test_table -o %(thisDir)s/cl_output/" % locals(
104 )
105 args = docopt(doc, command.split(" ")[1:])
106 cl_utils.main(args)
107 return
109 def test_name_search(self):
110 # TEST CL-OPTIONS
111 command = "transientNamer search 2016fbz"
112 args = docopt(doc, command.split(" ")[1:])
113 cl_utils.main(args)
114 return
116 def test_name_search_render(self):
117 # TEST CL-OPTIONS
118 command = "transientNamer search 2016fbz json"
119 args = docopt(doc, command.split(" ")[1:])
120 cl_utils.main(args)
122 # TEST CL-OPTIONS
123 command = "transientNamer search 2016fbz json"
124 args = docopt(doc, command.split(" ")[1:])
125 cl_utils.main(args)
127 # TEST CL-OPTIONS
128 command = "transientNamer search 2016fbz csv"
129 args = docopt(doc, command.split(" ")[1:])
130 cl_utils.main(args)
132 # TEST CL-OPTIONS
133 command = "transientNamer search 2016fbz table"
134 args = docopt(doc, command.split(" ")[1:])
135 cl_utils.main(args)
137 # TEST CL-OPTIONS
138 command = "transientNamer search 2016fbz yaml"
139 args = docopt(doc, command.split(" ")[1:])
140 cl_utils.main(args)
142 # TEST CL-OPTIONS
143 command = "transientNamer search 2016fbz markdown"
144 args = docopt(doc, command.split(" ")[1:])
145 cl_utils.main(args)
146 return
148 def test_name_search_mysql(self):
149 # TEST CL-OPTIONS
150 command = "transientNamer search 2016fbz mysql test_search"
151 args = docopt(doc, command.split(" ")[1:])
152 cl_utils.main(args)
154 def test_name_search_output_to_file(self):
155 # TEST CL-OPTIONS
156 thisDir = pathToOutputDir
157 command = "transientNamer search 2016fbz markdown -o %(thisDir)s/cl_output" % locals(
158 )
159 args = docopt(doc, command.split(" ")[1:])
160 cl_utils.main(args)
162 def test_name_new(self):
163 # TEST CL-OPTIONS
164 thisDir = pathToOutputDir
165 command = "transientNamer new 2 markdown -o %(thisDir)s/cl_output" % locals(
166 )
167 args = docopt(doc, command.split(" ")[1:])
168 cl_utils.main(args)
170 def test_name_new_render(self):
171 # TEST CL-OPTIONS
172 thisDir = pathToOutputDir
173 command = "transientNamer new 2 markdown -o %(thisDir)s/cl_output" % locals(
174 )
175 args = docopt(doc, command.split(" ")[1:])
176 cl_utils.main(args)
178 def test_name_new_mysql(self):
179 # TEST CL-OPTIONS
180 thisDir = pathToOutputDir
181 command = "transientNamer new 2 mysql test_new" % locals(
182 )
183 args = docopt(doc, command.split(" ")[1:])
184 cl_utils.main(args)
186 def test_name_new_to_file(self):
187 # TEST CL-OPTIONS
188 thisDir = pathToOutputDir
189 command = "transientNamer new 2 markdown -o %(thisDir)s/cl_output" % locals(
190 )
191 args = docopt(doc, command.split(" ")[1:])
192 cl_utils.main(args)
194 # x-class-to-test-named-worker-function