This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sage.feature.join_feature: New, factored out from LatteFeature; use i…
…t to implement FourTi2Feature
- Loading branch information
Matthias Koeppe
committed
Jul 19, 2021
1 parent
56016ce
commit 2b45b77
Showing
3 changed files
with
108 additions
and
38 deletions.
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
r""" | ||
Join features | ||
""" | ||
|
||
from . import Feature, FeatureTestResult | ||
|
||
|
||
class JoinFeature(Feature): | ||
r""" | ||
Join of several :class:`sage.features.Feature` instances. | ||
EXAMPLES:: | ||
sage: from sage.features import Executable | ||
sage: from sage.features.join_feature import JoinFeature | ||
sage: F = JoinFeature("shell-boolean", | ||
....: (Executable('shell-true', 'true'), | ||
....: Executable('shell-false', 'false'))) | ||
sage: F.is_present() | ||
FeatureTestResult('shell-boolean', True) | ||
sage: F = JoinFeature("asdfghjkl", | ||
....: (Executable('shell-true', 'true'), | ||
....: Executable('xxyyyy', 'xxyyyy-does-not-exist'))) | ||
sage: F.is_present() | ||
FeatureTestResult('xxyyyy', False) | ||
""" | ||
def __init__(self, name, features, spkg=None, url=None): | ||
""" | ||
TESTS: | ||
The empty join feature is present:: | ||
sage: from sage.features.join_feature import JoinFeature | ||
sage: JoinFeature("empty", ()).is_present() | ||
FeatureTestResult('empty', True) | ||
""" | ||
if spkg is None: | ||
spkgs = set(f.spkg for f in features if f.spkg) | ||
if len(spkgs) > 1: | ||
raise ValueError('given features have more than one spkg; provide spkg argument') | ||
elif len(spkgs) == 1: | ||
spkg = next(iter(spkgs)) | ||
if url is None: | ||
urls = set(f.url for f in features if f.url) | ||
if len(urls) > 1: | ||
raise ValueError('given features have more than one url; provide url argument') | ||
elif len(urls) == 1: | ||
url = next(iter(urls)) | ||
super().__init__(name, spkg=spkg, url=url) | ||
self._features = features | ||
|
||
def _is_present(self): | ||
r""" | ||
Test for the presence of the join feature. | ||
EXAMPLES:: | ||
sage: from sage.features.latte import Latte | ||
sage: Latte()._is_present() # optional - latte_int | ||
FeatureTestResult('LattE', True) | ||
""" | ||
for f in self._features: | ||
test = f._is_present() | ||
if not test: | ||
return test | ||
return FeatureTestResult(self, True) | ||
|
||
def is_functional(self): | ||
r""" | ||
Test whether the join feature is functional. | ||
EXAMPLES:: | ||
sage: from sage.features.latte import Latte | ||
sage: Latte().is_functional() # optional - latte_int | ||
FeatureTestResult('LattE', True) | ||
""" | ||
for f in self._features: | ||
test = f.is_functional() | ||
if not test: | ||
return test | ||
return FeatureTestResult(self, True) |
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