Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Variables.PackageVariable with bool default string #4703

Merged
merged 2 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER

- Whatever John Doe did.

From Bill Prendergast:
- Fixed SCons.Variables.PackageVariable to correctly test the default
setting against both enable & disable strings. (Fixes #4702)
- Extended unittests (crudely) to test for correct/expected response
when default setting is a boolean string.


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

Expand Down
3 changes: 2 additions & 1 deletion RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
FIXES
-----

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

IMPROVEMENTS
------------
Expand Down
2 changes: 1 addition & 1 deletion SCons/Variables/PackageVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _converter(val: str | bool, default: str) -> str | bool:
if lval in ENABLE_STRINGS:
# Can't return the default if it is one of the enable/disable strings;
# test code expects a bool.
if default in ENABLE_STRINGS:
if default in ENABLE_STRINGS + DISABLE_STRINGS:
return True
else:
return default
Expand Down
28 changes: 28 additions & 0 deletions SCons/Variables/PackageVariableTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ def test_converter(self) -> None:
x = o.converter(False)
assert not x, f"converter returned False for {t!r}"

# When the variable is created with boolean string make sure the converter
# returns the correct result i.e. a bool or a passed path
opts = SCons.Variables.Variables()
opts.Add(SCons.Variables.PackageVariable('test', 'test build variable help', 'yes'))
o = opts.options[0]

x = o.converter(str(True))
assert not isinstance(x, str), "converter with default str(yes) returned a string when given str(True)"
assert x, "converter with default str(yes) returned False for str(True)"
x = o.converter(str(False))
assert not isinstance(x, str), "converter with default str(yes) returned a string when given str(False)"
assert not x, "converter with default str(yes) returned True for str(False)"
x = o.converter('/explicit/path')
assert x == '/explicit/path', "converter with default str(yes) did not return path"

opts = SCons.Variables.Variables()
opts.Add(SCons.Variables.PackageVariable('test', 'test build variable help', 'no'))
o = opts.options[0]

x = o.converter(str(True))
assert not isinstance(x, str), "converter with default str(no) returned a string when given str(True)"
assert x, "converter with default str(no) returned False for str(True)"
x = o.converter(str(False))
assert not isinstance(x, str), "converter with default str(no) returned a string when given str(False)"
assert not x, "converter with default str(no) returned True for str(False)"
x = o.converter('/explicit/path')
assert x == '/explicit/path', "converter with default str(no) did not return path"

def test_validator(self) -> None:
"""Test the PackageVariable validator"""
opts = SCons.Variables.Variables()
Expand Down