From e693f8b1f676468416445d4ca2401a1af6cd3883 Mon Sep 17 00:00:00 2001 From: James Douglass Date: Tue, 21 Apr 2020 11:01:43 -0700 Subject: [PATCH] Catching an unhandled SystemError occurring in some tests. RE:#72 --- src/natcap/invest/utils.py | 14 +++++++++++--- ui_tests/test_cli_gui.py | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/natcap/invest/utils.py b/src/natcap/invest/utils.py index fc0e1b57d..e7b4d87bd 100644 --- a/src/natcap/invest/utils.py +++ b/src/natcap/invest/utils.py @@ -174,8 +174,16 @@ def log_to_file(logfile, exclude_threads=None, logging_level=logging.NOTSET, Returns: ``None``""" - if os.path.exists(logfile): - LOGGER.warn('Logfile %s exists and will be overwritten', logfile) + try: + if os.path.exists(logfile): + LOGGER.warn('Logfile %s exists and will be overwritten', logfile) + except SystemError: + # This started happening in Windows tests: + # SystemError: returned NULL without + # setting an error + # Looking at https://bugs.python.org/issue28040#msg276223, this might + # be a low-level python error. + pass handler = logging.FileHandler(logfile, 'w', encoding='UTF-8') formatter = logging.Formatter(log_fmt, date_fmt) @@ -459,7 +467,7 @@ def build_lookup_from_csv( table = pandas.read_csv( table_path, sep=None, engine='python', encoding=encoding) header_row = list(table) - + if to_lower: key_field = key_field.lower() header_row = [ diff --git a/ui_tests/test_cli_gui.py b/ui_tests/test_cli_gui.py index ff2863cec..87b137d05 100644 --- a/ui_tests/test_cli_gui.py +++ b/ui_tests/test_cli_gui.py @@ -16,7 +16,6 @@ class CLIGUITests(unittest.TestCase): def test_run_model(self): """CLI-GUI: Run a model GUI through the cli.""" from natcap.invest import cli - from natcap.invest import delineateit parameter_set_path = os.path.join( os.path.dirname(__file__), '..', 'data', 'invest-test-data', 'fisheries', 'spiny_lobster_belize.invs.json')