Skip to content

Commit

Permalink
Merge branch 'develop' into i406_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Philip committed Dec 3, 2022
2 parents 06cf1c0 + 9964b12 commit ea4bb01
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions eppy/modeleditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,9 @@ def save(self, filename=None, lineendings="default", encoding="latin-1"):
is compatible with the EnergyPlus IDFEditor.
"""
if self.idfabsname is None and isinstance(self.idfname, str):
# this happens when the user sets self.idfname to an in-memory idf
self.idfabsname = os.path.abspath(self.idfname)
if filename is None:
filename = self.idfabsname
s = self.idfstr()
Expand Down Expand Up @@ -1023,6 +1026,13 @@ def save(self, filename=None, lineendings="default", encoding="latin-1"):
except TypeError:
filename.write(s.decode(encoding))

try:
pass
except Exception as e:
raise e
else:
pass

def saveas(self, filename, lineendings="default", encoding="latin-1"):
"""Save the IDF as a text file with the filename passed.
Expand Down
19 changes: 18 additions & 1 deletion tests/test_modeleditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
# =======================================================================
"""py.test for modeleditor"""
"""Main py.test modeleditor. Other tests are in test_modeleditor.py"""

from __future__ import absolute_import
from __future__ import division
Expand Down Expand Up @@ -690,3 +690,20 @@ def test_copyidf():
idf = IDF(StringIO(idftxt))
new_idf = idf.copyidf()
assert idf.idfstr() == new_idf.idfstr()


def test_name_and_save_inmemoryidf():
"""py.test to name and save a file that is created in memory"""
# fixing and testing an error from user documentation code
# fix for issue #408

idftxt = "VERSION, 7.3;"
fhandle = StringIO(idftxt)
idf_notemptyfile = IDF(fhandle)
idf_notemptyfile.idfname = "notemptyfile_randomchars_laksdfjl.idf"
try:
idf_notemptyfile.save()
except Exception as e:
raise e
finally:
os.remove("notemptyfile_randomchars_laksdfjl.idf")
2 changes: 1 addition & 1 deletion tests/test_modeleditor1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
# =======================================================================
"""py.test for some functions of modeleditor"""
"""py.test for some functions of modeleditor. Other tests are in test_modeleditor.py"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
Expand Down

0 comments on commit ea4bb01

Please sign in to comment.