|
| 1 | +import unittest |
| 2 | + |
| 3 | +from executorlib import get_cache_data |
| 4 | +from executorlib.api import TestClusterExecutor |
| 5 | +from executorlib.standalone.serialize import cloudpickle_register |
| 6 | + |
| 7 | +try: |
| 8 | + import h5py |
| 9 | + |
| 10 | + skip_h5py_test = False |
| 11 | +except ImportError: |
| 12 | + skip_h5py_test = True |
| 13 | + |
| 14 | + |
| 15 | +def foo(x): |
| 16 | + return x + 1 |
| 17 | + |
| 18 | + |
| 19 | +@unittest.skipIf( |
| 20 | + skip_h5py_test, "h5py is not installed, so the h5io tests are skipped." |
| 21 | +) |
| 22 | +class TestTestClusterExecutor(unittest.TestCase): |
| 23 | + def test_cache_dir(self): |
| 24 | + with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe: |
| 25 | + cloudpickle_register(ind=1) |
| 26 | + future = exe.submit( |
| 27 | + foo, |
| 28 | + 1, |
| 29 | + resource_dict={ |
| 30 | + "cache_directory": "rather_this_dir", |
| 31 | + "cache_key": "foo", |
| 32 | + }, |
| 33 | + ) |
| 34 | + self.assertEqual(future.result(), 2) |
| 35 | + cache_lst = get_cache_data(cache_directory="not_this_dir") |
| 36 | + self.assertEqual(len(cache_lst), 0) |
| 37 | + cache_lst = get_cache_data(cache_directory="rather_this_dir") |
| 38 | + self.assertEqual(len(cache_lst), 1) |
| 39 | + with TestClusterExecutor(cache_directory="not_this_dir", resource_dict={}) as exe: |
| 40 | + cloudpickle_register(ind=1) |
| 41 | + future = exe.submit( |
| 42 | + foo, |
| 43 | + 1, |
| 44 | + resource_dict={ |
| 45 | + "cache_directory": "rather_this_dir", |
| 46 | + "cache_key": "foo", |
| 47 | + }, |
| 48 | + ) |
| 49 | + self.assertEqual(future.result(), 2) |
| 50 | + cache_lst = get_cache_data(cache_directory="not_this_dir") |
| 51 | + self.assertEqual(len(cache_lst), 0) |
| 52 | + cache_lst = get_cache_data(cache_directory="rather_this_dir") |
| 53 | + self.assertEqual(len(cache_lst), 1) |
0 commit comments