Method checking all objects. The pkgutil-based method in `test_all_modules_are_expected` does not catch imports into a namespace, only filenames. So this test is more thorough, and checks this like: import .lib.scimath as emath To check if something in a module is (effect
()
| 389 | |
| 390 | |
| 391 | def test_all_modules_are_expected_2(): |
| 392 | """ |
| 393 | Method checking all objects. The pkgutil-based method in |
| 394 | `test_all_modules_are_expected` does not catch imports into a namespace, |
| 395 | only filenames. So this test is more thorough, and checks this like: |
| 396 | |
| 397 | import .lib.scimath as emath |
| 398 | |
| 399 | To check if something in a module is (effectively) public, one can check if |
| 400 | there's anything in that namespace that's a public function/object but is |
| 401 | not exposed in a higher-level namespace. For example for a `numpy.lib` |
| 402 | submodule:: |
| 403 | |
| 404 | mod = np.lib.mixins |
| 405 | for obj in mod.__all__: |
| 406 | if obj in np.__all__: |
| 407 | continue |
| 408 | elif obj in np.lib.__all__: |
| 409 | continue |
| 410 | |
| 411 | else: |
| 412 | print(obj) |
| 413 | |
| 414 | """ |
| 415 | |
| 416 | def find_unexpected_members(mod_name): |
| 417 | members = [] |
| 418 | module = importlib.import_module(mod_name) |
| 419 | if hasattr(module, '__all__'): |
| 420 | objnames = module.__all__ |
| 421 | else: |
| 422 | objnames = dir(module) |
| 423 | |
| 424 | for objname in objnames: |
| 425 | if not objname.startswith('_'): |
| 426 | fullobjname = mod_name + '.' + objname |
| 427 | if isinstance(getattr(module, objname), types.ModuleType): |
| 428 | if is_unexpected(fullobjname): |
| 429 | if fullobjname not in SKIP_LIST_2: |
| 430 | members.append(fullobjname) |
| 431 | |
| 432 | return members |
| 433 | |
| 434 | unexpected_members = find_unexpected_members("numpy") |
| 435 | for modname in PUBLIC_MODULES: |
| 436 | unexpected_members.extend(find_unexpected_members(modname)) |
| 437 | |
| 438 | if unexpected_members: |
| 439 | raise AssertionError("Found unexpected object(s) that look like " |
| 440 | "modules: {}".format(unexpected_members)) |
| 441 | |
| 442 | |
| 443 | def test_api_importable(): |
nothing calls this directly
no test coverage detected