Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

# This file is part of pex_config. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (http://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

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

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

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

# (at your option) any later version. 

# 

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

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

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

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

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

 

import unittest 

 

import testLib 

import pickle 

 

 

class WrapTest(unittest.TestCase): 

 

def testMakeControl(self): 

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

config = testLib.ConfigObject() 

config.foo = 2 

config.bar.append("baz") 

control = config.makeControl() 

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

 

def testReadControl(self): 

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

control = testLib.ControlObject() 

control.foo = 3 

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

config = testLib.ConfigObject() 

config.readControl(control) 

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

 

def testDefaults(self): 

"""Test that C++ Control object defaults are correctly used as defaults for Config objects.""" 

config = testLib.ConfigObject() 

control = testLib.ControlObject() 

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

 

def testPickle(self): 

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

config = testLib.ConfigObject() 

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

self.assertTrue(config.compare(new)) 

self.assertTrue(new.compare(config)) 

 

 

class NestedWrapTest(unittest.TestCase): 

 

def testMakeControl(self): 

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

config = testLib.OuterConfigObject() 

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

config.a.p = 5.0 

config.a.q = 7 

config.b = 2 

control = config.makeControl() 

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

 

def testReadControl(self): 

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

control = testLib.OuterControlObject() 

control.a.p = 6.0 

control.a.q = 4 

control.b = 3 

config = testLib.OuterConfigObject() 

config.readControl(control) 

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

 

def testDefaults(self): 

"""Test that C++ Control object defaults are correctly used as defaults for Config objects.""" 

config = testLib.OuterConfigObject() 

control = testLib.OuterControlObject() 

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

 

def testInt64(self): 

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

config = testLib.OuterConfigObject() 

control = testLib.OuterControlObject() 

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

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

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

 

 

98 ↛ 99line 98 didn't jump to line 99, because the condition on line 98 was never trueif __name__ == "__main__": 

unittest.main()