|
7 | 7 |
|
8 | 8 |
|
9 | 9 | try: |
10 | | - from executorlib.task_scheduler.file.backend import backend_execute_task_in_file |
| 10 | + from executorlib.task_scheduler.file.backend import backend_execute_task_in_file, backend_write_file |
11 | 11 | from executorlib.task_scheduler.file.shared import _check_task_output, _convert_args_and_kwargs, FutureItem |
12 | 12 | from executorlib.standalone.hdf import dump, get_runtime |
13 | 13 | from executorlib.standalone.serialize import serialize_funct |
@@ -64,6 +64,30 @@ def test_execute_function_mixed(self): |
64 | 64 | self.assertTrue(future_file_obj.done()) |
65 | 65 | self.assertEqual(future_file_obj.result(), 3) |
66 | 66 |
|
| 67 | + def test_backend_write_file(self): |
| 68 | + cache_directory = os.path.abspath("executorlib_cache") |
| 69 | + os.makedirs(cache_directory, exist_ok=True) |
| 70 | + file_name = os.path.join(cache_directory, "test_file_i.h5") |
| 71 | + dump(file_name=file_name, data_dict={"fn": my_funct, "args": [1], "kwargs": {"b": 2}}) |
| 72 | + backend_write_file(file_name=file_name, output={"result": 3}, runtime=0.1) |
| 73 | + future_file_obj = FutureItem( |
| 74 | + file_name=os.path.join(cache_directory, "test_file_o.h5") |
| 75 | + ) |
| 76 | + self.assertTrue(future_file_obj.done()) |
| 77 | + self.assertEqual(future_file_obj.result(), 3) |
| 78 | + |
| 79 | + def test_backend_write_file_serialization_error(self): |
| 80 | + cache_directory = os.path.abspath("executorlib_cache") |
| 81 | + os.makedirs(cache_directory, exist_ok=True) |
| 82 | + file_name = os.path.join(cache_directory, "test_file_i.h5") |
| 83 | + dump(file_name=file_name, data_dict={"fn": my_funct, "args": [1], "kwargs": {"b": 2}}) |
| 84 | + backend_write_file(file_name=file_name, output={"result": Future()}, runtime=0.1) |
| 85 | + future_file_obj = FutureItem( |
| 86 | + file_name=os.path.join(cache_directory, "test_file_o.h5") |
| 87 | + ) |
| 88 | + with self.assertRaises(Exception): |
| 89 | + future_file_obj.result() |
| 90 | + |
67 | 91 | def test_execute_function_mixed_selector_convert(self): |
68 | 92 | cache_directory = os.path.abspath("executorlib_cache") |
69 | 93 | os.makedirs(cache_directory, exist_ok=True) |
|
0 commit comments