Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c063b41

Browse filesBrowse files
committed
Make offline tests less annoying :)
1. no side effect files from running tests 2. don’t auto-open plot in browser, it auto-focuses and is incredibly distracting when multi-tasking.
1 parent f1d223c commit c063b41
Copy full SHA for c063b41

File tree

Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed

‎plotly/tests/test_core/test_offline/test_offline.py

Copy file name to clipboardExpand all lines: plotly/tests/test_core/test_offline/test_offline.py
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import absolute_import
66

7+
import os
78
from unittest import TestCase
89

910
from requests.compat import json as _json
@@ -24,7 +25,16 @@
2425
PLOTLYJS = plotly.offline.offline.get_plotlyjs()
2526

2627

27-
class PlotlyOfflineTestCase(TestCase):
28+
class PlotlyOfflineBaseTestCase(TestCase):
29+
def tearDown(self):
30+
# Some offline tests produce an html file. Make sure we clean up :)
31+
try:
32+
os.remove('temp-plot.html')
33+
except OSError:
34+
pass
35+
36+
37+
class PlotlyOfflineTestCase(PlotlyOfflineBaseTestCase):
2838
def setUp(self):
2939
pass
3040

@@ -42,7 +52,7 @@ def test_default_plot_generates_expected_html(self):
4252
fig['layout'],
4353
cls=plotly.utils.PlotlyJSONEncoder)
4454

45-
html = self._read_html(plotly.offline.plot(fig))
55+
html = self._read_html(plotly.offline.plot(fig, auto_open=False))
4656

4757
# I don't really want to test the entire script output, so
4858
# instead just make sure a few of the parts are in here?
@@ -54,11 +64,12 @@ def test_default_plot_generates_expected_html(self):
5464
self.assertTrue(html.startswith('<html>') and html.endswith('</html>'))
5565

5666
def test_including_plotlyjs(self):
57-
html = self._read_html(plotly.offline.plot(fig, include_plotlyjs=False))
67+
html = self._read_html(plotly.offline.plot(fig, include_plotlyjs=False,
68+
auto_open=False))
5869
self.assertTrue(PLOTLYJS not in html)
5970

6071
def test_div_output(self):
61-
html = plotly.offline.plot(fig, output_type='div')
72+
html = plotly.offline.plot(fig, output_type='div', auto_open=False)
6273

6374
self.assertTrue('<html>' not in html and '</html>' not in html)
6475
self.assertTrue(html.startswith('<div>') and html.endswith('</div>'))
@@ -69,7 +80,7 @@ def test_autoresizing(self):
6980
'Plotly.Plots.resize('
7081
]
7182
# If width or height wasn't specified, then we add a window resizer
72-
html = self._read_html(plotly.offline.plot(fig))
83+
html = self._read_html(plotly.offline.plot(fig, auto_open=False))
7384
for resize_code_string in resize_code_strings:
7485
self.assertTrue(resize_code_string in html)
7586

@@ -79,12 +90,12 @@ def test_autoresizing(self):
7990
'layout': {
8091
'width': 500, 'height': 500
8192
}
82-
})
93+
}, auto_open=False)
8394
for resize_code_string in resize_code_strings:
8495
self.assertTrue(resize_code_string not in html)
8596

8697

87-
class PlotlyOfflineOtherDomainTestCase(PlotlyTestCase):
98+
class PlotlyOfflineOtherDomainTestCase(PlotlyOfflineBaseTestCase):
8899
def setUp(self):
89100
super(PlotlyOfflineOtherDomainTestCase, self).setUp()
90101
plotly.tools.set_config_file(plotly_domain='https://stage.plot.ly',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.