|
10 | 10 | import json |
11 | 11 | import math |
12 | 12 | import os |
| 13 | +import pathlib |
13 | 14 | import shutil |
14 | 15 | import tempfile |
15 | 16 | import textwrap |
|
22 | 23 |
|
23 | 24 | import khiops |
24 | 25 | import khiops.core as kh |
| 26 | +import khiops.core.internals.filesystems as fs |
25 | 27 | from khiops.core import KhiopsRuntimeError |
26 | 28 | from khiops.core.internals.io import KhiopsOutputWriter |
27 | 29 | from khiops.core.internals.runner import KhiopsLocalRunner, KhiopsRunner |
@@ -3186,5 +3188,40 @@ def test_raise_exception_on_error_case_without_a_message(self): |
3186 | 3188 | self.assertEqual(output_msg, expected_msg) |
3187 | 3189 |
|
3188 | 3190 |
|
| 3191 | +class LocalFileSystemTests(unittest.TestCase): |
| 3192 | + """Test the methods of the `LocalFileSystem`""" |
| 3193 | + |
| 3194 | + def setUp(self): |
| 3195 | + self.current_dir = os.getcwd() # save the current directory |
| 3196 | + |
| 3197 | + def test_copy_from_local(self): |
| 3198 | + """Ensure fs.copy_from_local behaves as expected""" |
| 3199 | + |
| 3200 | + tmp_dir = "/tmp" |
| 3201 | + os.chdir(tmp_dir) # folder location of the target files |
| 3202 | + # target file names that will be created |
| 3203 | + target_file_name1 = "khiops-python-unit-test-target1.txt" |
| 3204 | + target_file_name2 = "khiops-python-unit-test-target2.txt" |
| 3205 | + with tempfile.NamedTemporaryFile( |
| 3206 | + prefix="khiops-python-unit-test-source", dir=tmp_dir |
| 3207 | + ) as tmp_file_source: |
| 3208 | + try: |
| 3209 | + fs.copy_from_local(target_file_name1, tmp_file_source.name) |
| 3210 | + fs.copy_from_local(f"./{target_file_name2}", tmp_file_source.name) |
| 3211 | + fs.copy_from_local( |
| 3212 | + "./created_folder/khiops-python-unit-test-target3.txt", |
| 3213 | + tmp_file_source.name, |
| 3214 | + ) |
| 3215 | + except FileNotFoundError as exc: |
| 3216 | + self.fail(f"'copy_from_local' failed unexpectedly : {str(exc)}") |
| 3217 | + finally: |
| 3218 | + pathlib.Path(target_file_name1).unlink(missing_ok=True) |
| 3219 | + pathlib.Path(target_file_name1).unlink(missing_ok=True) |
| 3220 | + shutil.rmtree("./created_folder/", ignore_errors=True) |
| 3221 | + |
| 3222 | + def tearDown(self): |
| 3223 | + os.chdir(self.current_dir) # restore the current directory |
| 3224 | + |
| 3225 | + |
3189 | 3226 | if __name__ == "__main__": |
3190 | 3227 | unittest.main() |
0 commit comments