Coverage for soxspipe/commonutils/tests/test_sof_util.py: 92%

# Coverage for soxspipe/commonutils/tests/test_sof_util.py : 92%

## 60 statements 55 run 5 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("", dbConn=False).get_project_root()

14 settingsFile = packageDirectory + "/test_settings.yaml"

15# settingsFile = home + "/.config/soxspipe/soxspipe.yaml"

16 su = tools(

17 arguments={"settingsFile": settingsFile},

18 docString=__doc__,

19 logLevel="DEBUG",

20 options_first=False,

21 projectName=None,

22 defaultSettingsFile=False

23)

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

25

26# SETUP AND TEARDOWN FIXTURE FUNCTIONS FOR THE ENTIRE MODULE

27 moduleDirectory = os.path.dirname(__file__)

28 utKit = utKit(moduleDirectory)

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

30 utKit.tearDownModule()

31

32 try:

33 shutil.rmtree(pathToOutputDir)

34 except:

35 pass

36# COPY INPUT TO OUTPUT DIR

37 shutil.copytree(pathToInputDir, pathToOutputDir)

38

39# Recursively create missing directories

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

41 os.makedirs(pathToOutputDir)

42

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

44

45

46 class test_sof_util(unittest.TestCase):

47

48 def test01_sof_util_function(self):

49 directory = settings["test-data-root"] + "/xshooter-bias/vis"

50 other_output = settings[

51 "reduced-data-root"].replace("reduced", "other_output")

52

53 sofPath = other_output + "/test.sof"

54 from soxspipe.commonutils import sof_util

55 sof = sof_util(

56 log=log,

57 settings=settings

58 )

59 sofFile = sof.generate_sof_file_from_directory(

60 directory=directory, sofPath=sofPath)

61 print("sof file written to %(sofPath)s" % locals())

62

63 def test_sof_to_collection_function(self):

64 directory = settings["test-data-root"] + "/xshooter-bias/vis"

65 other_output = settings[

66 "reduced-data-root"].replace("reduced", "other_output")

67

68 sofPath = other_output + "/test.sof"

69 from soxspipe.commonutils import sof_util

70 sof = sof_util(

71 log=log,

72 settings=settings

73 )

74 sofFile = sof.generate_sof_file_from_directory(

75 directory=directory, sofPath=sofPath)

76 print("sof file written to %(sofPath)s" % locals())

77

78 def test_validate_sof_frames_function(self):

79 directory = settings["test-data-root"] + "/xshooter-bias/vis"

80 other_output = settings[

81 "reduced-data-root"].replace("reduced", "other_output")

82 sofPath = other_output + "/test.sof"

83 from soxspipe.commonutils import sof_util

84 sof = sof_util(

85 log=log,

86 settings=settings

87 )

88 sofFile = sof.generate_sof_file_from_directory(

89 directory=directory, sofPath=sofPath)

90

91 print("sof file written to %(sofPath)s" % locals())

92

93 def test_sof_util_function_exception(self):

94

95 from soxspipe.commonutils import sof_util

96 try:

97 this = sof_util(

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

107

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

109

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