Skip to content

Commit a394c8b

Browse files
committed
Fix Variables.PackageVariable with bool default string
when passed a 'true' string on the command line actually test default value against both ENABLE_STRINGS and DISABLE_STRINGS Closes: #4702 See-Also: https://bugs.gentoo.org/950584 Signed-off-by: Bill Prendergast <[email protected]>
1 parent d54721e commit a394c8b

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
1616

1717
- Whatever John Doe did.
1818

19+
From Bill Prendergast:
20+
- Fixed SCons.Variables.PackageVariable to correctly test the default
21+
setting against both enable & disable strings.
22+
- Extended unittests (crudely) to test for correct/expected response
23+
when default setting is a boolean string.
24+
1925

2026
RELEASE 4.9.1 - Thu, 27 Mar 2025 11:40:20 -0700
2127

SCons/Variables/PackageVariable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _converter(val: str | bool, default: str) -> str | bool:
8686
if lval in ENABLE_STRINGS:
8787
# Can't return the default if it is one of the enable/disable strings;
8888
# test code expects a bool.
89-
if default in ENABLE_STRINGS:
89+
if default in ENABLE_STRINGS + DISABLE_STRINGS:
9090
return True
9191
else:
9292
return default

SCons/Variables/PackageVariableTests.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@ def test_converter(self) -> None:
9292
x = o.converter(False)
9393
assert not x, f"converter returned False for {t!r}"
9494

95+
# When the variable is created with boolean string make sure the converter
96+
# returns the correct result i.e. a bool or a passed path
97+
opts = SCons.Variables.Variables()
98+
opts.Add(SCons.Variables.PackageVariable('test', 'test build variable help', 'yes'))
99+
o = opts.options[0]
100+
101+
x = o.converter(str(True))
102+
assert not isinstance(x, str), "converter with default str(yes) returned a string when given str(True)"
103+
assert x, "converter with default str(yes) returned False for str(True)"
104+
x = o.converter(str(False))
105+
assert not isinstance(x, str), "converter with default str(yes) returned a string when given str(False)"
106+
assert not x, "converter with default str(yes) returned True for str(False)"
107+
x = o.converter('/explicit/path')
108+
assert x == '/explicit/path', "converter with default str(yes) did not return path"
109+
110+
opts = SCons.Variables.Variables()
111+
opts.Add(SCons.Variables.PackageVariable('test', 'test build variable help', 'no'))
112+
o = opts.options[0]
113+
114+
x = o.converter(str(True))
115+
assert not isinstance(x, str), "converter with default str(no) returned a string when given str(True)"
116+
assert x, "converter with default str(no) returned False for str(True)"
117+
x = o.converter(str(False))
118+
assert not isinstance(x, str), "converter with default str(no) returned a string when given str(False)"
119+
assert not x, "converter with default str(no) returned True for str(False)"
120+
x = o.converter('/explicit/path')
121+
assert x == '/explicit/path', "converter with default str(no) did not return path"
122+
95123
def test_validator(self) -> None:
96124
"""Test the PackageVariable validator"""
97125
opts = SCons.Variables.Variables()

0 commit comments

Comments
 (0)