diff --git a/site_scons/buildutils.py b/site_scons/buildutils.py index 370ac455153..6cea0004ee1 100644 --- a/site_scons/buildutils.py +++ b/site_scons/buildutils.py @@ -43,6 +43,7 @@ def __init__(self, low: int, high: int) -> None: self._low = low self._high = high super().__init__() + def filter(self, record: logging.LogRecord) -> bool: if self._low <= record.levelno < self._high: return True @@ -83,6 +84,7 @@ class TestState(enum.IntEnum): PASS = 0 FAIL = 1 + class DefineDict: """ A dictionary-like object which generates appropriate preprocessor @@ -147,7 +149,8 @@ def print_report(self, target, source, env): "failed": sum(self.failed.values()), "skipped": len(self.tests) } - message = textwrap.dedent("""\ + message = textwrap.dedent( + """ ***************************** *** Testing Summary *** ***************************** @@ -159,11 +162,12 @@ def print_report(self, target, source, env): ).format_map(values) if self.failed: message = (message + "Failed tests:" + - ''.join('\n - ' + n for n in self.failed) + - '\n') + ''.join('\n - ' + n for n in self.failed) + + '\n') message = message + "*****************************" if self.failed: - logger.error("One or more tests failed.\n" + message, extra={"print_level": False}) + logger.error("One or more tests failed.\n" + message, + extra={"print_level": False}) sys.exit(1) else: logger.info(message, extra={"print_level": False}) @@ -225,14 +229,16 @@ def regression_test(target, source, env): comparisons.append((Path(blessed_name), output_name)) for blessed, output in comparisons: - logger.info(f"Comparing '{blessed}' with '{output}'", extra={"print_level": False}) + logger.info(f"Comparing '{blessed}' with '{output}'", + extra={"print_level": False}) d = compare_files(env, dir.joinpath(blessed), dir.joinpath(output)) if d: logger.error("FAILED", extra={"print_level": False}) diff |= d for blessed, output in env["test_profiles"]: - logger.info(f"Comparing '{blessed}' with '{output}'", extra={"print_level": False}) + logger.info(f"Comparing '{blessed}' with '{output}'", + extra={"print_level": False}) d = compare_profiles(env, dir.joinpath(blessed), dir.joinpath(output)) if d: logger.error("FAILED", extra={"print_level": False}) @@ -314,7 +320,6 @@ def compare_text_files(env, file1: Path, file2: Path) -> TestState: # String representations match, so replacement is unnecessary continue - try: num1 = float(float_1[1]) num2 = float(float_2[1]) @@ -354,7 +359,18 @@ def compare_text_files(env, file1: Path, file2: Path) -> TestState: def get_precision(number: str) -> int: - """Return the integer representing the power of 10 of the least significant digit in the number represented as a string.""" + """Return the precision of the least significant digit in a number. + + Return an integer representing the power of 10 of the least significant digit in + ``number``, which must be a string. + + Patterns to consider: + 123 -> 0 + 123.45 -> -2 + 123.45e6 -> 4 + 123e4 -> 4 + """ + number = number.lower() if "e" in number: number, exponent = number.split("e") @@ -443,9 +459,8 @@ def compare_profiles(env, ref_file, sample_file): it = np.nditer((abserr, relerr, xerr), flags=["multi_index"]) for a, r, x in it: i, j = it.multi_index - bad.append((reference[0, j], i, reference[i,j], comp[i,j], a, r, x)) + bad.append((reference[0, j], i, reference[i, j], comp[i, j], a, r, x)) - # TODO: Fix line lengths here footer = [] maxrows = 10 if len(bad) > maxrows: @@ -454,12 +469,15 @@ def compare_profiles(env, ref_file, sample_file): bad = bad[:maxrows] if bad: - header = [ - "Failed series comparisons:", - "coordinate comp. reference val test value abs. err rel. err pos. err", - "---------- ----- -------------- -------------- --------- --------- ---------" - ] - logger.error("\n".join(header + [template.format(*row) for row in bad] + footer), extra={"print_level": False}) + header = ["Failed series comparisons:"] + header.append("coordinate comp. reference val test value " + "abs. err rel. err pos. err") + header.append("---------- ----- -------------- -------------- " + "--------- --------- ---------") + logger.error( + "\n".join(header + [template.format(*row) for row in bad] + footer), + extra={"print_level": False}, + ) return TestState.FAIL else: return TestState.PASS @@ -515,7 +533,7 @@ def compare_csv_files(env, file1: Path, file2: Path) -> TestState: return TestState.FAIL tol = env["test_csv_tolerance"] - if maxerror < tol: # Threshold based on printing 6 digits in the CSV file + if maxerror < tol: # Threshold based on printing 6 digits in the CSV file return TestState.PASS n_fail = np.sum(relerror > tol) @@ -580,7 +598,7 @@ def which(program: str) -> bool: return False -def help(env: "SCEnvironment.Environment", options: "SCVariables.Variables") -> None: +def help(env, options): """Print help about configuration options and exit. Print a nicely formatted description of a SCons configuration @@ -588,7 +606,8 @@ def help(env: "SCEnvironment.Environment", options: "SCVariables.Variables") -> if different from the default. """ - message = [textwrap.dedent(""" + message = [textwrap.dedent( + """ ************************************************** * Configuration options for building Cantera * ************************************************** @@ -689,9 +708,9 @@ def ipdb(): where this function is called. """ from IPython.core.debugger import Pdb - from IPython.core import ipapi + from IPython.core import getipython - ip = ipapi.get() + ip = getipython.get_ipython() def_colors = ip.colors Pdb(def_colors).set_trace(sys._getframe().f_back) @@ -752,7 +771,9 @@ def get_command_output(cmd, *args): ) return data.stdout.strip() + # Monkey patch for SCons Cygwin bug # See https://github.com/SCons/scons/issues/2664 if "cygwin" in platform.system().lower(): + import SCons.Node.FS SCons.Node.FS._my_normcase = lambda x: x diff --git a/src/fortran/cantera.f90 b/src/fortran/cantera.f90 index 1cb17e61bce..eba0e2c7375 100644 --- a/src/fortran/cantera.f90 +++ b/src/fortran/cantera.f90 @@ -8,7 +8,6 @@ MODULE CANTERA - USE cantera_thermo USE cantera_thermo USE cantera_kinetics USE cantera_transport @@ -429,4 +428,3 @@ MODULE CANTERA END INTERFACE write END MODULE CANTERA -