Coverage for tests/test_pre_transform.py: 49%

Shortcuts 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

37 statements  

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 execute, create_quantum_graph 

28 

29 

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

31 

32 

33class TestExecute(unittest.TestCase): 

34 

35 def setUp(self): 

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

37 

38 def tearDown(self): 

39 self.file.close() 

40 

41 def testSuccessfulExecution(self): 

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

43 status = execute('true', self.file.name) 

44 self.assertIn('true', self.file.read()) 

45 self.assertEqual(status, 0) 

46 

47 def testFailingExecution(self): 

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

49 status = execute('false', self.file.name) 

50 self.assertIn('false', self.file.read()) 

51 self.assertNotEqual(status, 0) 

52 

53 

54class TestCreatingQuantumGraph(unittest.TestCase): 

55 

56 def setUp(self): 

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

58 

59 def tearDown(self): 

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

61 

62 def testCreatingQuantumGraph(self): 

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

64 settings = { 

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

66 "submitPath": self.tmpdir, 

67 "whenSaveJobQgraph": "NEVER", 

68 "uniqProcName": "my_test", 

69 "qgraphFileTemplate": "{uniqProcName}.qgraph" 

70 } 

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

72 create_quantum_graph(config, self.tmpdir) 

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

74 

75 def testCreatingQuantumGraphFailure(self): 

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

77 settings = { 

78 "createQuantumGraph": "false", 

79 "submitPath": self.tmpdir, 

80 } 

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

82 with self.assertRaises(RuntimeError): 

83 create_quantum_graph(config, self.tmpdir) 

84 

85 

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

87 unittest.main()