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 unittest 

7import yaml 

8from soxspipe.utKit import utKit 

9from fundamentals import tools 

10from os.path import expanduser 

11home = expanduser("~") 

12from astropy.nddata import CCDData 

13from astropy import units as u 

14 

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

16settingsFile = packageDirectory + "/test_settings.yaml" 

17# settingsFile = home + \ 

18# "/git_repos/_misc_/settings/soxspipe/test_settings.yaml" 

19 

20su = tools( 

21 arguments={"settingsFile": settingsFile}, 

22 docString=__doc__, 

23 logLevel="DEBUG", 

24 options_first=False, 

25 projectName=None, 

26 defaultSettingsFile=False 

27) 

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

29 

30# SETUP PATHS TO COMMON DIRECTORIES FOR TEST DATA 

31moduleDirectory = os.path.dirname(__file__) 

32pathToInputDir = moduleDirectory + "/input/" 

33pathToOutputDir = moduleDirectory + "/output/" 

34 

35try: 

36 shutil.rmtree(pathToOutputDir) 

37except: 

38 pass 

39# COPY INPUT TO OUTPUT DIR 

40shutil.copytree(pathToInputDir, pathToOutputDir) 

41 

42# Recursively create missing directories 

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

44 os.makedirs(pathToOutputDir) 

45 

46 

47# xt-setup-unit-testing-files-and-folders 

48 

49 

50class test_detect_continuum(unittest.TestCase): 

51 

52 def test_detect_continuum_function(self): 

53 pinholeFlatPath = "~/xshooter-pipeline-data/unittest_data/xsh/detect_continuum/order_definition_NIR_calibrated.fits" 

54 dispersion_map = "~/xshooter-pipeline-data/unittest_data/xsh/detect_continuum/single_pinhole_NIR_disp_map.csv" 

55 home = expanduser("~") 

56 pinholeFlatPath = pinholeFlatPath.replace("~", home) 

57 

58 pinholeFlat = CCDData.read(pinholeFlatPath, hdu=0, unit=u.electron, hdu_uncertainty='ERRS', 

59 hdu_mask='QUAL', hdu_flags='FLAGS', key_uncertainty_type='UTYPE') 

60 

61 from soxspipe.commonutils import detect_continuum 

62 this = detect_continuum( 

63 log=log, 

64 pinholeFlat=pinholeFlat, 

65 dispersion_map=dispersion_map, 

66 settings=settings, 

67 recipeName="soxs-order-centre" 

68 ) 

69 this.get() 

70 

71 def test_detect_continuum_function_exception(self): 

72 

73 from soxspipe.commonutils import detect_continuum 

74 try: 

75 this = detect_continuum( 

76 log=log, 

77 settings=settings, 

78 fakeKey="break the code" 

79 ) 

80 this.get() 

81 assert False 

82 except Exception as e: 

83 assert True 

84 print(str(e)) 

85 

86 # x-print-testpage-for-pessto-marshall-web-object 

87 

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