Coverage for tests/test_history.py: 45%

18 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-20 11:16 +0000

1# This file is part of pex_config. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

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

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

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

18# (at your option) any later version. 

19# 

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

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

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

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <http://www.gnu.org/licenses/>. 

27 

28import unittest 

29 

30import lsst.pex.config as pexConfig 

31import lsst.pex.config.history as pexConfigHistory 

32 

33 

34class PexTestConfig(pexConfig.Config): 

35 """Simple test config.""" 

36 

37 a = pexConfig.Field("Parameter A", float, default=1.0) 

38 

39 

40class HistoryTest(unittest.TestCase): 

41 """Test history recording.""" 

42 

43 def testHistory(self): 

44 b = PexTestConfig() 

45 b.update(a=4.0) 

46 pexConfigHistory.Color.colorize(False) 

47 output = b.formatHistory("a", writeSourceLine=False) 

48 

49 # The history differs depending on how the tests are executed and might 

50 # depend on pytest internals. We therefore test the output for the 

51 # presence of strings that we know should be there. 

52 

53 # For reference, this is the output from running with unittest.main() 

54 """a 

551.0 unittest.main() 

56 self.runTests() 

57 self.result = testRunner.run(self.test) 

58 test(result) 

59 return self.run(*args, **kwds) 

60 test(result) 

61 return self.run(*args, **kwds) 

62 testMethod() 

63 b = PexTestConfig() 

64 a = pexConfig.Field('Parameter A', float, default=1.0) 

654.0 unittest.main() 

66 self.runTests() 

67 self.result = testRunner.run(self.test) 

68 test(result) 

69 return self.run(*args, **kwds) 

70 test(result) 

71 return self.run(*args, **kwds) 

72 testMethod() 

73 b.update(a=4.0)""" 

74 

75 self.assertTrue(output.startswith("a\n1.0")) 

76 print(output) 

77 self.assertIn( 

78 """ 

79 b = PexTestConfig() 

80 a = pexConfig.Field("Parameter A", float, default=1.0) 

814.0""", 

82 output, 

83 ) 

84 

85 self.assertIn("\n b.update(a=4.0)", output) 

86 

87 

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

89 unittest.main()