Coverage for neddy/tests/test_cl_utils.py: 74%

78 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-09-20 10:57 +0000

1from __future__ import print_function 

2from builtins import str 

3import os 

4import unittest 

5import shutil 

6import yaml 

7from neddy.utKit import utKit 

8from fundamentals import tools 

9from os.path import expanduser 

10from docopt import docopt 

11from neddy import cl_utils 

12doc = cl_utils.__doc__ 

13home = expanduser("~") 

14 

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

16settingsFile = packageDirectory + "/test_settings.yaml" 

17 

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() 

27 

28# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

29moduleDirectory = os.path.dirname(__file__) 

30pathToInputDir = moduleDirectory + "/input/" 

31pathToOutputDir = moduleDirectory + "/output/" 

32 

33try: 

34 shutil.rmtree(pathToOutputDir) 

35except: 

36 pass 

37# COPY INPUT TO OUTPUT DIR 

38shutil.copytree(pathToInputDir, pathToOutputDir) 

39 

40# RECURSIVELY CREATE MISSING DIRECTORIES 

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

42 os.makedirs(pathToOutputDir) 

43 

44 

45class test_cl_utils(unittest.TestCase): 

46 

47 import pytest 

48 

49 def test_init(self): 

50 # TEST INITIALISATION OF NEDDY 

51 command = "neddy init" 

52 args = docopt(doc, command.split(" ")[1:]) 

53 cl_utils.main(args) 

54 return 

55 

56 @pytest.mark.full 

57 def test_conesearch(self): 

58 # RUN A SINGLE CONESEARCH ON NED 

59 command = "neddy cone 02:27:16.9 +33:34:45 4.0" 

60 args = docopt(doc, command.split(" ")[1:]) 

61 cl_utils.main(args) 

62 

63 # RETURN A MORE VERBOSE OUTPUT 

64 command = "neddy -v cone 02:27:16.9 +33:34:45 4.0" 

65 args = docopt(doc, command.split(" ")[1:]) 

66 cl_utils.main(args) 

67 

68 # RETURN THE NEAREST OBJECT ONLY 

69 command = "neddy -n cone 02:27:16.9 +33:34:45 4.0" 

70 args = docopt(doc, command.split(" ")[1:]) 

71 cl_utils.main(args) 

72 

73 # INCLUDE UNCLASSIFIED EXTRA-GALACTIC OBJECTS 

74 command = "neddy -u cone 02:27:16.9 +33:34:45 4.0" 

75 args = docopt(doc, command.split(" ")[1:]) 

76 cl_utils.main(args) 

77 

78 # REDSHIFT MUST BE AVAILABLE 

79 command = "neddy -r cone 02:27:16.9 +33:34:45 4.0" 

80 args = docopt(doc, command.split(" ")[1:]) 

81 cl_utils.main(args) 

82 

83 # WRITE THE RESULTS TO FILE 

84 command = f"neddy -r cone 02:27:16.9 +33:34:45 4.0 --o {pathToOutputDir}/results.csv" 

85 args = docopt(doc, command.split(" ")[1:]) 

86 cl_utils.main(args) 

87 return 

88 

89 def test_conesearch_all(self): 

90 # RUN A SINGLE CONESEARCH ON NED 

91 command = f"neddy -vnur cone 02:27:16.9 +33:34:45 4.0 --o {pathToOutputDir}/results.csv" 

92 args = docopt(doc, command.split(" ")[1:]) 

93 cl_utils.main(args) 

94 

95 def test_conesearches(self): 

96 # RUN MULTIPLE NED CONESEARCHES 

97 command = f"neddy -vn cones {pathToOutputDir}/coordinates.txt 4.0" 

98 args = docopt(doc, command.split(" ")[1:]) 

99 cl_utils.main(args) 

100 

101 # RUN MULTIPLE NED CONESEARCHES AND OUTPUT TO FILE 

102 command = f"neddy -vn cones {pathToOutputDir}/coordinates.txt 4.0 --o {pathToOutputDir}/results.csv" 

103 args = docopt(doc, command.split(" ")[1:]) 

104 cl_utils.main(args) 

105 return 

106 

107 def test_name_searches(self): 

108 # RUN A SINGLE NED NAME SEARCH 

109 command = f"neddy -v name m31" 

110 args = docopt(doc, command.split(" ")[1:]) 

111 cl_utils.main(args) 

112 

113 # RUN MULTIPLE NED NAME SEARCHES 

114 command = f"neddy -v name m31 m51 m101" 

115 args = docopt(doc, command.split(" ")[1:]) 

116 cl_utils.main(args) 

117 

118 # RUN MULTIPLE NED NAME SEARCHES AND OUTPUT TO FILE 

119 command = f"neddy -v name m31 m51 m101 --o {pathToOutputDir}/results.csv" 

120 args = docopt(doc, command.split(" ")[1:]) 

121 cl_utils.main(args) 

122 return 

123 

124 # x-class-to-test-named-worker-function