|
| 1 | +import unittest |
| 2 | +from unittest.mock import MagicMock, patch |
| 3 | + |
| 4 | +from dpgen.auto_test.common_prop import run_property |
| 5 | + |
| 6 | + |
| 7 | +class TestRunProperty(unittest.TestCase): |
| 8 | + @patch( |
| 9 | + "dpgen.auto_test.common_prop.convert_mdata", side_effect=lambda data, _: data |
| 10 | + ) |
| 11 | + @patch("dpgen.auto_test.common_prop.make_calculator") |
| 12 | + @patch("dpgen.auto_test.common_prop.util.collect_task") |
| 13 | + @patch("dpgen.auto_test.common_prop.glob.glob") |
| 14 | + @patch("dpgen.auto_test.common_prop.Pool") |
| 15 | + def test_only_unfinished_tasks_are_sent_to_worker( |
| 16 | + self, pool_class, glob_files, collect_task, make_calculator, _convert_mdata |
| 17 | + ): |
| 18 | + task_paths = ["/work/task.000000", "/work/task.000001"] |
| 19 | + glob_files.side_effect = lambda pattern: ( |
| 20 | + task_paths if "task.[0-9]*[0-9]" in pattern else ["conf"] |
| 21 | + ) |
| 22 | + collect_task.return_value = ["task.000001"] |
| 23 | + |
| 24 | + calculator = MagicMock() |
| 25 | + calculator.forward_files.return_value = [] |
| 26 | + calculator.forward_common_files.return_value = [] |
| 27 | + calculator.backward_files.return_value = [] |
| 28 | + make_calculator.return_value = calculator |
| 29 | + |
| 30 | + pool = MagicMock() |
| 31 | + result = MagicMock() |
| 32 | + result.successful.return_value = True |
| 33 | + pool.apply_async.return_value = result |
| 34 | + pool_class.return_value = pool |
| 35 | + |
| 36 | + run_property( |
| 37 | + ["conf"], |
| 38 | + {"type": "vasp"}, |
| 39 | + [{"type": "eos"}], |
| 40 | + {}, |
| 41 | + ) |
| 42 | + |
| 43 | + worker_args = pool.apply_async.call_args.args[1] |
| 44 | + self.assertEqual(worker_args[1], ["task.000001"]) |
| 45 | + |
| 46 | + |
| 47 | +if __name__ == "__main__": |
| 48 | + unittest.main() |
0 commit comments