Coverage for tests/test_pre_transform.py: 46%

37 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-07 02:51 -0800

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 program is free software: you can redistribute it and/or modify 

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21import os 

22import shutil 

23import tempfile 

24import unittest 

25 

26from lsst.ctrl.bps import BpsConfig 

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

28 

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

30 

31 

32class TestExecute(unittest.TestCase): 

33 def setUp(self): 

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

35 

36 def tearDown(self): 

37 self.file.close() 

38 

39 def testSuccessfulExecution(self): 

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

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

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

43 self.assertEqual(status, 0) 

44 

45 def testFailingExecution(self): 

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

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

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

49 self.assertNotEqual(status, 0) 

50 

51 

52class TestCreatingQuantumGraph(unittest.TestCase): 

53 def setUp(self): 

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

55 

56 def tearDown(self): 

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

58 

59 def testCreatingQuantumGraph(self): 

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

61 settings = { 

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

63 "submitPath": self.tmpdir, 

64 "whenSaveJobQgraph": "NEVER", 

65 "uniqProcName": "my_test", 

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

67 } 

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

69 create_quantum_graph(config, self.tmpdir) 

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

71 

72 def testCreatingQuantumGraphFailure(self): 

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

74 settings = { 

75 "createQuantumGraph": "false", 

76 "submitPath": self.tmpdir, 

77 } 

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

79 with self.assertRaises(RuntimeError): 

80 create_quantum_graph(config, self.tmpdir) 

81 

82 

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

84 unittest.main()