Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions khiops/core/internals/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ def read(self, size=None):
return local_file.read(size)

def write(self, data):
directory = os.path.dirname(self.path)
if len(directory) > 0 and not os.path.isdir(directory):
os.makedirs(directory)
with open(self.path, "wb") as output_file:
output_file.write(data)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ def test_dictionary(self):
ref_kdic = os.path.join(ref_kdic_dir, f"{dictionary}.kdic")
ref_kdicj = os.path.join(ref_kdicj_dir, f"{dictionary}.kdicj")
output_kdic = os.path.join(output_kdic_dir, f"{dictionary}.kdic")
output_kdic_in_a_new_folder = os.path.join(
output_kdic_dir, "missing_folder", f"{dictionary}.kdic"
)
copy_output_kdic = os.path.join(copy_output_kdic_dir, f"{dictionary}.kdic")

with self.subTest(dictionary=dictionary):
if dictionary in dictionaries_warn:
with self.assertWarns(UserWarning):
Expand All @@ -312,6 +316,8 @@ def test_dictionary(self):
domain = kh.read_dictionary_file(ref_kdicj)
domain.export_khiops_dictionary_file(output_kdic)
assert_files_equal(self, ref_kdic, output_kdic)
domain.export_khiops_dictionary_file(output_kdic_in_a_new_folder)
assert_files_equal(self, ref_kdic, output_kdic_in_a_new_folder)

domain_copy = domain.copy()
domain_copy.export_khiops_dictionary_file(copy_output_kdic)
Expand Down
Loading