reflex/tests/units/components/graphing/test_plotly.py
Thomas Brandého 3f538865b5
reorganize all tests in a single top folder (#3981)
* lift node version restraint to allow more recent version if already installed

* add node test for latest version

* change python version

* use purple for debug logs

* update workflow

* add playwright dev dependency

* update workflow

* change test

* oops

* improve test

* update test

* fix tests

* mv units tests to a subfolder

* reorganize tests

* fix install

* update test_state

* revert node changes and only keep new tests organization

* move integration tests in tests/integration

* fix integration workflow

* fix dockerfile workflow

* fix dockerfile workflow 2

* fix shared_state
2024-09-26 01:22:52 +02:00

45 lines
1.1 KiB
Python

import numpy as np
import plotly.graph_objects as go
import pytest
import reflex as rx
from reflex.utils.serializers import serialize, serialize_figure
@pytest.fixture
def plotly_fig() -> go.Figure:
"""Get a plotly figure.
Returns:
A random plotly figure.
"""
# Generate random data.
data = np.random.randint(0, 10, size=(10, 4))
trace = go.Scatter(
x=list(range(len(data))), y=data[:, 0], mode="lines", name="Trace 1"
)
# Create a graph.
return go.Figure(data=[trace])
def test_serialize_plotly(plotly_fig: go.Figure):
"""Test that serializing a plotly figure works.
Args:
plotly_fig: The figure to serialize.
"""
value = serialize(plotly_fig)
assert isinstance(value, dict)
assert value == serialize_figure(plotly_fig)
def test_plotly_config_option(plotly_fig: go.Figure):
"""Test that the plotly component can be created with a config option.
Args:
plotly_fig: The figure to display.
"""
# This tests just confirm that the component can be created with a config option.
_ = rx.plotly(data=plotly_fig, config={"showLink": True})