Hide keyboard shortcuts

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 sherlock.utKit import utKit 

8from fundamentals import tools 

9from os.path import expanduser 

10home = expanduser("~") 

11 

12packageDirectory = utKit("").get_project_root() 

13settingsFile = packageDirectory + "/test_settings.yaml" 

14 

15su = tools( 

16 arguments={"settingsFile": settingsFile}, 

17 docString=__doc__, 

18 logLevel="DEBUG", 

19 options_first=False, 

20 projectName=None, 

21 defaultSettingsFile=False 

22) 

23arguments, settings, log, dbConn = su.setup() 

24 

25# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

26moduleDirectory = os.path.dirname(__file__) 

27pathToInputDir = moduleDirectory + "/input/" 

28pathToOutputDir = moduleDirectory + "/output/" 

29 

30try: 

31 shutil.rmtree(pathToOutputDir) 

32except: 

33 pass 

34# COPY INPUT TO OUTPUT DIR 

35shutil.copytree(pathToInputDir, pathToOutputDir) 

36 

37# Recursively create missing directories 

38if not os.path.exists(pathToOutputDir): 

39 os.makedirs(pathToOutputDir) 

40 

41# SETUP ALL DATABASE CONNECTIONS 

42from sherlock import database 

43db = database( 

44 log=log, 

45 settings=settings 

46) 

47dbConns, dbVersions = db.connect() 

48transientsDbConn = dbConns["transients"] 

49cataloguesDbConn = dbConns["catalogues"] 

50 

51try: 

52 from fundamentals.mysql import writequery 

53 sqlQuery = """drop table IF EXISTS tcs_cat_ned_stream;""" % locals() 

54 writequery( 

55 log=log, 

56 sqlQuery=sqlQuery, 

57 dbConn=cataloguesDbConn 

58 ) 

59except: 

60 pass 

61 

62 

63class test_ned(unittest.TestCase): 

64 

65 def test_ned_function(self): 

66 coordinateList = ["23.2323 -43.23434"] 

67 from sherlock.imports import ned 

68 catalogue = ned( 

69 log=log, 

70 settings=settings, 

71 coordinateList=coordinateList, 

72 radiusArcsec=30 

73 ) 

74 catalogue.ingest() 

75 

76 def test_ned_function_exception(self): 

77 

78 from sherlock.imports import ned 

79 try: 

80 this = ned( 

81 log=log, 

82 settings=settings, 

83 fakeKey="break the code" 

84 ) 

85 this.get() 

86 assert False 

87 except Exception as e: 

88 assert True 

89 print(str(e))