Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 833cddc

Browse files
committed
tests/offline: use assertIn()/assertNotIn() instead of assertTrue()
The benefit is in the more informative context when the tests fail.
1 parent 07fd710 commit 833cddc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

plotly/tests/test_core/test_offline/test_offline.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,23 @@ def test_default_plot_generates_expected_html(self):
5656

5757
# I don't really want to test the entire script output, so
5858
# instead just make sure a few of the parts are in here?
59-
self.assertTrue('Plotly.newPlot' in html) # plot command is in there
60-
self.assertTrue(data_json in html) # data is in there
61-
self.assertTrue(layout_json in html) # so is layout
62-
self.assertTrue(PLOTLYJS in html) # and the source code
59+
self.assertIn('Plotly.newPlot', html) # plot command is in there
60+
self.assertIn(data_json, html) # data is in there
61+
self.assertIn(layout_json, html) # so is layout
62+
self.assertIn(PLOTLYJS, html) # and the source code
6363
# and it's an <html> doc
6464
self.assertTrue(html.startswith('<html>') and html.endswith('</html>'))
6565

6666
def test_including_plotlyjs(self):
6767
html = self._read_html(plotly.offline.plot(fig, include_plotlyjs=False,
6868
auto_open=False))
69-
self.assertTrue(PLOTLYJS not in html)
69+
self.assertNotIn(PLOTLYJS, html)
7070

7171
def test_div_output(self):
7272
html = plotly.offline.plot(fig, output_type='div', auto_open=False)
7373

74-
self.assertTrue('<html>' not in html and '</html>' not in html)
74+
self.assertNotIn('<html>', html)
75+
self.assertNotIn('</html>', html)
7576
self.assertTrue(html.startswith('<div>') and html.endswith('</div>'))
7677

7778
def test_autoresizing(self):
@@ -82,7 +83,7 @@ def test_autoresizing(self):
8283
# If width or height wasn't specified, then we add a window resizer
8384
html = self._read_html(plotly.offline.plot(fig, auto_open=False))
8485
for resize_code_string in resize_code_strings:
85-
self.assertTrue(resize_code_string in html)
86+
self.assertIn(resize_code_string, html)
8687

8788
# If width or height was specified, then we don't resize
8889
html = self._read_html(plotly.offline.plot({
@@ -92,7 +93,7 @@ def test_autoresizing(self):
9293
}
9394
}, auto_open=False))
9495
for resize_code_string in resize_code_strings:
95-
self.assertTrue(resize_code_string not in html)
96+
self.assertNotIn(resize_code_string, html)
9697

9798
def test_config(self):
9899
config = dict(linkText='Plotly rocks!',
@@ -115,7 +116,7 @@ def test_plot_rendered_if_non_plotly_domain(self):
115116
html = plotly.offline.plot(fig, output_type='div')
116117

117118
# test that 'Export to stage.plot.ly' is in the html
118-
self.assertTrue('Export to stage.plot.ly' in html)
119+
self.assertIn('Export to stage.plot.ly', html)
119120

120121
def tearDown(self):
121122
plotly.tools.set_config_file(plotly_domain='https://plot.ly',

0 commit comments

Comments
 (0)