Skip to content

Commit f150a8c

Browse files
Kullyjonmmease
authored andcommitted
Test fixes 2 (#994)
* remove get_data, strip_style and to_string test files * fixed test_frames * test_data working * remove test_graph_objs_tools as graph_objs_tools doesn't exist * move strip_dict_params to plotly/test/utils.py * fixed most of test_update * all test_core tests passing (sans streaming tests) * removed graph_objs as only to_dataframe is there - unsupported method on figuretypes * test_core tests working sans matplotlylib datatypes stuff * update axis scales * scatter - fixed test_scatter * working on matplotlylib... * convert dashed to dash in matplotlylib tools // fix test_lines * test_date_times * fixed test_bars * remove commented x=... line * axis_scales * annotations * subplots in matplotlylib * fixed all streaming tests w/o server error to interupt \n playing with retrying decorator to fix remaining tests * working on using admin buildly account * corrected coerce stream trace to dict if BaseTraceType line * mid stream write validation error * move print statements around * fixed streaming tests//no validation within stream.write * remove print statement
1 parent 30063d4 commit f150a8c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+399
-915
lines changed

Diff for: plotly/matplotlylib/mpltools.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def convert_dash(mpl_dash):
5757
"""Convert mpl line symbol to plotly line symbol and return symbol."""
5858
if mpl_dash in DASH_MAP:
5959
return DASH_MAP[mpl_dash]
60-
else:
60+
else:
6161
dash_array = mpl_dash.split(',')
6262

6363
if (len(dash_array) < 2):
@@ -70,9 +70,19 @@ def convert_dash(mpl_dash):
7070

7171
# If we can't find the dash pattern in the map, convert it
7272
# into custom values in px, e.g. '7,5' -> '7px,5px'
73-
dashpx=','.join([x + 'px' for x in dash_array])
73+
dashpx = ','.join([x + 'px' for x in dash_array])
74+
75+
# TODO: rewrite the convert_dash code
76+
# only strings 'solid', 'dashed', etc allowed
77+
if dashpx == '7.4px,3.2px':
78+
dashpx = 'dashed'
79+
elif dashpx == '12.8px,3.2px,2.0px,3.2px':
80+
dashpx = 'dashdot'
81+
elif dashpx == '2.0px,3.3px':
82+
dashpx = 'dotted'
7483
return dashpx
7584

85+
7686
def convert_path(path):
7787
verts = path[0] # may use this later
7888
code = tuple(path[1])
@@ -92,7 +102,7 @@ def convert_symbol(mpl_symbol):
92102
elif mpl_symbol in SYMBOL_MAP:
93103
return SYMBOL_MAP[mpl_symbol]
94104
else:
95-
return 'dot' # default
105+
return 'circle' # default
96106

97107

98108
def hex_to_rgb(value):
@@ -544,13 +554,14 @@ def mpl_dates_to_datestrings(dates, mpl_formatter):
544554
for date in dates]
545555
return time_stings
546556

547-
557+
# dashed is dash in matplotlib
548558
DASH_MAP = {
549559
'10,0': 'solid',
550560
'6,6': 'dash',
551-
'2,2': 'dot',
561+
'2,2': 'circle',
552562
'4,4,2,4': 'dashdot',
553-
'none': 'solid'
563+
'none': 'solid',
564+
'7.4,3.2': 'dash',
554565
}
555566

556567
PATH_MAP = {
@@ -567,15 +578,15 @@ def mpl_dates_to_datestrings(dates, mpl_formatter):
567578
}
568579

569580
SYMBOL_MAP = {
570-
'o': 'dot',
581+
'o': 'circle',
571582
'v': 'triangle-down',
572583
'^': 'triangle-up',
573584
'<': 'triangle-left',
574585
'>': 'triangle-right',
575586
's': 'square',
576587
'+': 'cross',
577588
'x': 'x',
578-
'*': 'x', # no star yet in plotly!!
589+
'*': 'star',
579590
'D': 'diamond',
580591
'd': 'diamond',
581592
}

