Check that all submodules listed higher up in this file can be imported Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may simply need to be removed from the list (deprecation may or may not be needed - apply common sense).
()
| 441 | |
| 442 | |
| 443 | def test_api_importable(): |
| 444 | """ |
| 445 | Check that all submodules listed higher up in this file can be imported |
| 446 | |
| 447 | Note that if a PRIVATE_BUT_PRESENT_MODULES entry goes missing, it may |
| 448 | simply need to be removed from the list (deprecation may or may not be |
| 449 | needed - apply common sense). |
| 450 | """ |
| 451 | def check_importable(module_name): |
| 452 | try: |
| 453 | importlib.import_module(module_name) |
| 454 | except (ImportError, AttributeError): |
| 455 | return False |
| 456 | |
| 457 | return True |
| 458 | |
| 459 | module_names = [] |
| 460 | for module_name in PUBLIC_MODULES: |
| 461 | if not check_importable(module_name): |
| 462 | module_names.append(module_name) |
| 463 | |
| 464 | if module_names: |
| 465 | raise AssertionError("Modules in the public API that cannot be " |
| 466 | "imported: {}".format(module_names)) |
| 467 | |
| 468 | for module_name in PUBLIC_ALIASED_MODULES: |
| 469 | try: |
| 470 | eval(module_name) |
| 471 | except AttributeError: |
| 472 | module_names.append(module_name) |
| 473 | |
| 474 | if module_names: |
| 475 | raise AssertionError("Modules in the public API that were not " |
| 476 | "found: {}".format(module_names)) |
| 477 | |
| 478 | with warnings.catch_warnings(record=True) as w: |
| 479 | warnings.filterwarnings('always', category=DeprecationWarning) |
| 480 | warnings.filterwarnings('always', category=ImportWarning) |
| 481 | for module_name in PRIVATE_BUT_PRESENT_MODULES: |
| 482 | if not check_importable(module_name): |
| 483 | module_names.append(module_name) |
| 484 | |
| 485 | if module_names: |
| 486 | raise AssertionError("Modules that are not really public but looked " |
| 487 | "public and can not be imported: " |
| 488 | "{}".format(module_names)) |
| 489 | |
| 490 | |
| 491 | @pytest.mark.xfail( |
nothing calls this directly
no test coverage detected