Coverage for tests/test_wrap.py: 33%

60 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-06 03:53 -0700

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 

30try: 

31 import testLib 

32except ImportError: 

33 testLib = None 

34 

35import pickle 

36 

37 

38@unittest.skipIf(testLib is None, "C++ tests disabled") 

39class WrapTest(unittest.TestCase): 

40 """Test C++ wrappgin.""" 

41 

42 def testMakeControl(self): 

43 """Test making a C++ Control object from a Config object.""" 

44 config = testLib.ConfigObject() 

45 config.foo = 2 

46 config.bar.append("baz") 

47 control = config.makeControl() 

48 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list())) 

49 

50 def testReadControl(self): 

51 """Test reading the values from a C++ Control object into a Config 

52 object. 

53 """ 

54 control = testLib.ControlObject() 

55 control.foo = 3 

56 control.bar = ["zot", "yox"] 

57 config = testLib.ConfigObject() 

58 config.readControl(control) 

59 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list())) 

60 

61 def testDefaults(self): 

62 """Test that C++ Control object defaults are correctly used as defaults 

63 for Config objects. 

64 """ 

65 config = testLib.ConfigObject() 

66 control = testLib.ControlObject() 

67 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list())) 

68 

69 def testPickle(self): 

70 """Test that C++ Control object pickles correctly.""" 

71 config = testLib.ConfigObject() 

72 new = pickle.loads(pickle.dumps(config)) 

73 self.assertTrue(config.compare(new)) 

74 self.assertTrue(new.compare(config)) 

75 

76 

77@unittest.skipIf(testLib is None, "C++ tests disabled") 

78class NestedWrapTest(unittest.TestCase): 

79 """Test of nested C++ test.""" 

80 

81 def testMakeControl(self): 

82 """Test making a C++ Control object from a Config object.""" 

83 config = testLib.OuterConfigObject() 

84 self.assertIsInstance(config.a, testLib.InnerConfigObject) 

85 config.a.p = 5.0 

86 config.a.q = 7 

87 config.b = 2 

88 control = config.makeControl() 

89 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b)) 

90 

91 def testReadControl(self): 

92 """Test reading the values from a C++ Control object into a Config 

93 object. 

94 """ 

95 control = testLib.OuterControlObject() 

96 control.a.p = 6.0 

97 control.a.q = 4 

98 control.b = 3 

99 config = testLib.OuterConfigObject() 

100 config.readControl(control) 

101 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b)) 

102 

103 def testDefaults(self): 

104 """Test that C++ Control object defaults are correctly used as defaults 

105 for Config objects. 

106 """ 

107 config = testLib.OuterConfigObject() 

108 control = testLib.OuterControlObject() 

109 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b)) 

110 

111 def testInt64(self): 

112 """Test that we can wrap C++ Control objects with int64 members.""" 

113 config = testLib.OuterConfigObject() 

114 control = testLib.OuterControlObject() 

115 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b)) 

116 self.assertGreater(config.a.q, 1 << 30) 

117 self.assertGreater(control.a.q, 1 << 30) 

118 

119 

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

121 unittest.main()