Skip to content

Commit 6bfeb88

Browse files
committed
arch: fix switchconfig with new setup
1 parent 0597d00 commit 6bfeb88

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

devito/arch/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ def __getitem__(self, key):
977977
return super().__getitem__(key)
978978

979979
def __contains__(self, k):
980+
if isinstance(k, Compiler):
981+
k = k.name
980982
return k in self.keys() or k.startswith('gcc-')
981983

982984

tests/test_arch.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

3-
from devito.arch.compiler import sniff_compiler_version, compiler_registry
3+
from devito import switchconfig, configuration
4+
from devito.arch.compiler import sniff_compiler_version, compiler_registry, GNUCompiler
45

56

67
@pytest.mark.parametrize("cc", [
@@ -15,3 +16,16 @@ def test_sniff_compiler_version(cc):
1516
@pytest.mark.parametrize("cc", ['gcc-4.9', 'gcc-11', 'gcc', 'gcc-14', 'gcc-123'])
1617
def test_gcc(cc):
1718
assert cc in compiler_registry
19+
20+
21+
def test_switcharch():
22+
old_compiler = configuration['compiler']
23+
with switchconfig(compiler='gcc-4.9'):
24+
tmp_comp = configuration['compiler']
25+
assert isinstance(tmp_comp, GNUCompiler)
26+
assert tmp_comp.suffix == '4.9'
27+
28+
tmp_comp = configuration['compiler']
29+
assert isinstance(tmp_comp, old_compiler.__class__)
30+
assert old_compiler.suffix == tmp_comp.suffix
31+
assert old_compiler.name == tmp_comp.name

0 commit comments

Comments
 (0)