forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_sg_scraper.py
60 lines (48 loc) · 1.46 KB
/
test_sg_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import plotly
import os
import shutil
import pytest
# Fixtures
# --------
@pytest.fixture()
def setup():
# Reset orca state
plotly.io.orca.config.restore_defaults(reset_server=False)
# Run setup before every test function in this file
pytestmark = pytest.mark.usefixtures("setup")
def execute_plotly_example():
"""
Some typical code which would go inside a gallery example.
"""
import plotly.graph_objs as go
# Create random data with numpy
import numpy as np
N = 200
random_x = np.random.randn(N)
random_y_0 = np.random.randn(N)
random_y_1 = np.random.randn(N) - 1
# Create traces
trace_0 = go.Scatter(
x=random_x,
y=random_y_0,
mode='markers',
name='Above',
)
fig = go.Figure(data=[trace_0])
plotly.io.show(fig)
def test_scraper():
from plotly.io._sg_scraper import plotly_sg_scraper
# test that monkey-patching worked ok
assert plotly.io.renderers.default == 'sphinx_gallery'
# Use dummy values for arguments of plotly_sg_scraper
block = '' # we don't need actually code
import tempfile
tempdir = tempfile.mkdtemp()
gallery_conf = {'src_dir':tempdir,
'examples_dirs':'plotly/tests/test_orca'}
names = iter(['0', '1', '2'])
block_vars = {'image_path_iterator':names}
execute_plotly_example()
res = plotly_sg_scraper(block, block_vars, gallery_conf)
shutil.rmtree(tempdir)
assert ".. raw:: html" in res