|
21 | 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22 | 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23 | 23 |
|
| 24 | +"""Test List Variables elements.""" |
| 25 | + |
24 | 26 | import copy
|
25 | 27 | import unittest
|
26 | 28 |
|
@@ -50,18 +52,22 @@ def test_ListVariable(self) -> None:
|
50 | 52 | assert o.default == 'one,three'
|
51 | 53 |
|
52 | 54 | def test_converter(self) -> None:
|
53 |
| - """Test the ListVariable converter""" |
| 55 | + """Test the ListVariable converter. |
| 56 | +
|
| 57 | + There is now a separate validator (for a long time validation was |
| 58 | + in the converter), but it depends on the _ListVariable instance the |
| 59 | + converter creates, so it's easier to test them in the same function. |
| 60 | + """ |
54 | 61 | opts = SCons.Variables.Variables()
|
55 | 62 | opts.Add(
|
56 | 63 | SCons.Variables.ListVariable(
|
57 | 64 | 'test',
|
58 | 65 | 'test option help',
|
59 |
| - 'all', |
60 |
| - ['one', 'two', 'three'], |
61 |
| - {'ONE': 'one', 'TWO': 'two'}, |
| 66 | + default='all', |
| 67 | + names=['one', 'two', 'three'], |
| 68 | + map={'ONE': 'one', 'TWO': 'two'}, |
62 | 69 | )
|
63 | 70 | )
|
64 |
| - |
65 | 71 | o = opts.options[0]
|
66 | 72 |
|
67 | 73 | x = o.converter('all')
|
@@ -110,10 +116,48 @@ def test_converter(self) -> None:
|
110 | 116 | # invalid value should convert (no change) without error
|
111 | 117 | x = o.converter('no_match')
|
112 | 118 | assert str(x) == 'no_match', x
|
113 |
| - # ... and fail to validate |
| 119 | + |
| 120 | + # validator checks |
| 121 | + |
| 122 | + # first, the one we just set up |
114 | 123 | with self.assertRaises(SCons.Errors.UserError):
|
115 | 124 | o.validator('test', 'no_match', {"test": x})
|
116 | 125 |
|
| 126 | + # now a new option, this time with a name w/ space in it (issue #4585) |
| 127 | + opts.Add( |
| 128 | + SCons.Variables.ListVariable( |
| 129 | + 'test2', |
| 130 | + help='test2 option help', |
| 131 | + default='two', |
| 132 | + names=['one', 'two', 'three', 'four space'], |
| 133 | + ) |
| 134 | + ) |
| 135 | + o = opts.options[1] |
| 136 | + |
| 137 | + def test_valid(opt, seq): |
| 138 | + """Validate a ListVariable value. |
| 139 | +
|
| 140 | + Call the converter manually, since we need the _ListVariable |
| 141 | + object to pass to the validator - this would normally be done |
| 142 | + by the Variables.Update method. |
| 143 | + """ |
| 144 | + x = opt.converter(seq) |
| 145 | + self.assertIsNone(opt.validator(opt.key, x, {opt.key: x})) |
| 146 | + |
| 147 | + with self.subTest(): |
| 148 | + test_valid(o, 'one') |
| 149 | + with self.subTest(): |
| 150 | + test_valid(o, 'one,two,three') |
| 151 | + with self.subTest(): |
| 152 | + test_valid(o, 'all') |
| 153 | + with self.subTest(): |
| 154 | + test_valid(o, 'none') |
| 155 | + with self.subTest(): |
| 156 | + test_valid(o, 'four space') |
| 157 | + with self.subTest(): |
| 158 | + test_valid(o, 'one,four space') |
| 159 | + |
| 160 | + |
117 | 161 | def test_copy(self) -> None:
|
118 | 162 | """Test copying a ListVariable like an Environment would"""
|
119 | 163 | opts = SCons.Variables.Variables()
|
|
0 commit comments