Coverage for tests/test_wrap.py: 33%
60 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-17 09:34 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-17 09:34 +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/>.
28import unittest
30try:
31 import testLib
32except ImportError:
33 testLib = None
35import pickle
38@unittest.skipIf(testLib is None, "C++ tests disabled")
39class WrapTest(unittest.TestCase):
40 def testMakeControl(self):
41 """Test making a C++ Control object from a Config object."""
42 config = testLib.ConfigObject()
43 config.foo = 2
44 config.bar.append("baz")
45 control = config.makeControl()
46 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))
48 def testReadControl(self):
49 """Test reading the values from a C++ Control object into a Config
50 object."""
51 control = testLib.ControlObject()
52 control.foo = 3
53 control.bar = ["zot", "yox"]
54 config = testLib.ConfigObject()
55 config.readControl(control)
56 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))
58 def testDefaults(self):
59 """Test that C++ Control object defaults are correctly used as defaults
60 for Config objects."""
61 config = testLib.ConfigObject()
62 control = testLib.ControlObject()
63 self.assertTrue(testLib.checkControl(control, config.foo, config.bar.list()))
65 def testPickle(self):
66 """Test that C++ Control object pickles correctly"""
67 config = testLib.ConfigObject()
68 new = pickle.loads(pickle.dumps(config))
69 self.assertTrue(config.compare(new))
70 self.assertTrue(new.compare(config))
73@unittest.skipIf(testLib is None, "C++ tests disabled")
74class NestedWrapTest(unittest.TestCase):
75 def testMakeControl(self):
76 """Test making a C++ Control object from a Config object."""
77 config = testLib.OuterConfigObject()
78 self.assertIsInstance(config.a, testLib.InnerConfigObject)
79 config.a.p = 5.0
80 config.a.q = 7
81 config.b = 2
82 control = config.makeControl()
83 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))
85 def testReadControl(self):
86 """Test reading the values from a C++ Control object into a Config
87 object."""
88 control = testLib.OuterControlObject()
89 control.a.p = 6.0
90 control.a.q = 4
91 control.b = 3
92 config = testLib.OuterConfigObject()
93 config.readControl(control)
94 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))
96 def testDefaults(self):
97 """Test that C++ Control object defaults are correctly used as defaults
98 for Config objects."""
99 config = testLib.OuterConfigObject()
100 control = testLib.OuterControlObject()
101 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))
103 def testInt64(self):
104 """Test that we can wrap C++ Control objects with int64 members."""
105 config = testLib.OuterConfigObject()
106 control = testLib.OuterControlObject()
107 self.assertTrue(testLib.checkNestedControl(control, config.a.p, config.a.q, config.b))
108 self.assertGreater(config.a.q, 1 << 30)
109 self.assertGreater(control.a.q, 1 << 30)
112if __name__ == "__main__": 112 ↛ 113line 112 didn't jump to line 113, because the condition on line 112 was never true
113 unittest.main()