Skip to content

Commit

Permalink
Fix flake8 suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanwweber committed Apr 15, 2021
1 parent e897fa4 commit ca7133a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
63 changes: 42 additions & 21 deletions site_scons/buildutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@ class TestState(enum.IntEnum):
PASS = 0
FAIL = 1


class DefineDict:
"""
A dictionary-like object which generates appropriate preprocessor
Expand Down Expand Up @@ -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 ***
*****************************
Expand All @@ -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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -580,15 +598,16 @@ 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
option, its permitted values, default value, and current value
if different from the default.
"""

message = [textwrap.dedent("""
message = [textwrap.dedent(
"""
**************************************************
* Configuration options for building Cantera *
**************************************************
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/fortran/cantera.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

MODULE CANTERA

USE cantera_thermo
USE cantera_thermo
USE cantera_kinetics
USE cantera_transport
Expand Down Expand Up @@ -429,4 +428,3 @@ MODULE CANTERA
END INTERFACE write

END MODULE CANTERA

0 comments on commit ca7133a

Please sign in to comment.