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

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"""Tests of things related to the GraphBuilder class.""" 

23 

24import unittest 

25 

26from lsst.pipe.base import GraphBuilder 

27 

28import lsst.utils.tests 

29 

30 

31class HelperTestCase(unittest.TestCase): 

32 

33 def testAddInstrument(self): 

34 """Verify the pipeline instrument is added to the query.""" 

35 self.assertEqual( 

36 GraphBuilder._verifyInstrumentRestriction("HSC", "tract = 42"), 

37 "instrument = 'HSC' AND (tract = 42)") 

38 

39 def testQueryContainsInstrument(self): 

40 """Verify the instrument is found and no further action is taken.""" 

41 self.assertEqual( 

42 GraphBuilder._verifyInstrumentRestriction("HSC", "'HSC' = instrument AND tract = 42"), 

43 "'HSC' = instrument AND tract = 42") 

44 

45 def testQueryContainsInstrumentAltOrder(self): 

46 """Verify instrument is found in a different order, with no further 

47 action.""" 

48 self.assertEqual( 

49 GraphBuilder._verifyInstrumentRestriction("HSC", "tract=42 AND instrument='HSC'"), 

50 "tract=42 AND instrument='HSC'") 

51 

52 def testQueryContainsSimilarKey(self): 

53 """Verify a key that contains "instrument" is not confused for the 

54 actual "instrument" key.""" 

55 self.assertEqual( 

56 GraphBuilder._verifyInstrumentRestriction("HSC", "notinstrument=42 AND instrument='HSC'"), 

57 "notinstrument=42 AND instrument='HSC'") 

58 

59 def testNoPipelineInstrument(self): 

60 """Verify that when no pipeline instrument is passed that the query is 

61 returned unchanged.""" 

62 self.assertEqual( 

63 GraphBuilder._verifyInstrumentRestriction(None, "foo=bar"), 

64 "foo=bar") 

65 

66 def testNoPipelineInstrumentTwoQueryInstruments(self): 

67 """Verify that when no pipeline instrument is passed that the query can 

68 contain two instruments.""" 

69 self.assertEqual( 

70 GraphBuilder._verifyInstrumentRestriction(None, "instrument = 'HSC' OR instrument = 'LSSTCam'"), 

71 "instrument = 'HSC' OR instrument = 'LSSTCam'") 

72 

73 def testTwoQueryInstruments(self): 

74 """Verify that when a pipeline instrument is passed and the query 

75 contains two instruments that a RuntimeError is raised.""" 

76 with self.assertRaises(RuntimeError): 

77 GraphBuilder._verifyInstrumentRestriction("HSC", "instrument = 'HSC' OR instrument = 'LSSTCam'") 

78 

79 

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

81 lsst.utils.tests.init() 

82 unittest.main()