Skip to content

Commit 5553f89

Browse files
committed
make cdn url generator not test exclusive
1 parent 49a777d commit 5553f89

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

packages/python/plotly/plotly/io/_base_renderers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
from os.path import isdir
88

99
import six
10-
from plotly.io import to_json, to_image, write_image, write_html
1110
from plotly import utils, optional_imports
11+
from plotly.io import to_json, to_image, write_image, write_html
1212
from plotly.io._orca import ensure_server
13+
from plotly.io._utils import plotly_cdn_url
1314
from plotly.offline.offline import _get_jconfig, get_plotlyjs
1415
from plotly.tools import return_figure_from_figure_or_data
1516

@@ -289,7 +290,7 @@ def activate(self):
289290
require.undef("plotly");
290291
requirejs.config({{
291292
paths: {{
292-
'plotly': ['https://cdn.plot.ly/plotly-latest.min']
293+
'plotly': ['{plotly_cdn}']
293294
}}
294295
}});
295296
require(['plotly'], function(Plotly) {{
@@ -298,7 +299,9 @@ def activate(self):
298299
}}
299300
</script>
300301
""".format(
301-
win_config=_window_plotly_config, mathjax_config=_mathjax_config
302+
win_config=_window_plotly_config,
303+
mathjax_config=_mathjax_config,
304+
plotly_cdn=plotly_cdn_url().rstrip(".js"),
302305
)
303306

304307
else:

packages/python/plotly/plotly/io/_html.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import six
77

8-
from plotly.io._utils import validate_coerce_fig_to_dict
9-
from plotly.offline.offline import _get_jconfig, get_plotlyjs, get_plotlyjs_version
8+
from plotly.io._utils import validate_coerce_fig_to_dict, plotly_cdn_url
9+
from plotly.offline.offline import _get_jconfig, get_plotlyjs
1010
from plotly import utils
1111

1212

@@ -273,14 +273,14 @@ def to_html(
273273
require_end = "});"
274274

275275
elif include_plotlyjs == "cdn" or include_plotlyjs == "cdn-latest":
276-
cdn_ver = get_plotlyjs_version()
276+
cdn_url = plotly_cdn_url()
277277
if include_plotlyjs == "cdn-latest":
278-
cdn_ver = "latest"
278+
cdn_url = plotly_cdn_url(cdn_ver="latest")
279279
load_plotlyjs = """\
280280
{win_config}
281-
<script src="https://cdn.plot.ly/plotly-{cdn_ver}.min.js"></script>\
281+
<script src="{cdn_url}"></script>\
282282
""".format(
283-
win_config=_window_plotly_config, cdn_ver=cdn_ver
283+
win_config=_window_plotly_config, cdn_url=cdn_url
284284
)
285285

286286
elif include_plotlyjs == "directory":

packages/python/plotly/plotly/io/_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import plotly
44
import plotly.graph_objs as go
5+
from plotly.offline import get_plotlyjs_version
56

67

78
def validate_coerce_fig_to_dict(fig, validate):
@@ -40,3 +41,10 @@ def validate_coerce_output_type(output_type):
4041
Must be one of: 'Figure', 'FigureWidget'"""
4142
)
4243
return cls
44+
45+
46+
def plotly_cdn_url(cdn_ver=get_plotlyjs_version()):
47+
"""Return a valid plotly CDN url."""
48+
return "https://cdn.plot.ly/plotly-{cdn_ver}.min.js".format(
49+
cdn_ver=cdn_ver,
50+
)

packages/python/plotly/plotly/tests/test_html.py renamed to packages/python/plotly/plotly/tests/test_io/test_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import plotly.graph_objs as go
88
import plotly.io as pio
9-
from plotly.tests.utils import plotly_cdn_url
9+
from plotly.io._utils import plotly_cdn_url
1010

1111

1212
if sys.version_info >= (3, 3):

packages/python/plotly/plotly/tests/test_io/test_renderers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import plotly.graph_objs as go
1212
import plotly.io as pio
1313
from plotly.offline import get_plotlyjs
14-
from plotly.tests.utils import plotly_cdn_url
14+
from plotly.io._utils import plotly_cdn_url
1515

1616
if sys.version_info >= (3, 3):
1717
import unittest.mock as mock
@@ -135,8 +135,8 @@ def assert_not_full_html(html):
135135
assert not html.startswith("<html")
136136

137137

138-
def assert_connected(html):
139-
assert plotly_cdn_url() in html
138+
def assert_html_renderer_connected(html):
139+
assert plotly_cdn_url().rstrip(".js") in html
140140

141141

142142
def assert_offline(html):
@@ -167,7 +167,7 @@ def test_colab_renderer_show(fig1):
167167
# Check html contents
168168
html = mock_arg1["text/html"]
169169
assert_full_html(html)
170-
assert_connected(html)
170+
assert_html_renderer_connected(html)
171171
assert_not_requirejs(html)
172172

173173
# check kwargs
@@ -196,7 +196,7 @@ def test_notebook_connected_show(fig1, name, connected):
196196
# Check init display contents
197197
bundle_display_html = mock_arg1_html
198198
if connected:
199-
assert_connected(bundle_display_html)
199+
assert_html_renderer_connected(bundle_display_html)
200200
else:
201201
assert_offline(bundle_display_html)
202202

packages/python/plotly/plotly/tests/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from numbers import Number as Num
33
from unittest import TestCase
44
import plotly.io as pio
5-
from plotly.offline import get_plotlyjs_version
65

76

87
class TestCaseNoTemplate(TestCase):
@@ -96,10 +95,3 @@ def is_num_list(item):
9695
except TypeError:
9796
return False
9897
return True
99-
100-
101-
def plotly_cdn_url(cdn_ver=get_plotlyjs_version()):
102-
"""Return plotly CDN url for use in assertions."""
103-
return "https://cdn.plot.ly/plotly-{cdn_ver}.min.js".format(
104-
cdn_ver=cdn_ver
105-
)

0 commit comments

Comments
 (0)