Skip to content

test: add unit tests for image_array_to_data_uri#5657

Open
eeshsaxena wants to merge 1 commit into
plotly:mainfrom
eeshsaxena:test/data-utils
Open

test: add unit tests for image_array_to_data_uri#5657
eeshsaxena wants to merge 1 commit into
plotly:mainfrom
eeshsaxena:test/data-utils

Conversation

@eeshsaxena

Copy link
Copy Markdown

Description

_plotly_utils.data_utils.image_array_to_data_uri converts a numpy uint8
image array into a base64 PNG/JPG data URI. It had no direct test coverage.

This adds tests/test_optional/test_utils/test_data_utils.py covering:

  • greyscale (2D), RGB and RGBA arrays each producing a PNG data URI
  • ValueError on out-of-range compression (-1 and 10)
  • ValueError on an invalid image shape
  • ValueError when requesting jpg with a non-PIL backend

The tests use the pypng backend so they do not require Pillow. No source
changes.

Verification

pytest tests/test_optional/test_utils/test_data_utils.py - 7 passed.
ruff check / ruff format --check clean.

@emilykl emilykl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eeshsaxena Thanks for the PR!

Can you move this test file to tests/test_plotly_utils/test_data_utils.py so that it lives with the rest of the _plotly_utils tests?

Could you also update the first 3 tests to verify the contents of the whole string, in addition to the prefix? This could be done by comparing against a hard-coded string, or decoding the string and extracting the values and comparing them to the input. I'd also be okay with removing those tests entirely for now; up to you. But leaving them in gives a false impression of coverage.

Otherwise LGTM.

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.

3 participants