Coverage for tests/test_TestUtilities.py: 47%

30 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-08-22 09:50 +0000

1# This file is part of meas_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 

22import unittest 

23 

24import numpy as np 

25 

26import lsst.geom 

27import lsst.afw.geom as afwGeom 

28import lsst.utils.tests as utilsTests 

29 

30# Rename the class on import so it does not confuse the test scanner 

31from lsst.meas.base.tests import TestDataset as DatasetTester 

32 

33 

34class TestDatasetTestCase(utilsTests.TestCase): 

35 

36 def setUp(self): 

37 # Construct an arbitrary WCS for testing. 

38 crval = lsst.geom.SpherePoint(45.0, 45.0, lsst.geom.degrees) 

39 scale = 0.2*lsst.geom.arcseconds 

40 crpix = lsst.geom.PointD(100, 100) 

41 self.wcs = afwGeom.makeSkyWcs(crpix=crpix, crval=crval, 

42 cdMatrix=afwGeom.makeCdMatrix(scale=scale)) 

43 

44 def tearDown(self): 

45 del self.wcs 

46 

47 def test_perturb(self): 

48 """Test that perturbing a WCS gives us back something different. 

49 """ 

50 # We should always get something different from our starting point. 

51 self.assertNotEqual(self.wcs, DatasetTester.makePerturbedWcs(self.wcs)) 

52 

53 # If we use the same random seed, the results should be reproducible. 

54 self.assertEqual(DatasetTester.makePerturbedWcs(self.wcs, randomSeed=0), 

55 DatasetTester.makePerturbedWcs(self.wcs, randomSeed=0)) 

56 

57 # If we specify different seeds, we should always get something 

58 # different. 

59 self.assertNotEqual(DatasetTester.makePerturbedWcs(self.wcs, randomSeed=1), 

60 DatasetTester.makePerturbedWcs(self.wcs, randomSeed=2)) 

61 

62 def test_randomState(self): 

63 """Test that we do not alter global state when perturbing the WCS. 

64 

65 Notes 

66 ----- 

67 This checks that global state doesn't change while the test is 

68 executing. This isn't perfectly robust: the test will fail if another 

69 thread manipulates the RNG state while this is executing. However, 

70 since pytest doesn't using multi-threading, it should be safe in 

71 practice. 

72 """ 

73 init_state = np.random.get_state() 

74 DatasetTester.makePerturbedWcs(self.wcs) 

75 for init, final in zip(init_state, np.random.get_state()): 

76 self.assertTrue(np.array_equal(init, final)) 

77 

78 

79class TestMemory(utilsTests.MemoryTestCase): 

80 pass 

81 

82 

83def setup_module(module): 

84 utilsTests.init() 

85 

86 

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

88 utilsTests.init() 

89 unittest.main()