<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from nose . tools import raises <EOL> from nose . plugins . attrib import attr <EOL> from unittest import TestCase <EOL> import json <EOL> import plotly <EOL> from plotly . tools import _matplotlylib_imported <EOL> if _matplotlylib_imported : <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> import matplotlib . pyplot as plt <EOL> PLOTLYJS = plotly . offline . offline . get_plotlyjs ( ) <EOL> class PlotlyOfflineTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> plotly . offline . offline . __PLOTLY_OFFLINE_INITIALIZED = False <EOL> @ raises ( plotly . exceptions . PlotlyError ) <EOL> def test_iplot_doesnt_work_before_you_call_init_notebook_mode ( self ) : <EOL> plotly . offline . iplot ( [ { } ] ) <EOL> def test_iplot_works_after_you_call_init_notebook_mode ( self ) : <EOL> plotly . tools . _ipython_imported = True <EOL> plotly . offline . init_notebook_mode ( ) <EOL> plotly . offline . iplot ( [ { } ] ) <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_iplot_mpl_works_after_you_call_init_notebook_mode ( self ) : <EOL> fig = plt . figure ( ) <EOL> x = [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ] <EOL> y = [ <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT> ] <EOL> plt . plot ( x , y , "<STR_LIT:o>" ) <EOL> plotly . tools . _ipython_imported = True <EOL> plotly . offline . init_notebook_mode ( ) <EOL> plotly . offline . iplot_mpl ( fig ) <EOL> class PlotlyOfflineMPLTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> pass <EOL> def _read_html ( self , file_url ) : <EOL> """<STR_LIT>""" <EOL> with open ( file_url . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) ) as f : <EOL> return f . read ( ) <EOL> @ attr ( '<STR_LIT>' ) <EOL> def test_default_mpl_plot_generates_expected_html ( self ) : <EOL> fig = plt . figure ( ) <EOL> x = [ <NUM_LIT:10> , <NUM_LIT:20> , <NUM_LIT:30> ] <EOL> y = [ <NUM_LIT:100> , <NUM_LIT:200> , <NUM_LIT> ] <EOL> plt . plot ( x , y , "<STR_LIT:o>" ) <EOL> figure = plotly . tools . mpl_to_plotly ( fig ) <EOL> data = figure [ '<STR_LIT:data>' ] <EOL> layout = figure [ '<STR_LIT>' ] <EOL> data_json = json . dumps ( data , cls = plotly . utils . PlotlyJSONEncoder ) <EOL> layout_json = json . dumps ( layout , cls = plotly . utils . PlotlyJSONEncoder ) <EOL> html = self . _read_html ( plotly . offline . plot_mpl ( fig ) ) <EOL> self . assertTrue ( '<STR_LIT>' in html ) <EOL> self . assertTrue ( data_json in html ) <EOL> self . assertTrue ( layout_json in html ) <EOL> self . assertTrue ( PLOTLYJS in html ) <EOL> self . assertTrue ( html . startswith ( '<STR_LIT>' ) and html . endswith ( '<STR_LIT>' ) ) </s>
