-
Notifications
You must be signed in to change notification settings - Fork 990
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
test settings.possible_values() #13796
Merged
czoido
merged 4 commits into
conan-io:release/2.0
from
memsharded:feature/settings_get_definition
May 4, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,12 +152,12 @@ def validate(self): | |
if isinstance(self._definition, dict): | ||
self._definition[self._value].validate() | ||
|
||
def get_definition(self): | ||
def possible_values(self): | ||
if isinstance(self._definition, list): | ||
return [e if e != 'None' else None for e in self.values_range] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer use the |
||
return self.values_range.copy() | ||
ret = {} | ||
for key, value in self._definition.items(): | ||
ret[key] = value.get_definition() | ||
ret[key] = value.possible_values() | ||
return ret | ||
|
||
def rm_safe(self, name): | ||
|
@@ -341,11 +341,10 @@ def dumps(self): | |
result.append("%s=%s" % (name, value)) | ||
return '\n'.join(result) | ||
|
||
def get_definition(self): | ||
"""Check the range of values of the definition of a setting. e.g: | ||
get_definition_values("compiler.gcc.version") """ | ||
|
||
def possible_values(self): | ||
"""Check the range of values of the definition of a setting | ||
""" | ||
ret = {} | ||
for key, element in self._data.items(): | ||
ret[key] = element.get_definition() | ||
ret[key] = element.possible_values() | ||
return ret |
59 changes: 59 additions & 0 deletions
59
conans/test/integration/settings/test_settings_possible_values.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import textwrap | ||
|
||
from conans.test.utils.tools import TestClient | ||
|
||
|
||
def test_settings_definitions(): | ||
c = TestClient() | ||
conanfile = textwrap.dedent(""" | ||
from conan import ConanFile | ||
class Pkg(ConanFile): | ||
settings = "os" | ||
def generate(self): | ||
definition = self.settings.possible_values() | ||
assert "os" in definition | ||
assert "compiler" not in definition | ||
assert "arch" not in definition | ||
self.output.info(", ".join(definition["os"])) | ||
ios = definition["os"]["iOS"]["version"] | ||
self.output.info(f"iOS: {ios}") | ||
|
||
os_definition = self.settings.os.possible_values() | ||
ios = os_definition["iOS"]["version"] | ||
self.output.info(f"iOS2: {ios}") | ||
""") | ||
c.save({"conanfile.py": conanfile}) | ||
# New settings are there | ||
c.run("install . -s os=Linux") | ||
assert "conanfile.py: Windows, WindowsStore, WindowsCE, Linux," in c.out | ||
assert "conanfile.py: iOS: ['7.0', '7.1', '8.0'," in c.out | ||
assert "conanfile.py: iOS2: ['7.0', '7.1', '8.0'," in c.out | ||
|
||
|
||
def test_settings_definitions_compiler(): | ||
c = TestClient() | ||
conanfile = textwrap.dedent(""" | ||
from conan import ConanFile | ||
class Pkg(ConanFile): | ||
settings = "compiler" | ||
def generate(self): | ||
definition = self.settings.compiler.version.possible_values() | ||
self.output.info("HOST: " + ", ".join(definition)) | ||
definition = self.settings_build.compiler.version.possible_values() | ||
self.output.info("BUILD: " + ", ".join(definition)) | ||
cppstds = self.settings.compiler.cppstd.possible_values() | ||
self.output.info("CPPSTDS: " + str(cppstds)) | ||
""") | ||
profile = textwrap.dedent("""\ | ||
[settings] | ||
compiler=msvc | ||
compiler.version=192 | ||
compiler.runtime=dynamic | ||
""") | ||
c.save({"conanfile.py": conanfile, | ||
"profile": profile}) | ||
# New settings are there | ||
c.run("install . -pr=profile -s:b compiler=gcc") | ||
assert "conanfile.py: HOST: 170, 180, 190, 191, 192" in c.out | ||
assert "conanfile.py: BUILD: 4.1, 4.4, 4.5, 4.6, 4.7," in c.out | ||
assert "conanfile.py: CPPSTDS: [None, '14', '17', '20', '23']" in c.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug, realized while printing things.