Diff for: plotly/matplotlylib/renderer.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ def draw_marked_line(self, **props):
343343
color = \
344344
mpltools.merge_color_and_opacity(props['linestyle']['color'],
345345
props['linestyle']['alpha'])
346+
347+
#print(mpltools.convert_dash(props['linestyle']['dasharray']))
346348
line = go.Line(
347349
color=color,
348350
width=props['linestyle']['linewidth'],
@@ -722,7 +724,7 @@ def resize(self):
722724
for key in ['width', 'height', 'autosize', 'margin']:
723725
try:
724726
del self.plotly_fig['layout'][key]
725-
except KeyError:
727+
except (KeyError, AttributeError):
726728
pass
727729

728730
def strip_style(self):

Diff for: plotly/plotly/plotly.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from plotly.api import v1, v2
3232
from plotly.basedatatypes import BaseTraceType
3333
from plotly.plotly import chunked_requests
34+
from plotly.graph_objs import Scatter
3435
from plotly.grid_objs import Grid, Column
3536
from plotly.dashboard_objs import dashboard_objs as dashboard
3637

@@ -304,7 +305,6 @@ def plot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
304305
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
305306
if update and isinstance(update, dict):
306307
fig.update(update)
307-
fig.validate()
308308
elif update is not None:
309309
raise exceptions.PlotlyGraphObjectError(
310310
"'update' must be dictionary-like and a valid plotly Figure "
@@ -588,7 +588,7 @@ def open(self):
588588
streaming_specs = self.get_streaming_specs()
589589
self._stream = chunked_requests.Stream(**streaming_specs)
590590

591-
def write(self, trace, layout=None, validate=True,
591+
def write(self, trace, layout=None,
592592
reconnect_on=(200, '', 408)):
593593
"""
594594
Write to an open stream.
@@ -606,9 +606,6 @@ def write(self, trace, layout=None, validate=True,
606606
keyword arguments:
607607
layout (default=None) - A valid Layout object
608608
Run help(plotly.graph_objs.Layout)
609-
validate (default = True) - Validate this stream before sending?
610-
This will catch local errors if set to
611-
True.
612609
613610
Some valid keys for trace dictionaries:
614611
'x', 'y', 'text', 'z', 'marker', 'line'
@@ -629,15 +626,24 @@ def write(self, trace, layout=None, validate=True,
629626
http://nbviewer.ipython.org/github/plotly/python-user-guide/blob/master/s7_streaming/s7_streaming.ipynb
630627
631628
"""
629+
# always bypass validation in here as
630+
# now automatically done
631+
validate = False
632632

633633
# Convert trace objects to dictionaries
634634
if isinstance(trace, BaseTraceType):
635-
trace = tracefill_percent
635+
trace = trace.to_plotly_json()
636636

637637
stream_object = dict()
638638
stream_object.update(trace)
639639
if 'type' not in stream_object:
640+
# tests if Scatter contains invalid kwargs
641+
dummy_obj = copy.deepcopy(Scatter(**stream_object))
642+
stream_object = Scatter(**stream_object)
640643
stream_object['type'] = 'scatter'
644+
645+
# TODO: remove this validation as now it's
646+
# done automatically
641647
if validate:
642648
try:
643649
tools.validate(stream_object, stream_object['type'])

Diff for: plotly/tests/test_core/test_figure_messages/test_add_traces.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import sys
12
from unittest import TestCase
3+
24
import plotly.graph_objs as go
35

46
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
57
from unittest.mock import MagicMock
68
else:
79
from mock import MagicMock
810

11+
912
class TestAddTracesMessage(TestCase):
1013
def setUp(self):
1114
# Construct initial scatter object

Diff for: plotly/tests/test_core/test_figure_messages/test_batch_animate.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import sys
12
from unittest import TestCase
3+
24
import plotly.graph_objs as go
35

46
if sys.version_info.major == 3 and sys.version_info.minor >= 3:

Diff for: plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import sys
12
from unittest import TestCase
2-
import plotly.graph_objs as go
33
from nose.tools import raises
44

5+
import plotly.graph_objs as go
6+
57
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
68
from unittest.mock import MagicMock
79
else:

Diff for: plotly/tests/test_core/test_figure_messages/test_on_change.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import sys
12
from unittest import TestCase
2-
import plotly.graph_objs as go
33
from nose.tools import raises
44

5+
import plotly.graph_objs as go
6+
57
if sys.version_info.major == 3 and sys.version_info.minor >= 3:
68
from unittest.mock import MagicMock
79
else:

Diff for: plotly/tests/test_core/test_figure_messages/test_plotly_relayout.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import sys
12
from unittest import TestCase
2-
from nose.tools import raises
3+
34
import plotly.graph_objs as go
45

56
if sys.version_info.major == 3 and sys.version_info.minor >= 3:

Diff for: plotly/tests/test_core/test_figure_messages/test_plotly_restyle.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import sys
12
from unittest import TestCase
2-
from nose.tools import raises
33

44
import plotly.graph_objs as go
55

Diff for: plotly/tests/test_core/test_figure_messages/test_plotly_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import sys
12
from unittest import TestCase
2-
from nose.tools import raises
33

44
import plotly.graph_objs as go
55
from plotly.basedatatypes import Undefined

Diff for: plotly/tests/test_core/test_graph_objs/test_annotations.py

-15
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,3 @@ def test_dict_instantiation_graph_obj_error_0():
4747
def test_dict_instantiation_graph_obj_error_2():
4848
assert Annotations([Annotations()]) == [[]]
4949

50-
51-
def test_validate():
52-
annotations = Annotations()
53-
annotations.validate()
54-
annotations += [{'text': 'some text'}]
55-
annotations.validate()
56-
annotations += [{}, {}, {}]
57-
annotations.validate()
58-
59-
60-
@raises(PlotlyDictKeyError)
61-
def test_validate_error():
62-
annotations = Annotations()
63-
annotations.append({'not-a-key': 'anything'})
64-
annotations.validate()

Diff for: plotly/tests/test_core/test_graph_objs/test_append_trace.py

+2-32
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,13 @@
44

55
from plotly.graph_objs import (Data, Figure, Layout, Scatter, Scatter3d, Scene,
66
XAxis, YAxis)
7+
from plotly.tests.utils import strip_dict_params
8+
79
import plotly.tools as tls
810

911
import copy
1012

1113

12-
def strip_dict_params(d1, d2, ignore=['uid']):
13-
"""
14-
Helper function for assert_dict_equal
15-
16-
Nearly duplicate of assert_fig_equal in plotly/tests/test_optional/optional_utils.py
17-
Removes params in `ignore` from d1 and/or d2 if present
18-
then returns stripped dictionaries
19-
20-
:param (list|tuple) ignore: sequence of key names as
21-
strings that are removed from both d1 and d2 if
22-
they exist
23-
"""
24-
# deep copy d1 and d2
25-
if 'to_plotly_json' in dir(d1):
26-
d1_copy = copy.deepcopy(d1.to_plotly_json())
27-
else:
28-
d1_copy = copy.deepcopy(d1)
29-
30-
if 'to_plotly_json' in dir(d2):
31-
d2_copy = copy.deepcopy(d2.to_plotly_json())
32-
else:
33-
d2_copy = copy.deepcopy(d2)
34-
35-
for key in ignore:
36-
if key in d1_copy.keys():
37-
del d1_copy[key]
38-
if key in d2_copy.keys():
39-
del d2_copy[key]
40-
41-
return d1_copy, d2_copy
42-
43-
4414
@raises(Exception)
4515
def test_print_grid_before_make_subplots():
4616
fig = Figure()

Diff for: plotly/tests/test_core/test_graph_objs/test_data.py

-16
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,3 @@ def test_dict_instantiation_graph_obj_error_0():
6161
# raises(PlotlyListEntryError)
6262
def test_dict_instantiation_graph_obj_error_2():
6363
assert Data([Annotations()]) == [[]]
64-
65-
66-
def test_validate():
67-
data = Data()
68-
data.validate()
69-
data += [{'type': 'scatter'}]
70-
data.validate()
71-
data += [{}, {}, {}]
72-
data.validate()
73-
74-
75-
@raises(PlotlyDictKeyError)
76-
def test_validate_error():
77-
data = Data()
78-
data.append({'not-a-key': 'anything'})
79-
data.validate()

0 commit comments

Comments
 (0)