| 1 |
"""Tests for public API handling.""" |
| 2 |
|
| 3 |
from griffe import temporary_visited_module |
| 4 |
|
| 5 |
|
| 6 |
def test_not_detecting_imported_objects_as_public() -> None: |
| 7 |
"""Imported objects not listed in `__all__` must not be considered public.""" |
| 8 |
with temporary_visited_module("from abc import ABC\ndef func(): ...") as module: |
| 9 |
assert not module["ABC"].is_public |
| 10 |
assert module["func"].is_public |
| 11 |
|
| 12 |
|
| 13 |
def test_detecting_dunder_attributes_as_public() -> None: |
| 14 |
"""Dunder attributes (methods, etc.) must be considered public.""" |
| 15 |
with temporary_visited_module( |
| 16 |
""" |
| 17 |
def __getattr__(name): ... |
| 18 |
class A: |
| 19 |
def __init__(self): ... |
| 20 |
""", |
| 21 |
) as module: |
| 22 |
assert module["__getattr__"].is_public |
| 23 |
assert module["A.__init__"].is_public |