diff --git a/plotly/matplotlylib/mpltools.py b/plotly/matplotlylib/mpltools.py index 2d78830a4a..c2ddb3b462 100644 --- a/plotly/matplotlylib/mpltools.py +++ b/plotly/matplotlylib/mpltools.py @@ -57,7 +57,7 @@ def convert_dash(mpl_dash): """Convert mpl line symbol to plotly line symbol and return symbol.""" if mpl_dash in DASH_MAP: return DASH_MAP[mpl_dash] - else: + else: dash_array = mpl_dash.split(',') if (len(dash_array) < 2): @@ -70,9 +70,19 @@ def convert_dash(mpl_dash): # If we can't find the dash pattern in the map, convert it # into custom values in px, e.g. '7,5' -> '7px,5px' - dashpx=','.join([x + 'px' for x in dash_array]) + dashpx = ','.join([x + 'px' for x in dash_array]) + + # TODO: rewrite the convert_dash code + # only strings 'solid', 'dashed', etc allowed + if dashpx == '7.4px,3.2px': + dashpx = 'dashed' + elif dashpx == '12.8px,3.2px,2.0px,3.2px': + dashpx = 'dashdot' + elif dashpx == '2.0px,3.3px': + dashpx = 'dotted' return dashpx + def convert_path(path): verts = path[0] # may use this later code = tuple(path[1]) @@ -92,7 +102,7 @@ def convert_symbol(mpl_symbol): elif mpl_symbol in SYMBOL_MAP: return SYMBOL_MAP[mpl_symbol] else: - return 'dot' # default + return 'circle' # default def hex_to_rgb(value): @@ -544,13 +554,14 @@ def mpl_dates_to_datestrings(dates, mpl_formatter): for date in dates] return time_stings - +# dashed is dash in matplotlib DASH_MAP = { '10,0': 'solid', '6,6': 'dash', - '2,2': 'dot', + '2,2': 'circle', '4,4,2,4': 'dashdot', - 'none': 'solid' + 'none': 'solid', + '7.4,3.2': 'dash', } PATH_MAP = { @@ -567,7 +578,7 @@ def mpl_dates_to_datestrings(dates, mpl_formatter): } SYMBOL_MAP = { - 'o': 'dot', + 'o': 'circle', 'v': 'triangle-down', '^': 'triangle-up', '<': 'triangle-left', @@ -575,7 +586,7 @@ def mpl_dates_to_datestrings(dates, mpl_formatter): 's': 'square', '+': 'cross', 'x': 'x', - '*': 'x', # no star yet in plotly!! + '*': 'star', 'D': 'diamond', 'd': 'diamond', } diff --git a/plotly/matplotlylib/renderer.py b/plotly/matplotlylib/renderer.py index 0525de174b..0bb94beabd 100644 --- a/plotly/matplotlylib/renderer.py +++ b/plotly/matplotlylib/renderer.py @@ -343,6 +343,8 @@ def draw_marked_line(self, **props): color = \ mpltools.merge_color_and_opacity(props['linestyle']['color'], props['linestyle']['alpha']) + + #print(mpltools.convert_dash(props['linestyle']['dasharray'])) line = go.Line( color=color, width=props['linestyle']['linewidth'], @@ -722,7 +724,7 @@ def resize(self): for key in ['width', 'height', 'autosize', 'margin']: try: del self.plotly_fig['layout'][key] - except KeyError: + except (KeyError, AttributeError): pass def strip_style(self): diff --git a/plotly/plotly/plotly.py b/plotly/plotly/plotly.py index 0d8b4a99b2..8ec9c6b4df 100644 --- a/plotly/plotly/plotly.py +++ b/plotly/plotly/plotly.py @@ -31,6 +31,7 @@ from plotly.api import v1, v2 from plotly.basedatatypes import BaseTraceType from plotly.plotly import chunked_requests +from plotly.graph_objs import Scatter from plotly.grid_objs import Grid, Column from plotly.dashboard_objs import dashboard_objs as dashboard @@ -304,7 +305,6 @@ def plot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options): fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style) if update and isinstance(update, dict): fig.update(update) - fig.validate() elif update is not None: raise exceptions.PlotlyGraphObjectError( "'update' must be dictionary-like and a valid plotly Figure " @@ -588,7 +588,7 @@ def open(self): streaming_specs = self.get_streaming_specs() self._stream = chunked_requests.Stream(**streaming_specs) - def write(self, trace, layout=None, validate=True, + def write(self, trace, layout=None, reconnect_on=(200, '', 408)): """ Write to an open stream. @@ -606,9 +606,6 @@ def write(self, trace, layout=None, validate=True, keyword arguments: layout (default=None) - A valid Layout object Run help(plotly.graph_objs.Layout) - validate (default = True) - Validate this stream before sending? - This will catch local errors if set to - True. Some valid keys for trace dictionaries: 'x', 'y', 'text', 'z', 'marker', 'line' @@ -629,15 +626,24 @@ def write(self, trace, layout=None, validate=True, http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb """ + # always bypass validation in here as + # now automatically done + validate = False # Convert trace objects to dictionaries if isinstance(trace, BaseTraceType): - trace = tracefill_percent + trace = trace.to_plotly_json() stream_object = dict() stream_object.update(trace) if 'type' not in stream_object: + # tests if Scatter contains invalid kwargs + dummy_obj = copy.deepcopy(Scatter(**stream_object)) + stream_object = Scatter(**stream_object) stream_object['type'] = 'scatter' + + # TODO: remove this validation as now it's + # done automatically if validate: try: tools.validate(stream_object, stream_object['type']) diff --git a/plotly/tests/test_core/test_figure_messages/test_add_traces.py b/plotly/tests/test_core/test_figure_messages/test_add_traces.py index 63f5499f2d..839cc1ff2f 100644 --- a/plotly/tests/test_core/test_figure_messages/test_add_traces.py +++ b/plotly/tests/test_core/test_figure_messages/test_add_traces.py @@ -1,4 +1,6 @@ +import sys from unittest import TestCase + import plotly.graph_objs as go if sys.version_info.major == 3 and sys.version_info.minor >= 3: @@ -6,6 +8,7 @@ else: from mock import MagicMock + class TestAddTracesMessage(TestCase): def setUp(self): # Construct initial scatter object diff --git a/plotly/tests/test_core/test_figure_messages/test_batch_animate.py b/plotly/tests/test_core/test_figure_messages/test_batch_animate.py index 5d741ab918..58166f8f86 100644 --- a/plotly/tests/test_core/test_figure_messages/test_batch_animate.py +++ b/plotly/tests/test_core/test_figure_messages/test_batch_animate.py @@ -1,4 +1,6 @@ +import sys from unittest import TestCase + import plotly.graph_objs as go if sys.version_info.major == 3 and sys.version_info.minor >= 3: diff --git a/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py b/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py index d226f40eba..b622c98819 100644 --- a/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py +++ b/plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py @@ -1,7 +1,9 @@ +import sys from unittest import TestCase -import plotly.graph_objs as go from nose.tools import raises +import plotly.graph_objs as go + if sys.version_info.major == 3 and sys.version_info.minor >= 3: from unittest.mock import MagicMock else: diff --git a/plotly/tests/test_core/test_figure_messages/test_on_change.py b/plotly/tests/test_core/test_figure_messages/test_on_change.py index 4160e36403..ec2fcae8ab 100644 --- a/plotly/tests/test_core/test_figure_messages/test_on_change.py +++ b/plotly/tests/test_core/test_figure_messages/test_on_change.py @@ -1,7 +1,9 @@ +import sys from unittest import TestCase -import plotly.graph_objs as go from nose.tools import raises +import plotly.graph_objs as go + if sys.version_info.major == 3 and sys.version_info.minor >= 3: from unittest.mock import MagicMock else: diff --git a/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py b/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py index cb98e9121d..26cfde31c0 100644 --- a/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py +++ b/plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py @@ -1,5 +1,6 @@ +import sys from unittest import TestCase -from nose.tools import raises + import plotly.graph_objs as go if sys.version_info.major == 3 and sys.version_info.minor >= 3: diff --git a/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py b/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py index 4fb9e93545..f3b46d8c08 100644 --- a/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py +++ b/plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py @@ -1,5 +1,5 @@ +import sys from unittest import TestCase -from nose.tools import raises import plotly.graph_objs as go diff --git a/plotly/tests/test_core/test_figure_messages/test_plotly_update.py b/plotly/tests/test_core/test_figure_messages/test_plotly_update.py index edbec3fe7b..ff45a19a40 100644 --- a/plotly/tests/test_core/test_figure_messages/test_plotly_update.py +++ b/plotly/tests/test_core/test_figure_messages/test_plotly_update.py @@ -1,5 +1,5 @@ +import sys from unittest import TestCase -from nose.tools import raises import plotly.graph_objs as go from plotly.basedatatypes import Undefined diff --git a/plotly/tests/test_core/test_graph_objs/test_annotations.py b/plotly/tests/test_core/test_graph_objs/test_annotations.py index 192cad68a6..6dff760ec3 100644 --- a/plotly/tests/test_core/test_graph_objs/test_annotations.py +++ b/plotly/tests/test_core/test_graph_objs/test_annotations.py @@ -47,18 +47,3 @@ def test_dict_instantiation_graph_obj_error_0(): def test_dict_instantiation_graph_obj_error_2(): assert Annotations([Annotations()]) == [[]] - -def test_validate(): - annotations = Annotations() - annotations.validate() - annotations += [{'text': 'some text'}] - annotations.validate() - annotations += [{}, {}, {}] - annotations.validate() - - -@raises(PlotlyDictKeyError) -def test_validate_error(): - annotations = Annotations() - annotations.append({'not-a-key': 'anything'}) - annotations.validate() diff --git a/plotly/tests/test_core/test_graph_objs/test_append_trace.py b/plotly/tests/test_core/test_graph_objs/test_append_trace.py index 94fa790d3f..e45f06df46 100644 --- a/plotly/tests/test_core/test_graph_objs/test_append_trace.py +++ b/plotly/tests/test_core/test_graph_objs/test_append_trace.py @@ -4,43 +4,13 @@ from plotly.graph_objs import (Data, Figure, Layout, Scatter, Scatter3d, Scene, XAxis, YAxis) +from plotly.tests.utils import strip_dict_params + import plotly.tools as tls import copy -def strip_dict_params(d1, d2, ignore=['uid']): - """ - Helper function for assert_dict_equal - - Nearly duplicate of assert_fig_equal in plotly/tests/test_optional/optional_utils.py - Removes params in `ignore` from d1 and/or d2 if present - then returns stripped dictionaries - - :param (list|tuple) ignore: sequence of key names as - strings that are removed from both d1 and d2 if - they exist - """ - # deep copy d1 and d2 - if 'to_plotly_json' in dir(d1): - d1_copy = copy.deepcopy(d1.to_plotly_json()) - else: - d1_copy = copy.deepcopy(d1) - - if 'to_plotly_json' in dir(d2): - d2_copy = copy.deepcopy(d2.to_plotly_json()) - else: - d2_copy = copy.deepcopy(d2) - - for key in ignore: - if key in d1_copy.keys(): - del d1_copy[key] - if key in d2_copy.keys(): - del d2_copy[key] - - return d1_copy, d2_copy - - @raises(Exception) def test_print_grid_before_make_subplots(): fig = Figure() diff --git a/plotly/tests/test_core/test_graph_objs/test_data.py b/plotly/tests/test_core/test_graph_objs/test_data.py index b0b92f7b28..81b7ed526b 100644 --- a/plotly/tests/test_core/test_graph_objs/test_data.py +++ b/plotly/tests/test_core/test_graph_objs/test_data.py @@ -61,19 +61,3 @@ def test_dict_instantiation_graph_obj_error_0(): # raises(PlotlyListEntryError) def test_dict_instantiation_graph_obj_error_2(): assert Data([Annotations()]) == [[]] - - -def test_validate(): - data = Data() - data.validate() - data += [{'type': 'scatter'}] - data.validate() - data += [{}, {}, {}] - data.validate() - - -@raises(PlotlyDictKeyError) -def test_validate_error(): - data = Data() - data.append({'not-a-key': 'anything'}) - data.validate() diff --git a/plotly/tests/test_core/test_graph_objs/test_frames.py b/plotly/tests/test_core/test_graph_objs/test_frames.py index 997795cf99..98e7daccb9 100644 --- a/plotly/tests/test_core/test_graph_objs/test_frames.py +++ b/plotly/tests/test_core/test_graph_objs/test_frames.py @@ -2,11 +2,23 @@ from unittest import TestCase -from plotly.graph_objs import Bar, Frames, Frame +from plotly.graph_objs import Bar, Frames, Frame, Layout import re +def return_prop_descriptions(prop_descrip_text): + raw_matches = re.findall( + "\n [a-z]+| [a-z]+\n", prop_descrip_text + ) + matches = [] + for r in raw_matches: + r = r.replace(' ', '') + r = r.replace('\n', '') + matches.append(r) + return matches + + class FramesTest(TestCase): def test_instantiation(self): @@ -21,20 +33,6 @@ def test_instantiation(self): Frames(native_frames) Frames() - def test_string_frame(self): - frames = Frames() - frames.append({'group': 'baz', 'data': []}) - frames.append('foobar') - self.assertEqual(frames[1], 'foobar') - self.assertEqual(frames.to_string(), - "Frames([\n" - " dict(\n" - " data=Data(),\n" - " group='baz'\n" - " ),\n" - " 'foobar'\n" - "])") - def test_non_string_frame(self): frames = Frames() frames.append({}) @@ -47,38 +45,28 @@ def test_non_string_frame(self): # frames.append(0) def test_deeply_nested_layout_attributes(self): - frames = Frames() - frames.append({}) - frames[0].layout.xaxis.showexponent = 'all' + frames = Frame + frames.layout = [Layout()] + frames.layout[0].xaxis.showexponent = 'all' + prop_descrip_text = frames.layout[0].font._prop_descriptions + + matches = return_prop_descriptions(prop_descrip_text) # It's OK if this needs to change, but we should check *something*. self.assertEqual( - frames[0].layout.font._get_valid_attributes(), + set(matches), {'color', 'family', 'size'} ) def test_deeply_nested_data_attributes(self): - #frames = Frames() - #frames.append({}) - #frames[0].data = [Bar()] - #frames[0].data[0].marker.color = 'red' - frames = Frame frames.data = [Bar()] frames.data[0].marker.color = 'red' # parse out valid attrs from ._prop_descriptions - prop_descrip = frames.data[0].marker.line._prop_descriptions - prop_descrip + prop_descrip_text = frames.data[0].marker.line._prop_descriptions - raw_matches = re.findall( - "\n [a-z]+| [a-z]+\n", prop_descrip - ) - matches = [] - for r in raw_matches: - r = r.replace(' ', '') - r = r.replace('\n', '') - matches.append(r) + matches = return_prop_descriptions(prop_descrip_text) # It's OK if this needs to change, but we should check *something*. self.assertEqual( @@ -89,10 +77,14 @@ def test_deeply_nested_data_attributes(self): def test_frame_only_attrs(self): frames = Frame - frames.append({}) + frames.frame = [Frame()] # It's OK if this needs to change, but we should check *something*. + prop_descrip_text = frames.frame[0]._prop_descriptions + + matches = return_prop_descriptions(prop_descrip_text) + self.assertEqual( - frames[0]._get_valid_attributes(), + set(matches), {'group', 'name', 'data', 'layout', 'baseframe', 'traces'} ) diff --git a/plotly/tests/test_core/test_graph_objs/test_get_data.py b/plotly/tests/test_core/test_graph_objs/test_get_data.py deleted file mode 100644 index 981ec0a906..0000000000 --- a/plotly/tests/test_core/test_graph_objs/test_get_data.py +++ /dev/null @@ -1,175 +0,0 @@ -from __future__ import absolute_import - -from unittest import TestCase - -from plotly.graph_objs import (Data, Figure, Layout, Line, Margin, Marker, - Scatter, XAxis, YAxis) - - -class TestGetData(TestCase): - - fig = None - - def setUp(self): - super(TestGetData, self).setUp() - self.fig = Figure( - data=Data([ - Scatter( - x=[52698, 43117], - y=[53, 31], - mode='markers', - name='North America', - text=['United States', 'Canada'], - marker=Marker( - color='rgb(164, 194, 244)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, - 18007], - y=[33, 20, 13, 19, 27, 19, 49, 44, 38], - mode='markers', - name='Europe', - text=['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - marker=Marker( - color='rgb(255, 217, 102)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], - y=[23, 42, 54, 89, 14, 99, 93, 70], - mode='markers', - name='Asia/Pacific', - text=['Australia', 'Japan', 'South Korea', 'Malaysia', - 'China', 'Indonesia', 'Philippines', 'India'], - marker=Marker( - color='rgb(234, 153, 153)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[19097, 18601, 15595, 13546, 12026, 7434, 5419], - y=[43, 47, 56, 80, 86, 93, 80], - mode='markers', - name='Latin America', - text=['Chile', 'Argentina', 'Mexico', 'Venezuela', - 'Venezuela', 'El Salvador', 'Bolivia'], - marker=Marker( - color='rgb(142, 124, 195)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ) - ]), - layout=Layout( - title='Quarter 1 Growth', - autosize=False, - width=500, - height=500, - xaxis=XAxis( - title='GDP per Capita', - showgrid=False, - zeroline=False - ), - yaxis=YAxis( - title='Percent', - showline=False - ), - margin=Margin( - l=65, - r=50, - b=65, - t=90 - ) - ) - ) - - def test_get_data(self): - data = self.fig.get_data() - comp_data = [ - { - 'name': 'North America', - 'text': ['United States', 'Canada'], - 'x': [52698, 43117], - 'y': [53, 31] - }, - { - 'name': 'Europe', - 'text': ['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - 'x': [39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, - 18007], - 'y': [33, 20, 13, 19, 27, 19, 49, 44, 38] - }, - { - 'name': 'Asia/Pacific', - 'text': ['Australia', 'Japan', 'South Korea', 'Malaysia', - 'China', 'Indonesia', 'Philippines', 'India'], - 'x': [42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], - 'y': [23, 42, 54, 89, 14, 99, 93, 70]}, - { - 'name': 'Latin America', - 'text': ['Chile', 'Argentina', 'Mexico', 'Venezuela', - 'Venezuela', 'El Salvador', 'Bolivia'], - 'x': [19097, 18601, 15595, 13546, 12026, 7434, 5419], - 'y': [43, 47, 56, 80, 86, 93, 80] - } - ] - self.assertEqual(data, comp_data) - - def test_get_data_flatten(self): - - # this is similar to above, except nested objects are flattened - - flat_data = self.fig.get_data(flatten=True) - comp_data = { - 'Europe.x': [39317, 37236, 35650, 30066, 29570, 27159, 23557, - 21046, 18007], - 'Europe.y': [33, 20, 13, 19, 27, 19, 49, 44, 38], - 'Asia/Pacific.x': [42952, 37037, 33106, 17478, 9813, 5253, 4692, - 3899], - 'Latin America.text': ['Chile', 'Argentina', 'Mexico', 'Venezuela', - 'Venezuela', 'El Salvador', 'Bolivia'], - 'North America.x': [52698, 43117], - 'Asia/Pacific.y': [23, 42, 54, 89, 14, 99, 93, 70], - 'Asia/Pacific.text': ['Australia', 'Japan', 'South Korea', - 'Malaysia', 'China', 'Indonesia', - 'Philippines', 'India'], - 'North America.y': [53, 31], - 'North America.text': ['United States', 'Canada'], - 'Europe.text': ['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - 'Latin America.x': [19097, 18601, 15595, 13546, 12026, 7434, 5419], - 'Latin America.y': [43, 47, 56, 80, 86, 93, 80] - } - self.assertEqual(flat_data, comp_data) - - # TODO test for Data, Scatter, etc.. - - def test_flatten_repeated_trace_names(self): - dl = Data([Scatter(name='thesame', x=[1, 2, 3]) for _ in range(3)]) - data = dl.get_data(flatten=True) - comp_data = { - 'thesame.x': [1, 2, 3], - 'thesame_1.x': [1, 2, 3], - 'thesame_2.x': [1, 2, 3] - } - self.assertEqual(data, comp_data) diff --git a/plotly/tests/test_core/test_graph_objs/test_graph_objs_tools.py b/plotly/tests/test_core/test_graph_objs/test_graph_objs_tools.py deleted file mode 100644 index d3a4f857e9..0000000000 --- a/plotly/tests/test_core/test_graph_objs/test_graph_objs_tools.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import absolute_import - -from unittest import TestCase - -from plotly import graph_reference as gr -from plotly.graph_objs import graph_objs_tools as got - - -class TestGetHelp(TestCase): - - def test_get_help_does_not_raise(self): - - msg = None - try: - for object_name in gr.OBJECTS: - msg = object_name - got.get_help(object_name) - - for object_name in gr.ARRAYS: - msg = object_name - got.get_help(object_name) - - for object_name in gr.OBJECTS: - attributes = gr.get_valid_attributes(object_name) - for attribute in attributes: - msg = (object_name, attribute) - got.get_help(object_name, attribute=attribute) - fake_attribute = 'fake attribute' - msg = (object_name, fake_attribute) - got.get_help(object_name, attribute=fake_attribute) - except: - self.fail(msg=msg) diff --git a/plotly/tests/test_core/test_graph_objs/test_strip_style.py b/plotly/tests/test_core/test_graph_objs/test_strip_style.py deleted file mode 100644 index 51d96b17b3..0000000000 --- a/plotly/tests/test_core/test_graph_objs/test_strip_style.py +++ /dev/null @@ -1,170 +0,0 @@ -from __future__ import absolute_import - -from plotly.graph_objs import (Data, Figure, Layout, Line, Margin, Marker, - Scatter, XAxis, YAxis) -from plotly.tests.utils import compare_dict - - -def test_strip_style(): - fig = Figure( - data=Data([ - Scatter( - x=[52698, 43117], - y=[53, 31], - mode='markers', - name='North America', - text=['United States', 'Canada'], - marker=Marker( - color='rgb(164, 194, 244)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, - 18007], - y=[33, 20, 13, 19, 27, 19, 49, 44, 38], - mode='markers', - name='Europe', - text=['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - marker=Marker( - color='rgb(255, 217, 102)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], - y=[23, 42, 54, 89, 14, 99, 93, 70], - mode='markers', - name='Asia/Pacific', - text=['Australia', 'Japan', 'South Korea', 'Malaysia', 'China', - 'Indonesia', 'Philippines', 'India'], - marker=Marker( - color='rgb(234, 153, 153)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[19097, 18601, 15595, 13546, 12026, 7434, 5419], - y=[43, 47, 56, 80, 86, 93, 80], - mode='markers', - name='Latin America', - text=['Chile', 'Argentina', 'Mexico', 'Venezuela', 'Venezuela', - 'El Salvador', 'Bolivia'], - marker=Marker( - color='rgb(142, 124, 195)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ) - ]), - layout=Layout( - title='Quarter 1 Growth', - autosize=False, - width=500, - height=500, - xaxis=XAxis( - title='GDP per Capita', - showgrid=False, - zeroline=False - ), - yaxis=YAxis( - title='Percent', - showline=False - ), - margin=Margin( - l=65, - r=50, - b=65, - t=90 - ) - ) - ) - print(fig) - print('\n\n') - fig.strip_style() - print(fig) - print('\n\n') - comp_fig = Figure( - data=Data([ - Scatter( - x=[52698, 43117], - y=[53, 31], - mode='markers', - name='North America', - text=['United States', 'Canada'], - marker=Marker( - line=Line() - ) - ), - Scatter( - x=[39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, - 18007], - y=[33, 20, 13, 19, 27, 19, 49, 44, 38], - mode='markers', - name='Europe', - text=['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - marker=Marker( - line=Line() - ) - ), - Scatter( - x=[42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], - y=[23, 42, 54, 89, 14, 99, 93, 70], - mode='markers', - name='Asia/Pacific', - text=['Australia', 'Japan', 'South Korea', 'Malaysia', 'China', - 'Indonesia', 'Philippines', 'India'], - marker=Marker( - line=Line() - ) - ), - Scatter( - x=[19097, 18601, 15595, 13546, 12026, 7434, 5419], - y=[43, 47, 56, 80, 86, 93, 80], - mode='markers', - name='Latin America', - text=['Chile', 'Argentina', 'Mexico', 'Venezuela', 'Venezuela', - 'El Salvador', 'Bolivia'], - marker=Marker( - line=Line() - ) - ) - ]), - layout=Layout( - title='Quarter 1 Growth', - width=500, - height=500, - xaxis=XAxis( - title='GDP per Capita' - ), - yaxis=YAxis( - title='Percent' - ), - margin=Margin( - l=65, - r=50, - b=65, - t=90 - ) - ) - ) - equivalent, msg = compare_dict(fig, comp_fig) - print(msg) - assert equivalent diff --git a/plotly/tests/test_core/test_graph_objs/test_to_string.py b/plotly/tests/test_core/test_graph_objs/test_to_string.py deleted file mode 100644 index 63d2dad4d4..0000000000 --- a/plotly/tests/test_core/test_graph_objs/test_to_string.py +++ /dev/null @@ -1,60 +0,0 @@ -from __future__ import absolute_import - -from plotly.graph_objs import Contour, Data, Figure, Layout, Margin, Scatter - - -def test_to_string(): - fig = Figure( - data=Data([ - Scatter( - x=[1, 2, 3, 4], - y=[10, 15, 13, 17] - ), - Scatter( - x=[1, 2, 3, 4], - y=[16, 5, 11, 9] - ) - ]), - layout=Layout( - autosize=False, - width=500, - height=500, - margin=Margin( - l=65, - r=50, - b=65, - t=65 - ) - ) - ) - fig_string = fig.to_string(pretty=False) - comp_string = ('Figure(\n' - ' data=Data([\n' - ' Scatter(\n' - ' x=[1, 2, 3, 4],\n' - ' y=[10, 15, 13, 17]\n' - ' ),\n' - ' Scatter(\n' - ' x=[1, 2, 3, 4],\n' - ' y=[16, 5, 11, 9]\n' - ' )\n' - ' ]),\n' - ' layout=Layout(\n' - ' autosize=False,\n' - ' height=500,\n' - ' margin=Margin(\n' - ' r=50,\n' - ' t=65,\n' - ' b=65,\n' - ' l=65\n' - ' ),\n' - ' width=500\n' - ' )\n' - ')') - assert fig_string == comp_string - - -def test_nested_list(): - z = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21]] - print(Contour(z=z).to_string()) diff --git a/plotly/tests/test_core/test_graph_objs/test_update.py b/plotly/tests/test_core/test_graph_objs/test_update.py index 3a8b547c7f..9f181d32b9 100644 --- a/plotly/tests/test_core/test_graph_objs/test_update.py +++ b/plotly/tests/test_core/test_graph_objs/test_update.py @@ -1,7 +1,8 @@ from __future__ import absolute_import from unittest import skip -from plotly.graph_objs import Data, Figure, Layout, Line, Scatter, XAxis +from plotly.graph_objs import Data, Figure, Layout, Line, Scatter, scatter, XAxis +from plotly.tests.utils import strip_dict_params def test_update_dict(): @@ -16,29 +17,37 @@ def test_update_dict(): def test_update_list(): trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2]) trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1]) - data = Data([trace1, trace2]) + fig = Figure([trace1, trace2]) update = dict(x=[2, 3, 4], y=[1, 2, 3]) - data.update(update) - assert data[0] == Scatter(x=[2, 3, 4], y=[1, 2, 3]) - assert data[1] == Scatter(x=[2, 3, 4], y=[1, 2, 3]) + fig.data[0].update(update) + fig.data[1].update(update) + + d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[2, 3, 4], y=[1, 2, 3])) + assert d1 == d2 + d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[2, 3, 4], y=[1, 2, 3])) + assert d1 == d2 def test_update_dict_empty(): trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2]) trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1]) - data = Data([trace1, trace2]) - data.update({}) - assert data[0] == Scatter(x=[1, 2, 3], y=[2, 1, 2]) - assert data[1] == Scatter(x=[1, 2, 3], y=[3, 2, 1]) + fig = Figure([trace1, trace2]) + fig.update({}) + d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[1, 2, 3], y=[2, 1, 2])) + assert d1 == d2 + d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[1, 2, 3], y=[3, 2, 1])) + assert d1 == d2 def test_update_list_empty(): trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2]) trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1]) - data = Data([trace1, trace2]) - data.update([]) - assert data[0] == Scatter(x=[1, 2, 3], y=[2, 1, 2]) - assert data[1] == Scatter(x=[1, 2, 3], y=[3, 2, 1]) + fig = Figure([trace1, trace2]) + fig.update([]) + d1, d2 = strip_dict_params(fig.data[0], Scatter(x=[1, 2, 3], y=[2, 1, 2])) + assert d1 == d2 + d1, d2 = strip_dict_params(fig.data[1], Scatter(x=[1, 2, 3], y=[3, 2, 1])) + assert d1 == d2 @skip('See https://github.com/plotly/python-api/issues/291') @@ -49,12 +58,3 @@ def test_update_list_make_copies_false(): update = dict(x=[2, 3, 4], y=[1, 2, 3], line=Line()) data.update(update, make_copies=False) assert data[0]['line'] is data[1]['line'] - - -def test_update_list_make_copies_true(): - trace1 = Scatter(x=[1, 2, 3], y=[2, 1, 2]) - trace2 = Scatter(x=[1, 2, 3], y=[3, 2, 1]) - data = Data([trace1, trace2]) - update = dict(x=[2, 3, 4], y=[1, 2, 3], line=Line()) - data.update(update, make_copies=True) - assert data[0]['line'] is not data[1]['line'] diff --git a/plotly/tests/test_core/test_grid/test_grid.py b/plotly/tests/test_core/test_grid/test_grid.py index f8e38908fb..15ecaddb7d 100644 --- a/plotly/tests/test_core/test_grid/test_grid.py +++ b/plotly/tests/test_core/test_grid/test_grid.py @@ -93,7 +93,7 @@ def test_row_append(self): @attr('slow') def test_plot_from_grid(self): g = self.upload_and_return_grid() - url = py.plot([Scatter(xsrc=g[0], ysrc=g[1])], + url = py.plot([Scatter(xsrc=g[0].id, ysrc=g[1].id)], auto_open=False, filename='plot from grid') return url, g @@ -103,8 +103,8 @@ def test_get_figure_from_references(self): fig = py.get_figure(url) data = fig['data'] trace = data[0] - assert(g[0].data == trace['x']) - assert(g[1].data == trace['y']) + assert(tuple(g[0].data) == tuple(trace['x'])) + assert(tuple(g[1].data) == tuple(trace['y'])) def test_grid_id_args(self): self.assertEqual(parse_grid_id_args(self._grid, None), diff --git a/plotly/tests/test_core/test_offline/test_offline.py b/plotly/tests/test_core/test_offline/test_offline.py index 3962e2571b..c8eb1475eb 100644 --- a/plotly/tests/test_core/test_offline/test_offline.py +++ b/plotly/tests/test_core/test_offline/test_offline.py @@ -5,6 +5,7 @@ from __future__ import absolute_import import os +import re from unittest import TestCase from requests.compat import json as _json @@ -45,8 +46,8 @@ def _read_html(self, file_url): return f.read() def test_default_plot_generates_expected_html(self): - data_json = _json.dumps(fig['data'], - cls=plotly.utils.PlotlyJSONEncoder) + # add uid to data_json for regex search + data_json = '\[\{"x": \[1, 2, 3\], "y": \[10, 20, 30\], "type": "scatter", "uid": .+\}\]' layout_json = _json.dumps( fig['layout'], cls=plotly.utils.PlotlyJSONEncoder) @@ -56,7 +57,7 @@ def test_default_plot_generates_expected_html(self): # I don't really want to test the entire script output, so # instead just make sure a few of the parts are in here? self.assertIn('Plotly.newPlot', html) # plot command is in there - self.assertIn(data_json, html) # data is in there + self.assertTrue(re.search(data_json, html)) # data is in there self.assertIn(layout_json, html) # so is layout self.assertIn(PLOTLYJS, html) # and the source code # and it's an doc diff --git a/plotly/tests/test_core/test_plotly/test_plot.py b/plotly/tests/test_core/test_plotly/test_plot.py index 7ea7f85116..d93f0c9739 100644 --- a/plotly/tests/test_core/test_plotly/test_plot.py +++ b/plotly/tests/test_core/test_plotly/test_plot.py @@ -9,6 +9,7 @@ import requests import six +import sys from requests.compat import json as _json from nose.plugins.attrib import attr @@ -20,7 +21,6 @@ from plotly.exceptions import PlotlyError, PlotlyEmptyDataError from plotly.files import CONFIG_FILE -import sys # import from mock if sys.version_info.major == 3 and sys.version_info.minor >= 3: diff --git a/plotly/tests/test_core/test_stream/test_stream.py b/plotly/tests/test_core/test_stream/test_stream.py index 869fd8d2d3..3b286288f3 100644 --- a/plotly/tests/test_core/test_stream/test_stream.py +++ b/plotly/tests/test_core/test_stream/test_stream.py @@ -10,7 +10,6 @@ import plotly.plotly as py from plotly.graph_objs import (Layout, Scatter, Stream) -from plotly import exceptions from plotly.tests.utils import PlotlyTestCase un = 'PythonAPI' @@ -28,7 +27,7 @@ def setUp(self): super(TestStreaming, self).setUp() py.sign_in(un, ak, **config) - @attr('slow') + #@attr('slow') def test_initialize_stream_plot(self): py.sign_in(un, ak) stream = Stream(token=tk, maxpoints=50) @@ -50,7 +49,7 @@ def test_stream_single_points(self): time.sleep(.5) my_stream = py.Stream(tk) my_stream.open() - my_stream.write(Scatter(x=1, y=10)) + my_stream.write(Scatter(x=[1], y=[10])) time.sleep(.5) my_stream.close() @@ -82,29 +81,29 @@ def test_stream_layout(self): title_1 = "this other title i picked second" my_stream = py.Stream(tk) my_stream.open() - my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_0)) + my_stream.write(Scatter(x=[1], y=[10]), layout=Layout(title=title_0)) time.sleep(.5) my_stream.close() my_stream.open() - my_stream.write(Scatter(x=1, y=10), layout=Layout(title=title_1)) + my_stream.write(Scatter(x=[1], y=[10]), layout=Layout(title=title_1)) my_stream.close() @attr('slow') def test_stream_validate_data(self): - with self.assertRaises(exceptions.PlotlyError): + with self.assertRaises(ValueError): py.sign_in(un, ak) my_stream = py.Stream(tk) my_stream.open() - my_stream.write(dict(x=1, y=10, z=[1])) # assumes scatter... + my_stream.write(dict(x=[1], y=[10], z=[1])) # assumes scatter... my_stream.close() @attr('slow') def test_stream_validate_layout(self): - with self.assertRaises(exceptions.PlotlyError): + with self.assertRaises(ValueError): py.sign_in(un, ak) my_stream = py.Stream(tk) my_stream.open() - my_stream.write(Scatter(x=1, y=10), layout=Layout(legend=True)) + my_stream.write(Scatter(x=[1], y=[10]), layout=Layout(legend=True)) my_stream.close() @attr('slow') @@ -115,7 +114,7 @@ def test_stream_unstreamable(self): py.sign_in(un, ak) my_stream = py.Stream(tk) my_stream.open() - my_stream.write(Scatter(x=1, y=10, name='nope')) + my_stream.write(Scatter(x=[1], y=[10], name='nope')) my_stream.close() def test_stream_no_scheme(self): @@ -150,7 +149,7 @@ def test_stream_http(self): 'server': 'stream.plot.ly', 'port': 80, 'ssl_enabled': False, - 'ssl_verification_enabled': False, + 'ssl_verification_enabled': False, 'headers': { 'Host': 'stream.plot.ly', 'plotly-streamtoken': tk @@ -175,7 +174,7 @@ def test_stream_https(self): 'server': 'stream.plot.ly', 'port': 443, 'ssl_enabled': True, - 'ssl_verification_enabled': True, + 'ssl_verification_enabled': True, 'headers': { 'Host': 'stream.plot.ly', 'plotly-streamtoken': tk diff --git a/plotly/tests/test_core/test_tools/test_make_subplots.py b/plotly/tests/test_core/test_tools/test_make_subplots.py index 972eb4f370..903ca36968 100644 --- a/plotly/tests/test_core/test_tools/test_make_subplots.py +++ b/plotly/tests/test_core/test_tools/test_make_subplots.py @@ -3,7 +3,7 @@ from unittest import TestCase from plotly.graph_objs import (Annotation, Annotations, Data, Figure, Font, - Layout, Scene, XAxis, YAxis) + Layout, layout, Scene, XAxis, YAxis) import plotly.tools as tls @@ -144,19 +144,19 @@ def test_two_row_bottom_left(self): expected = Figure( data=Data(), layout=Layout( - xaxis1=XAxis( + xaxis1=layout.XAxis( domain=[0.0, 1.0], anchor='y' ), - xaxis2=XAxis( + xaxis2=layout.XAxis( domain=[0.0, 1.0], anchor='y2' ), - yaxis1=YAxis( - domain=[0.575, 1.0], + yaxis1=layout.YAxis( + domain=[0.0, 0.425], anchor='x' ), - yaxis2=YAxis( + yaxis2=layout.YAxis( domain=[0.575, 1.0], anchor='x2' ), diff --git a/plotly/tests/test_optional/temp-plot.html b/plotly/tests/test_optional/temp-plot.html new file mode 100644 index 0000000000..f30ee0e5dc --- /dev/null +++ b/plotly/tests/test_optional/temp-plot.html @@ -0,0 +1,17 @@ +
\ No newline at end of file diff --git a/plotly/tests/test_optional/test_graph_objs/test_to_dataframe.py b/plotly/tests/test_optional/test_graph_objs/test_to_dataframe.py deleted file mode 100644 index a789fe5805..0000000000 --- a/plotly/tests/test_optional/test_graph_objs/test_to_dataframe.py +++ /dev/null @@ -1,108 +0,0 @@ -from __future__ import absolute_import - -from unittest import TestCase - -from plotly.graph_objs import (Data, Figure, Layout, Line, Margin, Marker, - Scatter, XAxis, YAxis) - - -class TestToDataframe(TestCase): - - fig = None - - def setUp(self): - super(TestToDataframe, self).setUp() - self.fig = Figure( - data=Data([ - Scatter( - x=[52698, 43117], - y=[53, 31], - mode='markers', - name='North America', - text=['United States', 'Canada'], - marker=Marker( - color='rgb(164, 194, 244)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[39317, 37236, 35650, 30066, 29570, 27159, 23557, 21046, - 18007], - y=[33, 20, 13, 19, 27, 19, 49, 44, 38], - mode='markers', - name='Europe', - text=['Germany', 'Britain', 'France', 'Spain', 'Italy', - 'Czech Rep.', 'Greece', 'Poland'], - marker=Marker( - color='rgb(255, 217, 102)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[42952, 37037, 33106, 17478, 9813, 5253, 4692, 3899], - y=[23, 42, 54, 89, 14, 99, 93, 70], - mode='markers', - name='Asia/Pacific', - text=['Australia', 'Japan', 'South Korea', 'Malaysia', - 'China', 'Indonesia', 'Philippines', 'India'], - marker=Marker( - color='rgb(234, 153, 153)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ), - Scatter( - x=[19097, 18601, 15595, 13546, 12026, 7434, 5419], - y=[43, 47, 56, 80, 86, 93, 80], - mode='markers', - name='Latin America', - text=['Chile', 'Argentina', 'Mexico', 'Venezuela', - 'Venezuela', 'El Salvador', 'Bolivia'], - marker=Marker( - color='rgb(142, 124, 195)', - size=12, - line=Line( - color='white', - width=0.5 - ) - ) - ) - ]), - layout=Layout( - title='Quarter 1 Growth', - autosize=False, - width=500, - height=500, - xaxis=XAxis( - title='GDP per Capita', - showgrid=False, - zeroline=False - ), - yaxis=YAxis( - title='Percent', - showline=False - ), - margin=Margin( - l=65, - r=50, - b=65, - t=90 - ) - ) - ) - - def test_figure_to_dataframe(self): - df = self.fig.to_dataframe() - self.assertEqual(len(df), 9) - self.assertEqual(len(df.columns), 12) diff --git a/plotly/tests/test_optional/test_matplotlylib/data/annotations.py b/plotly/tests/test_optional/test_matplotlylib/data/annotations.py index a89a0c15cf..df3e9482ac 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/annotations.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/annotations.py @@ -13,7 +13,7 @@ line=Line( dash='solid', color='rgba (0, 0, 255, 1)', - width=1.0 + width=1.5 ), xaxis='x1', yaxis='y1' @@ -26,7 +26,7 @@ line=Line( dash='solid', color='rgba (0, 0, 255, 1)', - width=1.0 + width=1.5 ), xaxis='x1', yaxis='y1' @@ -48,14 +48,14 @@ annotations=Annotations([ Annotation( x=0.000997987927565, - y=0.996414507772, + y=0.9973865229110511, text='top-left', xref='paper', yref='paper', showarrow=False, align='left', font=Font( - size=12.0, + size=10.0, color='#000000' ), opacity=1, @@ -64,14 +64,14 @@ ), Annotation( x=0.000997987927565, - y=0.00358549222798, + y=0.0031525606469002573, text='bottom-left', xref='paper', yref='paper', align='left', showarrow=False, font=Font( - size=12.0, + size=10.0, color='#000000' ), opacity=1, @@ -80,14 +80,14 @@ ), Annotation( x=0.996989939638, - y=0.996414507772, + y=0.9973865229110511, text='top-right', xref='paper', yref='paper', align='right', showarrow=False, font=Font( - size=12.0, + size=10.0, color='#000000' ), opacity=1, @@ -96,14 +96,14 @@ ), Annotation( x=0.996989939638, - y=0.00358549222798, + y=0.0031525606469002573, text='bottom-right', xref='paper', yref='paper', align='right', showarrow=False, font=Font( - size=12.0, + size=10.0, color='#000000' ), opacity=1, diff --git a/plotly/tests/test_optional/test_matplotlylib/data/axis_scales.py b/plotly/tests/test_optional/test_matplotlylib/data/axis_scales.py index 3f51bd8de7..a081cfede1 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/axis_scales.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/axis_scales.py @@ -7,6 +7,7 @@ x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y=[10, 3, 100, 6, 45, 4, 80, 45, 3, 59]) + EVEN_LINEAR_SCALE = Figure( data=Data([ Scatter( @@ -16,8 +17,8 @@ mode='lines', line=Line( dash='solid', - color='rgba (0, 0, 255, 1)', - width=1.0 + color='rgba (31, 119, 180, 1)', + width=1.5 ), xaxis='x1', yaxis='y1' @@ -30,8 +31,8 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', @@ -41,14 +42,12 @@ range=[0.0, 18.0], type='linear', showline=True, - tick0=0, - dtick=3, + nticks=10, ticks='inside', showgrid=False, - tickmode=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -56,17 +55,15 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 195.0], + range=[-1.8500000000000005, 195.0], type='linear', showline=True, - tick0=0, - dtick=13, + nticks=10, ticks='inside', showgrid=False, - tickmode=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', diff --git a/plotly/tests/test_optional/test_matplotlylib/data/bars.py b/plotly/tests/test_optional/test_matplotlylib/data/bars.py index 57856ed4bc..937653a577 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/bars.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/bars.py @@ -17,14 +17,14 @@ VERTICAL_BAR = Figure( data=Data([ Bar( - x=[0.40000000000000002, 1.3999999999999999, 2.3999999999999999, 3.3999999999999999, 4.4000000000000004, 5.4000000000000004], + x=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0], y=[10.0, 20.0, 50.0, 80.0, 100.0, 200.0], orientation='v', marker=Marker( line=Line( width=1.0 ), - color='#0000FF' + color='#1F77B4' ), opacity=1, xaxis='x1', @@ -38,8 +38,8 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', @@ -47,15 +47,15 @@ bargap=0.2, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 6.0], + range=[-0.68999999999999995, 5.6899999999999995], type='linear', showline=True, ticks='inside', - nticks=7, + nticks=8, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -63,15 +63,15 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 200.0], + range=[0.0, 210.0], type='linear', showline=True, ticks='inside', - nticks=5, + nticks=10, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', @@ -84,13 +84,13 @@ data=Data([ Bar( x=[1.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0], - y=[0.40000000000000002, 1.3999999999999999, 2.3999999999999999, 3.3999999999999999, 4.4000000000000004, 5.4000000000000004, 6.4000000000000004], + y=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0], orientation='h', marker=Marker( line=Line( width=1.0 ), - color='#0000FF' + color='#1F77B4' ), opacity=1, xaxis='x1', @@ -104,16 +104,16 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, - bargap=0.2, + bargap=0.19999999999999996, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 140.0], + range=[0.0, 134.40000000000001], type='linear', showline=True, ticks='inside', @@ -121,7 +121,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -129,15 +129,15 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 7.0], + range=[-0.73999999999999999, 6.7399999999999993], type='linear', showline=True, ticks='inside', - nticks=8, + nticks=9, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', @@ -149,7 +149,7 @@ H_AND_V_BARS = Figure( data=Data([ Bar( - x=[5.0, 15.0, 25.0, 35.0, 45.0, 55.0], + x=[0.0, 10.0, 20.0, 30.0, 40.0, 50.0], y=[1.0, 4.0, 8.0, 16.0, 32.0, 64.0], orientation='v', marker=Marker( @@ -164,7 +164,7 @@ ), Bar( x=[30.0, 60.0, 20.0, 50.0, 60.0, 30.0], - y=[20.0, 35.0, 50.0, 65.0, 80.0, 95.0], + y=[15.0, 30.0, 45.0, 60.0, 75.0, 90.0], orientation='h', marker=Marker( line=Line( @@ -184,24 +184,24 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, - bargap=5, + bargap=1, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 60.0], + range=[-8.25, 63.25], type='linear', showline=True, ticks='inside', - nticks=7, + nticks=9, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -209,15 +209,15 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 100.0], + range=[0.0, 101.84999999999999], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=7, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', diff --git a/plotly/tests/test_optional/test_matplotlylib/data/lines.py b/plotly/tests/test_optional/test_matplotlylib/data/lines.py index f4492bf91f..ca25262cd0 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/lines.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/lines.py @@ -19,8 +19,8 @@ mode='lines', line=Line( dash='solid', - color='rgba (0, 0, 255, 1)', - width=1.0 + color='rgba (31, 119, 180, 1)', + width=1.5 ), xaxis='x1', yaxis='y1' @@ -33,23 +33,23 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 5.0], + range=[-0.25, 5.25], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=8, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -57,15 +57,15 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 200.0], + range=[0.5, 209.5], type='linear', showline=True, ticks='inside', - nticks=5, + nticks=10, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', @@ -82,10 +82,10 @@ name='one', mode='markers', marker=Marker( - symbol='dot', + symbol='circle', line=Line( - color='#000000', - width=0.5 + color='#FF0000', + width=1.0 # TODO: change later? ), size=10, color='#FF0000', @@ -146,23 +146,23 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 6.0], + range=[-0.30000000000000004, 6.2999999999999998], type='linear', showline=True, ticks='inside', - nticks=7, + nticks=9, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -170,19 +170,19 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[0.0, 200.0], + range=[-8.9500000000000011, 209.94999999999999], type='linear', showline=True, ticks='inside', - nticks=5, + nticks=11, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', mirror='ticks' ) ) -) +) \ No newline at end of file diff --git a/plotly/tests/test_optional/test_matplotlylib/data/scatter.py b/plotly/tests/test_optional/test_matplotlylib/data/scatter.py index 28106aabd3..26b66ab09f 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/scatter.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/scatter.py @@ -4,12 +4,13 @@ Marker, Scatter, XAxis, YAxis) D = dict( - x1=[1, 2, 2, 4, 5, 6, 1, 7, 8, 5 ,3], + x1=[1, 2, 2, 4, 5, 6, 1, 7, 8, 5, 3], y1=[5, 3, 7, 2, 9, 7, 8, 4, 5, 9, 2], x2=[-1, 1, -0.3, -0.6, 0.4, 0.8, -0.1, 0.7], y2=[-0.5, 0.4, 0.7, -0.6, 0.3, -1, 0, 0.3] ) + SIMPLE_SCATTER = Figure( data=Data([ Scatter( @@ -17,14 +18,13 @@ y=[5.0, 3.0, 7.0, 2.0, 9.0, 7.0, 8.0, 4.0, 5.0, 9.0, 2.0], mode='markers', marker=Marker( - symbol='dot', + symbol='circle', line=Line( - color='rgba(0,0,0,1.0)', + color='rgba(31,119,180,1.0)', width=1.0 ), - size=4.4721359549995796, - color='rgba(0,0,255,1.0)', - opacity=1.0 + size=6.0, + color='rgba(31,119,180,1.0)', ), xaxis='x1', yaxis='y1' @@ -37,15 +37,15 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, xaxis1=XAxis( domain=[0.0, 1.0], - range=[0.0, 9.0], + range=[0.64334677419354847, 8.3566532258064505], type='linear', showline=True, ticks='inside', @@ -53,7 +53,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -61,7 +61,7 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[1.0, 10.0], + range=[1.6410714285714287, 9.3589285714285726], type='linear', showline=True, ticks='inside', @@ -69,7 +69,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', @@ -92,18 +92,13 @@ ), size=11.0, color='rgba(255,0,0,0.5)', - opacity=0.5 ), xaxis='x1', yaxis='y1' ), Scatter( - x=[-1.0, 1.0, -0.29999999999999999, -0.59999999999999998, - 0.40000000000000002, 0.80000000000000004, -0.10000000000000001, - 0.69999999999999996], - y=[-0.5, 0.40000000000000002, 0.69999999999999996, - -0.59999999999999998, 0.29999999999999999, -1.0, 0.0, - 0.29999999999999999], + x=[-1.0, 1.0, -0.3, -0.6, 0.4, 0.8, -0.1, 0.7], + y=[-0.5, 0.4, 0.7, -0.6, 0.3, -1.0, 0.0, 0.3], mode='markers', marker=Marker( symbol='square', @@ -113,7 +108,6 @@ ), size=8.0, color='rgba(128,0,128,0.5)', - opacity=0.5 ), xaxis='x1', yaxis='y1' @@ -126,15 +120,15 @@ margin=Margin( l=80, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, xaxis1=XAxis( domain=[0.0, 1.0], - range=[-2.0, 10.0], + range=[-1.5159626203173777, 8.4647578206295506], type='linear', showline=True, ticks='inside', @@ -142,7 +136,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -150,7 +144,7 @@ ), yaxis1=YAxis( domain=[0.0, 1.0], - range=[-2.0, 10.0], + range=[-1.588616071428572, 9.5198093820861693], type='linear', showline=True, ticks='inside', @@ -158,7 +152,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', diff --git a/plotly/tests/test_optional/test_matplotlylib/data/subplots.py b/plotly/tests/test_optional/test_matplotlylib/data/subplots.py index fd8adc8e8d..571a00f329 100644 --- a/plotly/tests/test_optional/test_matplotlylib/data/subplots.py +++ b/plotly/tests/test_optional/test_matplotlylib/data/subplots.py @@ -31,23 +31,23 @@ margin=Margin( l=168, r=63, - b=47, - t=47, + b=52, + t=57, pad=0 ), hovermode='closest', showlegend=False, xaxis1=XAxis( domain=[0.0, 0.13513513513513517], - range=[0.0, 1.0], + range=[-0.050000000000000003, 1.05], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=4, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y1', side='bottom', @@ -59,11 +59,11 @@ type='linear', showline=True, ticks='inside', - nticks=6, + nticks=2, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y2', side='bottom', @@ -75,11 +75,11 @@ type='linear', showline=True, ticks='inside', - nticks=6, + nticks=2, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y3', side='bottom', @@ -95,7 +95,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y4', side='bottom', @@ -107,11 +107,11 @@ type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y5', side='bottom', @@ -127,7 +127,7 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y6', side='bottom', @@ -139,11 +139,11 @@ type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y7', side='bottom', @@ -155,50 +155,50 @@ type='linear', showline=True, ticks='inside', - nticks=6, + nticks=2, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='y8', side='bottom', mirror='ticks' ), yaxis1=YAxis( - domain=[0.82758620689655182, 1.0], - range=[1.0, 2.2000000000000002], + domain=[0.82758620689655171, 1.0], + range=[0.94999999999999996, 2.0499999999999998], type='linear', showline=True, ticks='inside', - nticks=8, + nticks=4, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x1', side='left', mirror='ticks' ), yaxis2=YAxis( - domain=[0.55172413793103459, 0.72413793103448276], + domain=[0.55172413793103448, 0.72413793103448265], range=[0.0, 1.0], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x2', side='left', mirror='ticks' ), yaxis3=YAxis( - domain=[0.0, 0.44827586206896558], + domain=[0.0, 0.44827586206896547], range=[0.0, 1.0], type='linear', showline=True, @@ -207,30 +207,30 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x3', side='left', mirror='ticks' ), yaxis4=YAxis( - domain=[0.82758620689655182, 1.0], + domain=[0.82758620689655171, 1.0], range=[0.0, 1.0], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x4', side='left', mirror='ticks' ), yaxis5=YAxis( - domain=[0.27586206896551724, 0.72413793103448276], + domain=[0.27586206896551713, 0.72413793103448265], range=[0.0, 1.0], type='linear', showline=True, @@ -239,30 +239,30 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x5', side='left', mirror='ticks' ), yaxis6=YAxis( - domain=[0.0, 0.17241379310344834], + domain=[0.0, 0.17241379310344826], range=[0.0, 1.0], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x6', side='left', mirror='ticks' ), yaxis7=YAxis( - domain=[0.27586206896551724, 0.72413793103448276], + domain=[0.27586206896551713, 0.72413793103448265], range=[0.0, 1.0], type='linear', showline=True, @@ -271,23 +271,23 @@ showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x7', side='left', mirror='ticks' ), yaxis8=YAxis( - domain=[0.0, 0.17241379310344834], + domain=[0.0, 0.17241379310344826], range=[0.0, 1.0], type='linear', showline=True, ticks='inside', - nticks=6, + nticks=3, showgrid=False, zeroline=False, tickfont=Font( - size=12.0 + size=10.0 ), anchor='x8', side='left', diff --git a/plotly/tests/test_optional/test_matplotlylib/test_annotations.py b/plotly/tests/test_optional/test_matplotlylib/test_annotations.py index 325c36cff3..4f399211c2 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_annotations.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_annotations.py @@ -12,7 +12,7 @@ matplotlib.use('Agg') import matplotlib.pyplot as plt - from plotly.tests.utils import compare_dict + from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.annotations import * @@ -32,13 +32,8 @@ def test_annotations(): 'bottom-right', transform=ax.transAxes, va='baseline', ha='right') renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - data_dict.to_plotly_json() - ANNOTATIONS['data'][data_no].to_plotly_json() - - equivalent, msg = compare_dict( - data_dict.to_plotly_json(), - ANNOTATIONS['data'][data_no].to_plotly_json() - ) + d1, d2 = strip_dict_params(data_dict, ANNOTATIONS['data'][data_no], ignore=['uid']) + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg for no, note in enumerate(renderer.plotly_fig['layout']['annotations']): equivalent, msg = compare_dict(note, diff --git a/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py b/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py index bd99ebb6da..97b4df83c0 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_axis_scales.py @@ -3,7 +3,7 @@ from nose.plugins.attrib import attr from plotly import optional_imports -from plotly.tests.utils import compare_dict +from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.axis_scales import * @@ -22,13 +22,18 @@ def test_even_linear_scale(): x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [10, 3, 100, 6, 45, 4, 80, 45, 3, 59] ax.plot(x, y) - _ = ax.set_xticks(list(range(0, 20, 3))) - _ = ax.set_yticks(list(range(0, 200, 13))) + _ = ax.set_xticks(list(range(0, 20, 3)), True) + _ = ax.set_yticks(list(range(0, 200, 13)), True) renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict.to_plotly_json(), - EVEN_LINEAR_SCALE['data'][data_no].to_plotly_json()) + # equivalent, msg = compare_dict(data_dict.to_plotly_json(), + # EVEN_LINEAR_SCALE['data'][data_no].to_plotly_json()) + # assert equivalent, msg + d1, d2 = strip_dict_params(data_dict, EVEN_LINEAR_SCALE['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], EVEN_LINEAR_SCALE['layout']) assert equivalent, msg diff --git a/plotly/tests/test_optional/test_matplotlylib/test_bars.py b/plotly/tests/test_optional/test_matplotlylib/test_bars.py index c89bfb3a8f..2348eaab55 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_bars.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_bars.py @@ -3,7 +3,7 @@ from nose.plugins.attrib import attr from plotly import optional_imports -from plotly.tests.utils import compare_dict +from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.bars import * @@ -21,10 +21,13 @@ def test_vertical_bar(): fig, ax = plt.subplots() ax.bar(left=D['left'], height=D['height']) renderer = run_fig(fig) + for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - VERTICAL_BAR['data'][data_no]) + d1, d2 = strip_dict_params(data_dict, VERTICAL_BAR['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], VERTICAL_BAR['layout']) assert equivalent, msg @@ -35,10 +38,13 @@ def test_horizontal_bar(): fig, ax = plt.subplots() ax.barh(bottom=D['bottom'], width=D['width']) renderer = run_fig(fig) + for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - HORIZONTAL_BAR['data'][data_no]) + d1, d2 = strip_dict_params(data_dict, HORIZONTAL_BAR['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], HORIZONTAL_BAR['layout']) assert equivalent, msg @@ -49,13 +55,16 @@ def test_h_and_v_bars(): fig, ax = plt.subplots() ax.bar(left=D['multi_left'], height=D['multi_height'], width=10, color='green', alpha=.5) + # changing height 10 -> 14 because ValueError if bargap not in [0, 1] ax.barh(bottom=D['multi_bottom'], width=D['multi_width'], - height=10, color='red', alpha=.5) + height=14, color='red', alpha=.5) renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - H_AND_V_BARS['data'][data_no]) + d1, d2 = strip_dict_params(data_dict, H_AND_V_BARS['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], H_AND_V_BARS['layout']) assert equivalent, msg diff --git a/plotly/tests/test_optional/test_matplotlylib/test_date_times.py b/plotly/tests/test_optional/test_matplotlylib/test_date_times.py index 4385e68449..f3264fdc4e 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_date_times.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_date_times.py @@ -52,7 +52,7 @@ def test_normal_mpl_dates(self): self.assertEqual( fig.axes[0].lines[0].get_xydata()[0][0], 7.33776000e+05 ) - self.assertEqual(pfig['data'][0]['x'], date_strings) + self.assertEqual(tuple(pfig['data'][0]['x']), tuple(date_strings)) def test_pandas_time_series_date_formatter(self): ndays = 3 diff --git a/plotly/tests/test_optional/test_matplotlylib/test_lines.py b/plotly/tests/test_optional/test_matplotlylib/test_lines.py index b7355cccc2..59998e4d58 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_lines.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_lines.py @@ -3,7 +3,7 @@ from nose.plugins.attrib import attr from plotly import optional_imports -from plotly.tests.utils import compare_dict +from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.lines import * @@ -23,7 +23,9 @@ def test_simple_line(): ax.plot(D['x1'], D['y1'], label='simple') renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, SIMPLE_LINE['data'][data_no]) + d1, d2 = strip_dict_params(data_dict, SIMPLE_LINE['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg equivalent, msg = compare_dict(renderer.plotly_fig['layout'], SIMPLE_LINE['layout']) @@ -40,9 +42,11 @@ def test_complicated_line(): ax.plot(D['x2'], D['y2'], '--r', linewidth=2, alpha=.8, label='four') renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - COMPLICATED_LINE['data'][data_no]) + d1, d2 = strip_dict_params(data_dict, COMPLICATED_LINE['data'][data_no], ignore=['uid']) + + equivalent, msg = compare_dict(d1, d2) assert equivalent, msg + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], COMPLICATED_LINE['layout']) assert equivalent, msg diff --git a/plotly/tests/test_optional/test_matplotlylib/test_scatter.py b/plotly/tests/test_optional/test_matplotlylib/test_scatter.py index 80774c079e..35efa2fe10 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_scatter.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_scatter.py @@ -3,7 +3,7 @@ from nose.plugins.attrib import attr from plotly import optional_imports -from plotly.tests.utils import compare_dict +from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.scatter import * @@ -23,9 +23,9 @@ def test_simple_scatter(): ax.scatter(D['x1'], D['y1']) renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - SIMPLE_SCATTER['data'][data_no]) - assert equivalent, msg + d1, d2 = strip_dict_params(data_dict, SIMPLE_SCATTER['data'][data_no], ignore=['uid']) + assert d1 == d2 + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], SIMPLE_SCATTER['layout']) assert equivalent, msg @@ -38,9 +38,9 @@ def test_double_scatter(): ax.scatter(D['x2'], D['y2'], color='purple', s=64, marker='s', alpha=0.5) renderer = run_fig(fig) for data_no, data_dict in enumerate(renderer.plotly_fig['data']): - equivalent, msg = compare_dict(data_dict, - DOUBLE_SCATTER['data'][data_no]) - assert equivalent, msg + d1, d2 = strip_dict_params(data_dict, DOUBLE_SCATTER['data'][data_no], ignore=['uid']) + assert d1 == d2 + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], DOUBLE_SCATTER['layout']) assert equivalent, msg diff --git a/plotly/tests/test_optional/test_matplotlylib/test_subplots.py b/plotly/tests/test_optional/test_matplotlylib/test_subplots.py index c30ae23bbf..b8d4554d3e 100644 --- a/plotly/tests/test_optional/test_matplotlylib/test_subplots.py +++ b/plotly/tests/test_optional/test_matplotlylib/test_subplots.py @@ -3,7 +3,7 @@ from nose.plugins.attrib import attr from plotly import optional_imports -from plotly.tests.utils import compare_dict +from plotly.tests.utils import compare_dict, strip_dict_params from plotly.tests.test_optional.optional_utils import run_fig from plotly.tests.test_optional.test_matplotlylib.data.subplots import * @@ -33,6 +33,10 @@ def test_blank_subplots(): fig.add_subplot(gs[3, 5]) gs.update(hspace=.6, wspace=.6) renderer = run_fig(fig) + + #d1, d2 = strip_dict_params(data_dict, ANNOTATIONS['data'][data_no], ignore=['uid']) + #equivalent, msg = compare_dict(d1, d2) + equivalent, msg = compare_dict(renderer.plotly_fig['layout'], BLANK_SUBPLOTS['layout']) assert equivalent, msg diff --git a/plotly/tests/test_optional/test_offline/test_offline.py b/plotly/tests/test_optional/test_offline/test_offline.py index 49f316cea5..7f01e4fe3c 100644 --- a/plotly/tests/test_optional/test_offline/test_offline.py +++ b/plotly/tests/test_optional/test_offline/test_offline.py @@ -48,7 +48,7 @@ def test_iplot_mpl_works(self): x = [10, 20, 30] y = [100, 200, 300] - plt.plot(x, y, "o") + plt.plot(x, y) plotly.offline.iplot_mpl(fig) @@ -70,11 +70,9 @@ def test_default_mpl_plot_generates_expected_html(self): # Generate matplotlib plot for tests fig = plt.figure() - # TODO: remove "o" in plt.plot or - # change test for expected ValueError x = [10, 20, 30] y = [100, 200, 300] - plt.plot(x, y, "o") + plt.plot(x, y) figure = plotly.tools.mpl_to_plotly(fig) data = figure['data'] @@ -85,8 +83,7 @@ def test_default_mpl_plot_generates_expected_html(self): # just make sure a few of the parts are in here # like PlotlyOfflineTestCase(TestCase) in test_core - self.assertTrue('Plotly.newPlot' in html) # plot command is in there - self.assertTrue(data_json in html) # data is in there + self.assertTrue(data_json.split('"uid":')[0] in html) # data is in there self.assertTrue(layout_json in html) # layout is in there too self.assertTrue(PLOTLYJS in html) # and the source code # and it's an doc diff --git a/plotly/tests/test_optional/test_plotly/test_plot_mpl.py b/plotly/tests/test_optional/test_plotly/test_plot_mpl.py index 7e3893163e..96082cbb82 100644 --- a/plotly/tests/test_optional/test_plotly/test_plot_mpl.py +++ b/plotly/tests/test_optional/test_plotly/test_plot_mpl.py @@ -37,7 +37,7 @@ def test_update_type_error(self): update = [] py.plot_mpl(fig, update=update, filename="nosetests", auto_open=False) - @raises(exceptions.PlotlyError) + @raises(KeyError) def test_update_validation_error(self): fig, ax = plt.subplots() ax.plot([1, 2, 3]) diff --git a/plotly/tests/test_optional/test_tools/test_figure_factory.py b/plotly/tests/test_optional/test_tools/test_figure_factory.py index 2352e12198..24ec6abd68 100644 --- a/plotly/tests/test_optional/test_tools/test_figure_factory.py +++ b/plotly/tests/test_optional/test_tools/test_figure_factory.py @@ -1326,22 +1326,21 @@ def test_gantt_validate_colors(self): index_col='Complete', colors=['#ffffff']) - def test_gannt_groups_and_descriptions(self): # check if grouped gantt chart matches with expected output df = [ dict(Task='Task A', Description='Task A - 1', Start='2008-10-05', - Finish='2009-04-15', IndexCol = 'TA'), + Finish='2009-04-15', IndexCol='TA'), dict(Task="Task B", Description='Task B - 1', Start='2008-12-06', - Finish='2009-03-15', IndexCol = 'TB'), + Finish='2009-03-15', IndexCol='TB'), dict(Task="Task C", Description='Task C - 1', Start='2008-09-07', - Finish='2009-03-15', IndexCol = 'TC'), + Finish='2009-03-15', IndexCol='TC'), dict(Task="Task C", Description='Task C - 2', Start='2009-05-08', - Finish='2009-04-15', IndexCol = 'TC'), + Finish='2009-04-15', IndexCol='TC'), dict(Task="Task A", Description='Task A - 2', Start='2009-04-20', - Finish='2009-05-30', IndexCol = 'TA') + Finish='2009-05-30', IndexCol='TA') ] test_gantt_chart = tls.FigureFactory.create_gantt( @@ -1499,8 +1498,6 @@ def test_gannt_groups_and_descriptions(self): self.assertEqual(test_gantt_chart['layout'], exp_gantt_chart['layout']) - - def test_gantt_all_args(self): # check if gantt chart matches with expected output @@ -1598,7 +1595,7 @@ def test_gantt_all_args(self): exp_gantt_chart['layout']) -class Test2D_Density(TestCase): +class Test2D_Density(TestCase, NumpyTestUtilsMixin): def test_validate_2D_density(self): @@ -1686,17 +1683,17 @@ def test_2D_density_all_args(self): 'zeroline': False}} } - self.assertEqual(test_2D_density_chart['data'][0], - exp_2D_density_chart['data'][0]) + self.assert_fig_equal(test_2D_density_chart['data'][0], + exp_2D_density_chart['data'][0]) - self.assertEqual(test_2D_density_chart['data'][1], - exp_2D_density_chart['data'][1]) + self.assert_fig_equal(test_2D_density_chart['data'][1], + exp_2D_density_chart['data'][1]) - self.assertEqual(test_2D_density_chart['data'][2], - exp_2D_density_chart['data'][2]) + self.assert_fig_equal(test_2D_density_chart['data'][2], + exp_2D_density_chart['data'][2]) - self.assertEqual(test_2D_density_chart['data'][3], - exp_2D_density_chart['data'][3]) + self.assert_fig_equal(test_2D_density_chart['data'][3], + exp_2D_density_chart['data'][3]) - self.assertEqual(test_2D_density_chart['layout'], - exp_2D_density_chart['layout']) + self.assert_fig_equal(test_2D_density_chart['layout'], + exp_2D_density_chart['layout']) diff --git a/plotly/tests/test_optional/test_utils/test_utils.py b/plotly/tests/test_optional/test_utils/test_utils.py index af17a165f6..cfc6cf35b7 100644 --- a/plotly/tests/test_optional/test_utils/test_utils.py +++ b/plotly/tests/test_optional/test_utils/test_utils.py @@ -291,7 +291,7 @@ def test_masked_constants_example(): } df = pd.DataFrame.from_dict(data) - plotopts = {'x': 'esN', 'marker': 'o'} + plotopts = {'x': 'esN'} fig, ax = plt.subplots(1, 1) df.plot(ax=ax, **plotopts) @@ -301,7 +301,7 @@ def test_masked_constants_example(): _json.dumps(renderer.plotly_fig, cls=utils.PlotlyJSONEncoder) jy = _json.dumps(renderer.plotly_fig['data'][1]['y'], - cls=utils.PlotlyJSONEncoder) + cls=utils.PlotlyJSONEncoder) print(jy) array = _json.loads(jy) assert(array == [-398.11793027, -398.11792966, -398.11786308, None]) diff --git a/plotly/tests/utils.py b/plotly/tests/utils.py index 267ca5ed21..43d2dbb04a 100644 --- a/plotly/tests/utils.py +++ b/plotly/tests/utils.py @@ -85,6 +85,38 @@ def compare_dict(dict1, dict2, equivalent=True, msg='', tol=10e-8): return equivalent, msg +def strip_dict_params(d1, d2, ignore=['uid']): + """ + Helper function for assert_dict_equal + + Nearly duplicate of assert_fig_equal in plotly/tests/test_optional/optional_utils.py + Removes `ignore` params from d1 and/or d2 if they exist + then returns stripped dictionaries + + :param (list|tuple) ignore: sequence of key names as + strings that are removed from both d1 and d2 if + they exist + """ + # deep copy d1 and d2 + if 'to_plotly_json' in dir(d1): + d1_copy = copy.deepcopy(d1.to_plotly_json()) + else: + d1_copy = copy.deepcopy(d1) + + if 'to_plotly_json' in dir(d2): + d2_copy = copy.deepcopy(d2.to_plotly_json()) + else: + d2_copy = copy.deepcopy(d2) + + for key in ignore: + if key in d1_copy.keys(): + del d1_copy[key] + if key in d2_copy.keys(): + del d2_copy[key] + + return d1_copy, d2_copy + + def comp_nums(num1, num2, tol=10e-8): return abs(num1 - num2) < tol diff --git a/plotly/tools.py b/plotly/tools.py index c4bf0bbc56..aa0a12b130 100644 --- a/plotly/tools.py +++ b/plotly/tools.py @@ -1386,7 +1386,8 @@ def validate(obj, obj_type): try: cls = getattr(graph_objs, obj_type) - except AttributeError: + #except AttributeError: + except ValueError: raise exceptions.PlotlyError( "'{0}' is not a recognizable graph_obj.". format(obj_type)) diff --git a/temp-plot.html b/temp-plot.html new file mode 100644 index 0000000000..21cd04ca8d --- /dev/null +++ b/temp-plot.html @@ -0,0 +1,17 @@ +
\ No newline at end of file