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

arch: fix switchconfig with new setup #2419

Merged
merged 1 commit into from
Jul 22, 2024
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
2 changes: 2 additions & 0 deletions devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,8 @@ def __getitem__(self, key):
return super().__getitem__(key)

def __contains__(self, k):
if isinstance(k, Compiler):
k = k.name
return k in self.keys() or k.startswith('gcc-')


Expand Down
16 changes: 15 additions & 1 deletion tests/test_arch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from devito.arch.compiler import sniff_compiler_version, compiler_registry
from devito import switchconfig, configuration
from devito.arch.compiler import sniff_compiler_version, compiler_registry, GNUCompiler


@pytest.mark.parametrize("cc", [
Expand All @@ -15,3 +16,16 @@ def test_sniff_compiler_version(cc):
@pytest.mark.parametrize("cc", ['gcc-4.9', 'gcc-11', 'gcc', 'gcc-14', 'gcc-123'])
def test_gcc(cc):
assert cc in compiler_registry


def test_switcharch():
old_compiler = configuration['compiler']
with switchconfig(compiler='gcc-4.9'):
tmp_comp = configuration['compiler']
assert isinstance(tmp_comp, GNUCompiler)
assert tmp_comp.suffix == '4.9'

tmp_comp = configuration['compiler']
assert isinstance(tmp_comp, old_compiler.__class__)
assert old_compiler.suffix == tmp_comp.suffix
assert old_compiler.name == tmp_comp.name
Loading