MCPcopy
hub / github.com/pydantic/pydantic / test_public_internal

Function test_public_internal

tests/test_exports.py:33–66  ·  view source on GitHub ↗

check we don't make anything from _internal public

()

Source from the content-addressed store, hash-verified

31@pytest.mark.thread_unsafe
32@pytest.mark.filterwarnings('ignore::DeprecationWarning')
33def test_public_internal():
34 """
35 check we don't make anything from _internal public
36 """
37 public_internal_attributes = []
38
39 def _test_file(file: Path, module_name: str):
40 if file.name != '__init__.py' and not file.name.startswith('_'):
41 module = sys.modules.get(module_name)
42 if module is None:
43 spec = importlib.util.spec_from_file_location(module_name, str(file))
44 module = importlib.util.module_from_spec(spec)
45 sys.modules[module_name] = module
46 try:
47 spec.loader.exec_module(module)
48 except ImportError:
49 return
50
51 for name, attr in vars(module).items():
52 if not name.startswith('_'):
53 attr_module = getattr(attr, '__module__', '')
54 if attr_module.startswith('pydantic._internal'):
55 public_internal_attributes.append(f'{module.__name__}:{name} from {attr_module}')
56
57 pydantic_files = (Path(__file__).parent.parent / 'pydantic').glob('*.py')
58 experimental_files = (Path(__file__).parent.parent / 'pydantic' / 'experimental').glob('*.py')
59
60 for file in pydantic_files:
61 _test_file(file, f'pydantic.{file.stem}')
62 for file in experimental_files:
63 _test_file(file, f'pydantic.experimental.{file.stem}')
64
65 if public_internal_attributes:
66 pytest.fail('The following should not be publicly accessible:\n ' + '\n '.join(public_internal_attributes))
67
68
69# language=Python

Callers

nothing calls this directly

Calls 2

_test_fileFunction · 0.85
failMethod · 0.80

Tested by

no test coverage detected