Skip to content

Commit

Permalink
Merge pull request #2419 from devitocodes/arch-misc-fix
Browse files Browse the repository at this point in the history
arch: fix switchconfig with new setup
  • Loading branch information
mloubout authored Jul 22, 2024
2 parents 0597d00 + 6bfeb88 commit 772f130
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 772f130

Please sign in to comment.