|
| 1 | +import pytest |
| 2 | +from test_module_dependencies import ( |
| 3 | + module_class_map, |
| 4 | + parameterize_module_class, |
| 5 | + register_modules_and_simulate, |
| 6 | + resourcefilepath, |
| 7 | +) |
| 8 | +from test_module_dependencies import sim as get_simulation # to silence unused import warning |
| 9 | + |
| 10 | +from tlo.dependencies import ( |
| 11 | + get_all_dependencies, |
| 12 | + get_all_required_dependencies, |
| 13 | + get_dependencies_and_initialise, |
| 14 | +) |
| 15 | + |
| 16 | +sim = get_simulation # pytest fixture |
| 17 | + |
| 18 | +@pytest.mark.slow |
| 19 | +@parameterize_module_class |
| 20 | +def test_module_dependencies_complete(sim, module_class): |
| 21 | + """Check declared dependencies are sufficient for successful (short) simulation. |
| 22 | +
|
| 23 | + Dependencies here refers to the union of INIT_DEPENDENCIES and |
| 24 | + ADDITIONAL_DEPENDENCIES. |
| 25 | + """ |
| 26 | + try: |
| 27 | + # If this module is an 'alternative' to one or more other modules, exclude these |
| 28 | + # modules from being selected to avoid clashes with this module |
| 29 | + excluded_module_classes = { |
| 30 | + module_class_map[module_name] for module_name in module_class.ALTERNATIVE_TO |
| 31 | + } |
| 32 | + register_modules_and_simulate( |
| 33 | + sim, |
| 34 | + get_dependencies_and_initialise( |
| 35 | + module_class, |
| 36 | + module_class_map=module_class_map, |
| 37 | + get_dependencies=get_all_dependencies, |
| 38 | + excluded_module_classes=excluded_module_classes, |
| 39 | + resourcefilepath=resourcefilepath |
| 40 | + ), |
| 41 | + check_all_dependencies=True |
| 42 | + ) |
| 43 | + except Exception: |
| 44 | + all_dependencies = get_all_required_dependencies(module_class) |
| 45 | + pytest.fail( |
| 46 | + f"Module {module_class.__name__} appears to be missing dependencies " |
| 47 | + f"required to run simulation in the union of the INIT_DEPENDENCIES and " |
| 48 | + f"ADDITIONAL_DEPENDENCIES class attributes which is currently " |
| 49 | + f"{{{', '.join(all_dependencies)}}}." |
| 50 | + ) |
0 commit comments