Coverage for HMpTy/htm/tests/test_sets.py : 86%

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 HMpTy.utKit import utKit
8from fundamentals import tools
9from os.path import expanduser
10from past.utils import old_div
11home = expanduser("~")
13packageDirectory = utKit("").get_project_root()
14settingsFile = packageDirectory + "/test_settings.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 PATHS TO COMMON DIRECTORIES FOR TEST DATA
27moduleDirectory = os.path.dirname(__file__)
28pathToInputDir = moduleDirectory + "/input/"
29pathToOutputDir = moduleDirectory + "/output/"
31try:
32 shutil.rmtree(pathToOutputDir)
33except:
34 pass
35# COPY INPUT TO OUTPUT DIR
36shutil.copytree(pathToInputDir, pathToOutputDir)
38# Recursively create missing directories
39if not os.path.exists(pathToOutputDir):
40 os.makedirs(pathToOutputDir)
42import codecs
43pathToReadFile = pathToInputDir + "test-data-for-sets.csv"
44try:
45 log.debug("attempting to open the file %s" % (pathToReadFile,))
46 readFile = codecs.open(pathToReadFile, encoding='utf-8', mode='r')
47 thisData = readFile.read().split("\n")
48 readFile.close()
49except IOError as e:
50 message = 'could not open the file %s' % (pathToReadFile,)
51 log.critical(message)
52 raise IOError(message)
54transientList = []
55raList = []
56decList = []
57for l in thisData[1:]:
58 l = l.split(",")
59 if len(l) == 3:
60 transientList.append(l)
61 raList.append(l[1])
62 decList.append(l[2])
64class test_sets(unittest.TestCase):
66 def test_sets_all_extract_function(self):
68 from HMpTy.htm import sets
69 xmatcher = sets(
70 log=log,
71 ra=raList,
72 dec=decList,
73 radius=old_div(10, (60. * 60.)),
74 sourceList=transientList
75 )
76 allMatches = xmatcher._extract_all_sets_from_list()
77 for i, m in enumerate(allMatches):
78 pass
79 #print(i, m)
81 def test_sets_match_function(self):
83 from HMpTy.htm import sets
84 xmatcher = sets(
85 log=log,
86 ra=raList,
87 dec=decList,
88 radius=old_div(10, (60. * 60.)),
89 sourceList=transientList
90 )
91 allMatches = xmatcher.match
93 def test_sets_function_exception(self):
95 from HMpTy.htm import sets
96 try:
97 this = sets(
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