Remove redundant code
[scons.git] / SCons / Variables / ListVariableTests.py
blob172a54ff011d284b4ebc60c820121dc4d631daa8
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import copy
25 import unittest
27 import SCons.Errors
28 import SCons.Variables
30 class ListVariableTestCase(unittest.TestCase):
31 def test_ListVariable(self) -> None:
32 """Test ListVariable creation"""
33 opts = SCons.Variables.Variables()
34 opts.Add(SCons.Variables.ListVariable('test', 'test option help', 'all',
35 ['one', 'two', 'three']))
37 o = opts.options[0]
38 assert o.key == 'test', o.key
39 assert o.help == 'test option help\n (all|none|comma-separated list of names)\n allowed names: one two three', repr(o.help)
40 assert o.default == 'all', o.default
41 assert o.validator is None, o.validator
42 assert o.converter is not None, o.converter
44 opts = SCons.Variables.Variables()
45 opts.Add(SCons.Variables.ListVariable('test2', 'test2 help',
46 ['one', 'three'],
47 ['one', 'two', 'three']))
49 o = opts.options[0]
50 assert o.default == 'one,three'
52 def test_converter(self) -> None:
53 """Test the ListVariable converter"""
54 opts = SCons.Variables.Variables()
55 opts.Add(SCons.Variables.ListVariable('test', 'test option help', 'all',
56 ['one', 'two', 'three'],
57 {'ONE':'one', 'TWO':'two'}))
59 o = opts.options[0]
61 x = o.converter('all')
62 assert str(x) == 'all', x
64 x = o.converter('none')
65 assert str(x) == 'none', x
67 x = o.converter('one')
68 assert str(x) == 'one', x
69 x = o.converter('ONE')
70 assert str(x) == 'one', x
72 x = o.converter('two')
73 assert str(x) == 'two', x
74 x = o.converter('TWO')
75 assert str(x) == 'two', x
77 x = o.converter('three')
78 assert str(x) == 'three', x
80 x = o.converter('one,two')
81 assert str(x) == 'one,two', x
82 x = o.converter('two,one')
83 assert str(x) == 'one,two', x
85 x = o.converter('one,three')
86 assert str(x) == 'one,three', x
87 x = o.converter('three,one')
88 assert str(x) == 'one,three', x
90 x = o.converter('two,three')
91 assert str(x) == 'three,two', x
92 x = o.converter('three,two')
93 assert str(x) == 'three,two', x
95 x = o.converter('one,two,three')
96 assert str(x) == 'all', x
98 x = o.converter('three,two,one')
99 assert str(x) == 'all', x
101 x = o.converter('three,ONE,TWO')
102 assert str(x) == 'all', x
104 caught = None
105 try:
106 x = o.converter('no_match')
107 except ValueError:
108 caught = 1
109 assert caught, "did not catch expected ValueError"
111 def test_copy(self) -> None:
112 """Test copying a ListVariable like an Environment would"""
113 opts = SCons.Variables.Variables()
114 opts.Add(SCons.Variables.ListVariable('test', 'test option help', 'all',
115 ['one', 'two', 'three']))
117 o = opts.options[0]
119 l = o.converter('all')
120 n = l.__class__(copy.copy(l))
122 if __name__ == "__main__":
123 unittest.main()
125 # Local Variables:
126 # tab-width:4
127 # indent-tabs-mode:nil
128 # End:
129 # vim: set expandtab tabstop=4 shiftwidth=4: