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