Skip to content

Commit ae19bc1

Browse files
committed
fixture
1 parent 49ffe94 commit ae19bc1

File tree

1 file changed

+27
-20
lines changed
  • packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image

1 file changed

+27
-20
lines changed

packages/python/chart-studio/chart_studio/tests/test_plot_ly/test_image/test_image.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,27 @@
1010
import _plotly_utils.exceptions
1111
from chart_studio.plotly import plotly as py
1212

13-
py.sign_in("PlotlyImageTest", "786r5mecv0")
14-
data = [{"x": [1, 2, 3], "y": [3, 1, 6]}]
13+
from chart_studio.tests.utils import PlotlyTestCase
1514

1615

17-
@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf"))
18-
@pytest.mark.parametrize('width', (None, 300))
19-
@pytest.mark.parametrize('height', (None, 300))
20-
@pytest.mark.parametrize('scale', (None, 5))
21-
def test_image_get_returns_valid_image_test(image_format, width, height, scale):
16+
@pytest.fixture
17+
def setup_image():
18+
py.sign_in("PlotlyImageTest", "786r5mecv0")
19+
data = [{"x": [1, 2, 3], "y": [3, 1, 6]}]
20+
21+
return data
22+
23+
24+
@pytest.mark.parametrize("image_format", ("png", "jpeg", "pdf", "svg", "emf"))
25+
@pytest.mark.parametrize("width", (None, 300))
26+
@pytest.mark.parametrize("height", (None, 300))
27+
@pytest.mark.parametrize("scale", (None, 3))
28+
def test_image_get_returns_valid_image_test(
29+
setup_image, image_format, width, height, scale
30+
):
2231
# TODO: better understand why this intermittently fails. See #649
23-
num_attempts = 5
32+
data = setup_image
33+
num_attempts = 2
2434
for i in range(num_attempts):
2535
if i > 0:
2636
warnings.warn("image test intermittently failed, retrying...")
@@ -34,24 +44,21 @@ def test_image_get_returns_valid_image_test(image_format, width, height, scale):
3444
raise
3545

3646

37-
@pytest.mark.parametrize('image_format', ("png", "jpeg", "pdf", "svg", "emf"))
38-
@pytest.mark.parametrize('width', (None, 300))
39-
@pytest.mark.parametrize('height', (None, 300))
40-
@pytest.mark.parametrize('scale', (None, 5))
41-
def test_image_save_as_saves_valid_image(image_format, width, height, scale):
47+
@pytest.mark.parametrize("image_format", ("png", "jpeg", "pdf", "svg", "emf"))
48+
@pytest.mark.parametrize("width", (None, 300))
49+
@pytest.mark.parametrize("height", (None, 300))
50+
@pytest.mark.parametrize("scale", (None, 3))
51+
def test_image_save_as_saves_valid_image(
52+
setup_image, image_format, width, height, scale
53+
):
54+
data = setup_image()
4255
f, filename = tempfile.mkstemp(".{}".format(image_format))
4356
py.image.save_as(
44-
data,
45-
filename,
46-
format=image_format,
47-
width=width,
48-
height=height,
49-
scale=scale,
57+
data, filename, format=image_format, width=width, height=height, scale=scale,
5058
)
5159
if image_format in ["png", "jpeg"]:
5260
assert imghdr.what(filename) == image_format
5361
else:
5462
assert os.path.getsize(filename) > 0
5563

5664
os.remove(filename)
57-

0 commit comments

Comments
 (0)