Coverage for soxspipe/commonutils/tests/test_keyword_lookup.py: 0%

# Coverage for soxspipe/commonutils/tests/test_keyword_lookup.py : 0%

## 52 statements 0 run 52 missing 0 excluded

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

1 from __future__ import print_function

2 from builtins import str

3 import os

4 import unittest

5 import shutil

6 import unittest

7 import yaml

8 from soxspipe.utKit import utKit

9 from fundamentals import tools

10 from os.path import expanduser

11 home = expanduser("~")

12

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

14 settingsFile = packageDirectory + "/test_settings.yaml"

15# settingsFile = home +

16# "/.config/soxspipe.commonutils/soxspipe.commonutils.yaml"

17 su = tools(

18 arguments={"settingsFile": settingsFile},

19 docString=__doc__,

20 logLevel="DEBUG",

21 options_first=False,

22 projectName=None,

23 defaultSettingsFile=False

24)

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

26

27# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE

28 moduleDirectory = os.path.dirname(__file__)

29 utKit = utKit(moduleDirectory)

30 log, dbConn, pathToInputDir, pathToOutputDir = utKit.setupModule()

31 utKit.tearDownModule()

32

33 try:

34 shutil.rmtree(pathToOutputDir)

35 except:

36 pass

37# COPY INPUT TO OUTPUT DIR

38 shutil.copytree(pathToInputDir, pathToOutputDir)

39

40# Recursively create missing directories

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

42 os.makedirs(pathToOutputDir)

43

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

45

46

47 class test_keyword_lookup(unittest.TestCase):

48

49 def test_keyword_dictionary_selection_function(self):

50

51 from soxspipe.commonutils import keyword_lookup

52 this = keyword_lookup(

53 log=log,

54 settings=settings

55 )

56 kw = this._select_dictionary()

57 print(kw["DET_NDITSKIP"])

58 print(kw["MJDOBS"])

59 print(kw["NAXIS1"])

60

61 def test_keyword_lookup_function(self):

62

63 from soxspipe.commonutils import keyword_lookup

64 kw = keyword_lookup(

65 log=log,

66 settings=settings

67 ).get

68 if settings["instrument"] == "xsh":

69 assert kw("DET_NDITSKIP") == "ESO DET NDITSKIP"

70 assert kw("PROV", 14) == "PROV14"

71 assert kw("PROV", 1) == "PROV01"

72

73 # AND HOW ABOUT LISTS

74 if settings["instrument"] == "xsh":

75 assert kw(["PROV", "DET_NDITSKIP"])[1] == 'ESO DET NDITSKIP'

76

77 def test_keyword_lookup_function_exception(self):

78

79 from soxspipe.commonutils import keyword_lookup

80 try:

81 this = keyword_lookup(

82 log=log,

83 settings=settings,

84 fakeKey="break the code"

85 )

86 this.get()

87 assert False

88 except Exception as e:

89 assert True

90 print(str(e))

91

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

93

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