Skip to content

Commit be6c181

Browse files
authored
Merge pull request #4703 from dekeonus/pkgvar_negdef
Fix Variables.PackageVariable with bool default string
2 parents d54721e + ccf9dfd commit be6c181

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
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. (Fixes #4702)
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

RELEASE.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
3232
FIXES
3333
-----
3434

35-
- List fixes of outright bugs
35+
- Fixed SCons.Variables.PackageVariable to correctly test the default
36+
setting against both enable & disable strings. (Fixes #4702)
3637

3738
IMPROVEMENTS
3839
------------

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)