Skip to content

Commit

Permalink
fix santoshphilip#245 by redirecting stderr to a tmp file rather than…
Browse files Browse the repository at this point in the history
… sys.stderr
  • Loading branch information
jamiebull1 authored and jamiebull1 committed Sep 14, 2019
1 parent 85a0271 commit bdb6db5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions eppy/runner/run_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import sys
import tempfile

from six import StringIO

try:
import multiprocessing as mp
except ImportError:
Expand Down Expand Up @@ -346,28 +348,32 @@ 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")
check_call(cmd)
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:
Expand Down
3 changes: 1 addition & 2 deletions eppy/tests/test_parse_error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import os
import shutil
import sys
Expand Down Expand Up @@ -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)
shutil.rmtree(rundir)
16 changes: 0 additions & 16 deletions eppy/tests/test_reproduce_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit bdb6db5

Please sign in to comment.