Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes 2 #994

Merged
merged 28 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3cef6d3
remove get_data, strip_style and to_string test files
Kully Apr 23, 2018
ce3b723
fixed test_frames
Kully Apr 23, 2018
7378270
test_data working
Kully Apr 23, 2018
fbdcb62
remove test_graph_objs_tools as graph_objs_tools doesn't exist
Kully Apr 23, 2018
39d036d
move strip_dict_params to plotly/test/utils.py
Kully Apr 23, 2018
53bcdec
fixed most of test_update
Kully Apr 24, 2018
c88ef40
Merge branch 'ipyplotly_integration' into test-fixes-2
Kully Apr 24, 2018
75b0ffc
Merge branch 'ipyplotly_integration' of https://github.com/plotly/plo…
Kully Apr 25, 2018
c2821a6
all test_core tests passing (sans streaming tests)
Kully Apr 26, 2018
f7c75cc
removed graph_objs as only to_dataframe is there - unsupported method…
Kully Apr 26, 2018
c228895
test_core tests working sans matplotlylib datatypes stuff
Kully Apr 26, 2018
22f15c0
update axis scales
Kully Apr 26, 2018
57a56aa
scatter - fixed test_scatter
Kully Apr 27, 2018
0fc2727
working on matplotlylib...
Kully Apr 30, 2018
6f8dcf4
convert dashed to dash in matplotlylib tools // fix test_lines
Kully Apr 30, 2018
20ecb25
test_date_times
Kully Apr 30, 2018
f024f57
fixed test_bars
Kully Apr 30, 2018
47622f5
remove commented x=... line
Kully Apr 30, 2018
390c4f2
axis_scales
Kully May 1, 2018
6d5dd92
annotations
Kully May 1, 2018
f70202d
subplots in matplotlylib
Kully May 1, 2018
6455837
fixed all streaming tests w/o server error to interupt \n playing wit…
Kully May 1, 2018
0fedc1b
working on using admin buildly account
Kully May 1, 2018
6ed70db
corrected coerce stream trace to dict if BaseTraceType line
Kully May 2, 2018
c891d75
mid stream write validation error
Kully May 2, 2018
77ca1b2
move print statements around
Kully May 2, 2018
f09a5ec
fixed streaming tests//no validation within stream.write
Kully May 2, 2018
0b5a98c
remove print statement
Kully May 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plotly/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def request(method, url, **kwargs):
:return: (requests.Response) The response directly from requests.

"""
print("Retrying")
if kwargs.get('json', None) is not None:
# See plotly.api.v2.utils.request for examples on how to do this.
raise exceptions.PlotlyError('V1 API does not handle arbitrary json.')
kwargs['headers'] = dict(kwargs.get('headers', {}), **get_headers())
kwargs['verify'] = config.get_config()['plotly_ssl_verification']

try:
response = requests.request(method, url, **kwargs)
except RequestException as e:
Expand Down
28 changes: 20 additions & 8 deletions plotly/matplotlylib/mpltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -70,9 +70,20 @@ 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])
Expand All @@ -92,7 +103,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):
Expand Down Expand Up @@ -544,13 +555,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 = {
Expand All @@ -567,15 +579,15 @@ def mpl_dates_to_datestrings(dates, mpl_formatter):
}

SYMBOL_MAP = {
'o': 'dot',
'o': 'circle',
'v': 'triangle-down',
'^': 'triangle-up',
'<': 'triangle-left',
'>': 'triangle-right',
's': 'square',
'+': 'cross',
'x': 'x',
'*': 'x', # no star yet in plotly!!
'*': 'star',
'D': 'diamond',
'd': 'diamond',
}
Expand Down
4 changes: 3 additions & 1 deletion plotly/matplotlylib/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 12 additions & 6 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it create an issue to create a dependancy of graph_objs for plotly.py?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. There shouldn't be an existing dependency the other way (i.e. plotly.graph_objs -> plotly.plotly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good. I only brought it up because another engineer advised against doing that i.e. sent me an blogpost saying it could be a problem

from plotly.grid_objs import Grid, Column
from plotly.dashboard_objs import dashboard_objs as dashboard

Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed validate so that users will not be able to use the internal validation

def write(self, trace, layout=None,
reconnect_on=(200, '', 408)):
"""
Write to an open stream.
Expand All @@ -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'
Expand All @@ -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))
Copy link
Contributor Author

@Kully Kully May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am making a deepcopy of the trace being coerced into a Scatter from the original dict. The point is that an error will pop up if there is one, and stream_object can continue down the code being untouched and do its thing.

Do you think this is a good idea? Is it better to have the actual object the user sent raise the error?

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'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import sys
from unittest import TestCase

import plotly.graph_objs as go

if sys.version_info.major == 3 and sys.version_info.minor >= 3:
from unittest.mock import MagicMock
else:
from mock import MagicMock


class TestAddTracesMessage(TestCase):
def setUp(self):
# Construct initial scatter object
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import sys
from unittest import TestCase
from nose.tools import raises

import plotly.graph_objs as go

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 0 additions & 15 deletions plotly/tests/test_core/test_graph_objs/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
34 changes: 2 additions & 32 deletions plotly/tests/test_core/test_graph_objs/test_append_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 0 additions & 16 deletions plotly/tests/test_core/test_graph_objs/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading