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 unittest 

27 

28from lsst.ctrl.mpexec import MPGraphExecutor, QuantumExecutor 

29from lsst.ctrl.mpexec.execFixupDataId import ExecFixupDataId 

30from testUtil import makeSimpleQGraph 

31 

32 

33logging.basicConfig(level=logging.INFO) 

34 

35 

36class QuantumExecutorMock(QuantumExecutor): 

37 """Mock class for QuantumExecutor 

38 """ 

39 def __init__(self): 

40 self.taskDefs = [] 

41 self.quanta = [] 

42 

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

44 self.taskDefs += [taskDef] 

45 self.quanta += [quantum] 

46 

47 def getDataIds(self, field): 

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

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

50 

51 

52class MPGraphExecutorTestCase(unittest.TestCase): 

53 """A test case for MPGraphExecutor class 

54 """ 

55 

56 def test_mpexec(self): 

57 """Make simple graph and execute""" 

58 

59 nQuanta = 3 

60 butler, qgraph = makeSimpleQGraph(nQuanta) 

61 

62 qexec = QuantumExecutorMock() 

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

64 mpexec.execute(qgraph, butler) 

65 # the order is not defined 

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

67 

68 def test_mpexec_fixup(self): 

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

70 

71 nQuanta = 3 

72 butler, qgraph = makeSimpleQGraph(nQuanta) 

73 

74 for reverse in (False, True): 

75 qexec = QuantumExecutorMock() 

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

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

78 executionGraphFixup=fixup) 

79 mpexec.execute(qgraph, butler) 

80 

81 expected = [0, 1, 2] 

82 if reverse: 

83 expected = list(reversed(expected)) 

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

85 

86 

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

88 unittest.main()