Coverage for tests/test_pre_transform.py: 46%

37 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-29 03:04 -0700

1# This file is part of ctrl_bps. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27import os 

28import shutil 

29import tempfile 

30import unittest 

31 

32from lsst.ctrl.bps import BpsConfig 

33from lsst.ctrl.bps.pre_transform import create_quantum_graph, execute 

34 

35TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

36 

37 

38class TestExecute(unittest.TestCase): 

39 """Test execution.""" 

40 

41 def setUp(self): 

42 self.file = tempfile.NamedTemporaryFile("w+") 

43 

44 def tearDown(self): 

45 self.file.close() 

46 

47 def testSuccessfulExecution(self): 

48 """Test exit status if command succeeded.""" 

49 status = execute("true", self.file.name) 

50 self.assertIn("true", self.file.read()) 

51 self.assertEqual(status, 0) 

52 

53 def testFailingExecution(self): 

54 """Test exit status if command failed.""" 

55 status = execute("false", self.file.name) 

56 self.assertIn("false", self.file.read()) 

57 self.assertNotEqual(status, 0) 

58 

59 

60class TestCreatingQuantumGraph(unittest.TestCase): 

61 """Test quantum graph creation.""" 

62 

63 def setUp(self): 

64 self.tmpdir = tempfile.mkdtemp(dir=TESTDIR) 

65 

66 def tearDown(self): 

67 shutil.rmtree(self.tmpdir, ignore_errors=True) 

68 

69 def testCreatingQuantumGraph(self): 

70 """Test if a config command creates appropriately named qgraph file.""" 

71 settings = { 

72 "createQuantumGraph": "touch {qgraphFile}", 

73 "submitPath": self.tmpdir, 

74 "whenSaveJobQgraph": "NEVER", 

75 "uniqProcName": "my_test", 

76 "qgraphFileTemplate": "{uniqProcName}.qgraph", 

77 } 

78 config = BpsConfig(settings, search_order=[]) 

79 create_quantum_graph(config, self.tmpdir) 

80 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, config["qgraphFileTemplate"]))) 

81 

82 def testCreatingQuantumGraphFailure(self): 

83 """Test if an exception is raised when creating qgraph file fails.""" 

84 settings = { 

85 "createQuantumGraph": "false", 

86 "submitPath": self.tmpdir, 

87 } 

88 config = BpsConfig(settings, search_order=[]) 

89 with self.assertRaises(RuntimeError): 

90 create_quantum_graph(config, self.tmpdir) 

91 

92 

93if __name__ == "__main__": 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true

94 unittest.main()