From bdb6db59e5c1e22bb589ba6f0e5a360fc9d1a41f Mon Sep 17 00:00:00 2001 From: jamiebull1 <^tA2nq%K&F8TB&At> Date: Sat, 14 Sep 2019 15:24:42 +0200 Subject: [PATCH] fix #245 by redirecting stderr to a tmp file rather than sys.stderr --- .coveragerc | 2 +- eppy/runner/run_functions.py | 14 ++++++++++---- eppy/tests/test_parse_error.py | 3 +-- eppy/tests/test_reproduce_bugs.py | 16 ---------------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/.coveragerc b/.coveragerc index f50c77ba..88961a31 100644 --- a/.coveragerc +++ b/.coveragerc @@ -3,6 +3,6 @@ # don't report on coverage of files in the tests dir itself omit = venv/* - eppy/tests/** + eppy/tests/* eppy/iddv* eppy/Main_Tutorial.py \ No newline at end of file diff --git a/eppy/runner/run_functions.py b/eppy/runner/run_functions.py index 0dc44e8d..5aa5fb2d 100644 --- a/eppy/runner/run_functions.py +++ b/eppy/runner/run_functions.py @@ -20,6 +20,8 @@ import sys import tempfile +from six import StringIO + try: import multiprocessing as mp except ImportError: @@ -346,6 +348,9 @@ def run( cmd.extend([args[arg]]) cmd.extend([idf_path]) + # send stdout to tmp filehandle to avoid issue #245 + tmp_err = StringIO() + sys.stderr = tmp_err try: if verbose == "v": print("\r\n" + " ".join(cmd) + "\r\n") @@ -353,21 +358,22 @@ def run( elif verbose == "q": check_call(cmd, stdout=open(os.devnull, "w")) except CalledProcessError: - message = parse_error(output_dir) + message = parse_error(tmp_err, output_dir) raise EnergyPlusRunError(message) finally: + sys.stderr = sys.__stderr__ os.chdir(cwd) return "OK" -def parse_error(output_dir): +def parse_error(tmp_err, output_dir): """Add contents of stderr and eplusout.err and put it in the exception message. + :param tmp_err: file-like :param output_dir: str :return: str """ - sys.stderr.seek(0) - std_err = sys.stderr.read().decode("utf-8") + std_err = tmp_err.getvalue() err_file = os.path.join(output_dir, "eplusout.err") if os.path.isfile(err_file): with open(err_file, "r") as f: diff --git a/eppy/tests/test_parse_error.py b/eppy/tests/test_parse_error.py index 13e894bc..cbc5b0dc 100644 --- a/eppy/tests/test_parse_error.py +++ b/eppy/tests/test_parse_error.py @@ -1,4 +1,3 @@ - import os import shutil import sys @@ -32,4 +31,4 @@ def test_capture_real_error(test_idf): except EnergyPlusRunError as e: assert "invalid Heating Setpoint Temperature Schedule" in str(e) finally: - shutil.rmtree(rundir) \ No newline at end of file + shutil.rmtree(rundir) diff --git a/eppy/tests/test_reproduce_bugs.py b/eppy/tests/test_reproduce_bugs.py index cc84fd1f..fefcfc8c 100644 --- a/eppy/tests/test_reproduce_bugs.py +++ b/eppy/tests/test_reproduce_bugs.py @@ -45,19 +45,3 @@ def test_reproduce_run_issue(): raise finally: shutil.rmtree("test_dir", ignore_errors=True) - - -@pytest.mark.xfail -@pytest.mark.parametrize(["people"], [["0.753473729169681"], [0.753473729169681]]) -def test_linux_rounding(base_idf, people): - assert str(people) == "0.753473729169681" - obj = base_idf.newidfobject( - "People", - Name="Test People", - Number_of_People_Calculation_Method="People/Area", - People_per_Zone_Floor_Area=people, - ) - assert obj.People_per_Zone_Floor_Area == people - idf = IDF() - idf.initreadtxt(base_idf.idfstr()) - assert idf.idfstr() == base_idf.idfstr()