Skip to content

test: add unit tests for relative_import#5663

Open
eeshsaxena wants to merge 1 commit into
plotly:mainfrom
eeshsaxena:test/importers
Open

test: add unit tests for relative_import#5663
eeshsaxena wants to merge 1 commit into
plotly:mainfrom
eeshsaxena:test/importers

Conversation

@eeshsaxena

Copy link
Copy Markdown
Contributor

Description

_plotly_utils.importers.relative_import is the helper behind plotly's lazy
submodule imports - it returns the (__all__, __getattr__, __dir__) triple a
package assigns to enable PEP 562 lazy loading. It had no test coverage.

This adds tests/test_core/test_utils/test_importers.py covering:

  • __all__ listing the leaf names of the requested modules and classes
  • __getattr__ lazily importing a submodule
  • __getattr__ lazily importing a class off a submodule
  • __getattr__ raising AttributeError for an unknown name
  • __dir__ returning __all__

The tests use the stdlib collections package as a stable lazy-import target,
so they don't depend on plotly's own module layout. No source changes.

Verification

pytest tests/test_core/test_utils/test_importers.py - 5 passed. ruff check
/ ruff format --check clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant