4
4
"""
5
5
from __future__ import absolute_import
6
6
7
+ import os
7
8
from unittest import TestCase
8
9
9
10
from requests .compat import json as _json
24
25
PLOTLYJS = plotly .offline .offline .get_plotlyjs ()
25
26
26
27
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 ):
28
38
def setUp (self ):
29
39
pass
30
40
@@ -42,7 +52,7 @@ def test_default_plot_generates_expected_html(self):
42
52
fig ['layout' ],
43
53
cls = plotly .utils .PlotlyJSONEncoder )
44
54
45
- html = self ._read_html (plotly .offline .plot (fig ))
55
+ html = self ._read_html (plotly .offline .plot (fig , auto_open = False ))
46
56
47
57
# I don't really want to test the entire script output, so
48
58
# instead just make sure a few of the parts are in here?
@@ -54,11 +64,12 @@ def test_default_plot_generates_expected_html(self):
54
64
self .assertTrue (html .startswith ('<html>' ) and html .endswith ('</html>' ))
55
65
56
66
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 ))
58
69
self .assertTrue (PLOTLYJS not in html )
59
70
60
71
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 )
62
73
63
74
self .assertTrue ('<html>' not in html and '</html>' not in html )
64
75
self .assertTrue (html .startswith ('<div>' ) and html .endswith ('</div>' ))
@@ -69,7 +80,7 @@ def test_autoresizing(self):
69
80
'Plotly.Plots.resize('
70
81
]
71
82
# 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 ))
73
84
for resize_code_string in resize_code_strings :
74
85
self .assertTrue (resize_code_string in html )
75
86
@@ -79,12 +90,12 @@ def test_autoresizing(self):
79
90
'layout' : {
80
91
'width' : 500 , 'height' : 500
81
92
}
82
- })
93
+ }, auto_open = False )
83
94
for resize_code_string in resize_code_strings :
84
95
self .assertTrue (resize_code_string not in html )
85
96
86
97
87
- class PlotlyOfflineOtherDomainTestCase (PlotlyTestCase ):
98
+ class PlotlyOfflineOtherDomainTestCase (PlotlyOfflineBaseTestCase ):
88
99
def setUp (self ):
89
100
super (PlotlyOfflineOtherDomainTestCase , self ).setUp ()
90
101
plotly .tools .set_config_file (plotly_domain = 'https://stage.plot.ly' ,
0 commit comments