Coverage for tests/test_reserveIsolatedStars.py: 41%

30 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-12 03:14 -0800

1# 

2# LSST Data Management System 

3# Copyright 2008-2022 AURA/LSST. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

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

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

11# (at your option) any later version. 

12# 

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

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

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

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22"""Test ReserveIsolatedStarsTask. 

23""" 

24import unittest 

25import numpy as np 

26 

27import lsst.utils.tests 

28 

29from lsst.pipe.tasks.reserveIsolatedStars import (ReserveIsolatedStarsConfig, 

30 ReserveIsolatedStarsTask) 

31 

32 

33class ReserveIsolatedStarsTestCase(lsst.utils.tests.TestCase): 

34 """Test ReserveIsolatedStarsTask.""" 

35 def test_reserve(self): 

36 """Test running the reserve isolated stars task.""" 

37 config = ReserveIsolatedStarsConfig() 

38 reserve_task = ReserveIsolatedStarsTask(config=config) 

39 

40 # Check we get the correct number of reserved stars. 

41 nstar = 1000 

42 reserved = reserve_task.run(nstar, extra='r_100') 

43 self.assertEqual(reserved.sum(), 

44 int(config.reserve_fraction*nstar)) 

45 

46 # Confirm we get the same list with the same run. 

47 reserved2 = reserve_task.run(nstar, extra='r_100') 

48 np.testing.assert_array_equal(reserved2, reserved) 

49 

50 # Confirm we get a different list with a different run. 

51 reserved3 = reserve_task.run(nstar, extra='r_101') 

52 self.assertFalse(np.all(reserved3 == reserved)) 

53 

54 def test_reserve_none(self): 

55 """Test running the reserve isolated stars task with no reserved stars.""" 

56 config = ReserveIsolatedStarsConfig() 

57 config.reserve_fraction = 0.0 

58 reserve_task = ReserveIsolatedStarsTask(config=config) 

59 

60 # Check we get the correct number of reserved stars. 

61 nstar = 1000 

62 reserved = reserve_task.run(nstar) 

63 self.assertEqual(reserved.sum(), 0) 

64 

65 

66class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase): 

67 pass 

68 

69 

70def setup_module(module): 

71 lsst.utils.tests.init() 

72 

73 

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

75 lsst.utils.tests.init() 

76 unittest.main()