Hide keyboard shortcuts

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# This file is part of ctrl_mpexec. 

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/>. 

21 

22"""Simple unit test for cmdLineFwk module. 

23""" 

24 

25import logging 

26import time 

27import unittest 

28 

29from lsst.ctrl.mpexec import MPGraphExecutor, MPTimeoutError, QuantumExecutor 

30from lsst.ctrl.mpexec.execFixupDataId import ExecFixupDataId 

31from testUtil import makeSimpleQGraph 

32 

33 

34logging.basicConfig(level=logging.INFO) 

35 

36 

37class QuantumExecutorMock(QuantumExecutor): 

38 """Mock class for QuantumExecutor 

39 """ 

40 def __init__(self, sleep=None): 

41 self.taskDefs = [] 

42 self.quanta = [] 

43 self.sleep = sleep 

44 

45 def execute(self, taskDef, quantum, butler): 

46 self.taskDefs += [taskDef] 

47 self.quanta += [quantum] 

48 if self.sleep: 

49 time.sleep(self.sleep) 

50 

51 def getDataIds(self, field): 

52 """Returns values for dataId field for each visited quanta""" 

53 return [quantum.dataId[field] for quantum in self.quanta] 

54 

55 

56class MPGraphExecutorTestCase(unittest.TestCase): 

57 """A test case for MPGraphExecutor class 

58 """ 

59 

60 def test_mpexec(self): 

61 """Make simple graph and execute""" 

62 

63 nQuanta = 3 

64 butler, qgraph = makeSimpleQGraph(nQuanta) 

65 

66 qexec = QuantumExecutorMock() 

67 mpexec = MPGraphExecutor(numProc=1, timeout=1, quantumExecutor=qexec) 

68 mpexec.execute(qgraph, butler) 

69 # the order is not defined 

70 self.assertCountEqual(qexec.getDataIds("detector"), [0, 1, 2]) 

71 

72 def test_mpexec_fixup(self): 

73 """Make simple graph and execute, add dependencies""" 

74 

75 nQuanta = 3 

76 butler, qgraph = makeSimpleQGraph(nQuanta) 

77 

78 for reverse in (False, True): 

79 qexec = QuantumExecutorMock() 

80 fixup = ExecFixupDataId("task1", "detector", reverse=reverse) 

81 mpexec = MPGraphExecutor(numProc=1, timeout=1, quantumExecutor=qexec, 

82 executionGraphFixup=fixup) 

83 mpexec.execute(qgraph, butler) 

84 

85 expected = [0, 1, 2] 

86 if reverse: 

87 expected = list(reversed(expected)) 

88 self.assertEqual(qexec.getDataIds("detector"), expected) 

89 

90 def test_mpexec_timeout(self): 

91 """Make simple graph and execute, add dependencies""" 

92 

93 nQuanta = 3 

94 butler, qgraph = makeSimpleQGraph(nQuanta) 

95 

96 for reverse in (False, True): 

97 qexec = QuantumExecutorMock(sleep=3) 

98 mpexec = MPGraphExecutor(numProc=3, timeout=1, quantumExecutor=qexec) 

99 with self.assertRaises(MPTimeoutError): 

100 mpexec.execute(qgraph, butler) 

101 

102 

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

104 unittest.main()