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