From 68ccc4c8c48bd60dd4914281dc194a7997073f61 Mon Sep 17 00:00:00 2001 From: Joerg Henrichs Date: Wed, 20 Nov 2024 14:57:40 +1100 Subject: [PATCH] Minor updates to documentation and coding style. --- source/fab/tools/compiler_wrapper.py | 10 +++++++++- tests/unit_tests/tools/test_compiler.py | 14 +++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/source/fab/tools/compiler_wrapper.py b/source/fab/tools/compiler_wrapper.py index e54f98ea..ad76bfad 100644 --- a/source/fab/tools/compiler_wrapper.py +++ b/source/fab/tools/compiler_wrapper.py @@ -47,12 +47,20 @@ def __str__(self): return f"{type(self).__name__}({self._compiler.name})" def get_version(self) -> Tuple[int, ...]: - """ + """Determines the version of the compiler. The implementation in the + compiler wrapper additionally ensures that the wrapper compiler and + compiler wrapper report both the same version. This verifies that the + user's build environment is as expected. For example, this will check + if mpif90 from mpif90-ifort does indeed invoke ifort (and not e.g. + gfortran). + :returns: a tuple of at least 2 integers, representing the version e.g. (6, 10, 1) for version '6.10.1'. :raises RuntimeError: if the compiler was not found, or if it returned an unrecognised output from the version command. + :raises RuntimeError: if the compiler wrapper and wrapped compiler + have different version numbers. """ if self._version is not None: diff --git a/tests/unit_tests/tools/test_compiler.py b/tests/unit_tests/tools/test_compiler.py index 6bfcece7..c31e480e 100644 --- a/tests/unit_tests/tools/test_compiler.py +++ b/tests/unit_tests/tools/test_compiler.py @@ -642,15 +642,15 @@ def test_ifort_get_version_with_icc_string(): "0.5.1.", "0.5..1"]) def test_ifort_get_version_invalid_version(version): - '''Tests the icc class with an icc version string that contains an invalid - version number.''' + '''Tests the ifort class with an ifort version string that contains an + invalid version number.''' full_output = dedent(f""" - icc (ICC) {version} 20230609 - Copyright (C) 1985-2023 Intel Corporation. All rights reserved. + ifort (IFORT) {version} 20140422 + Copyright (C) 1985-2014 Intel Corporation. All rights reserved. """) - icc = Ifort() - with mock.patch.object(icc, "run", mock.Mock(return_value=full_output)): + ifort = Ifort() + with mock.patch.object(ifort, "run", mock.Mock(return_value=full_output)): with pytest.raises(RuntimeError) as err: - icc.get_version() + ifort.get_version() assert "Unexpected version output format for compiler" in str(err.value)