Skip to content

Commit cfd7cab

Browse files
Handle TclError that percolates indirectly as TypeError in HTML output file test NREL#365
1 parent 797fd94 commit cfd7cab

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/geophires_x/MatplotlibUtils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ def plt_subplots(**kw_args) -> Any:
3636

3737
def _handle_tcl_error_on_windows_github_actions(e) -> None:
3838
# Can't import TclError directly since Python is not configured for Tk on all systems
39-
is_tcl_error = e.__class__.__name__ == 'TclError'
39+
tcl_error_name = 'TclError'
40+
is_tcl_error = e.__class__.__name__ == tcl_error_name
4041

41-
if os.name == 'nt' and 'TOXPYTHON' in os.environ:
42-
_logger.warning(f'Ignoring TclError when attempting to show plot '
42+
if is_tcl_error and os.name == 'nt' and 'TOXPYTHON' in os.environ:
43+
_logger.warning(f'Ignoring {tcl_error_name} when attempting to show plot '
4344
f'since we appear to be running on Windows in GitHub Actions ({str(e)})')
4445
else:
4546
raise e

tests/geophires_x_tests/test_outputs.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import sys
34
import tempfile
@@ -8,22 +9,33 @@
89
from geophires_x_client import GeophiresXClient
910
from tests.base_test_case import BaseTestCase
1011

12+
_log = logging.getLogger(__name__)
13+
1114

1215
class OutputsTestCase(BaseTestCase):
1316

1417
def test_html_output_file(self):
1518
html_path = Path(tempfile.gettempdir(), 'example12_DH.html').absolute()
16-
GeophiresXClient().get_geophires_result(
17-
GeophiresInputParameters(
18-
from_file_path=self._get_test_file_path('../examples/example12_DH.txt'),
19-
params={'HTML Output File': str(html_path)},
19+
try:
20+
GeophiresXClient().get_geophires_result(
21+
GeophiresInputParameters(
22+
from_file_path=self._get_test_file_path('../examples/example12_DH.txt'),
23+
params={'HTML Output File': str(html_path)},
24+
)
2025
)
21-
)
22-
self.assertTrue(html_path.exists())
23-
with open(html_path, encoding='UTF-8') as f:
24-
html_content = f.read()
25-
self.assertIn('***CASE REPORT***', html_content)
26-
# TODO expand test to assert more about output HTML
26+
27+
self.assertTrue(html_path.exists())
28+
with open(html_path, encoding='UTF-8') as f:
29+
html_content = f.read()
30+
self.assertIn('***CASE REPORT***', html_content)
31+
# TODO expand test to assert more about output HTML
32+
except TypeError as te:
33+
if os.name == 'nt' and 'TOXPYTHON' in os.environ:
34+
# https://github.com/NREL/GEOPHIRES-X/issues/365
35+
_log.warning(
36+
f'Ignoring TypeError while testing HTML output file '
37+
f'since we appear to be running on Windows in GitHub Actions ({te!s})'
38+
)
2739

2840
def test_relative_output_file_path(self):
2941
input_file = GeophiresInputParameters({'HTML Output File': 'foo.html'}).as_file_path()

0 commit comments

Comments
 (0)