Allow to write to unexisting directory

`ifcopenshell.write("/unexisting/path/model.ifc")` was failing without
throwing an error. It now works and a test ensure it works.
This commit is contained in:
CyrilWaechter
2022-12-19 01:44:40 +01:00
parent 88c9f15320
commit cabc91dd5e
2 changed files with 4 additions and 0 deletions
@@ -462,6 +462,7 @@ class file(object):
>>> model.write("path/to/model.anyextension", format=".ifcXML")
"""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
if format == None:
format = ifcopenshell.util.file.guess_format(path)
if format == ".ifcXML":
@@ -61,3 +61,6 @@ class TestWrite:
def test_write_anyextension_ifczip_ifcxml_format(self):
self.assert_model_is_written("model.anyextension", format=".ifcXML", zipped=True)
def test_write_to_non_existing_dir(self):
self.assert_model_is_written("tmp/model.ifczip")