Skip to content

Commit 52eebf1

Browse files
committed
update tests based on var name updates
1 parent a669408 commit 52eebf1

File tree

2 files changed

+68
-65
lines changed

2 files changed

+68
-65
lines changed

plotly/tests/test_core/test_tools/test_figure_factory.py

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ def test_unequal_z_text_size(self):
692692

693693
# check: PlotlyError if z and text are not the same dimmensions
694694

695-
kwargs = {'z': [[1, 2], [1, 2]], 'text': [[1, 2, 3], [1, 2]]}
695+
kwargs = {'z': [[1, 2], [1, 2]], 'annotation_text': [[1, 2, 3], [1]]}
696696
self.assertRaises(PlotlyError,
697697
tls.FigureFactory.create_annotated_heatmap,
698698
**kwargs)
699699

700-
kwargs = {'z': [[1, 2], [1, 2]], 'text': [[1, 2], [1, 2], [1, 2]]}
700+
kwargs = {'z': [[1], [1]], 'annotation_text': [[1], [1], [1]]}
701701
self.assertRaises(PlotlyError,
702702
tls.FigureFactory.create_annotated_heatmap,
703703
**kwargs)
@@ -710,45 +710,46 @@ def test_simple_annotated_heatmap(self):
710710
z = [[1, 0, .5], [.25, .75, .45]]
711711
a_heat = tls.FigureFactory.create_annotated_heatmap(z)
712712
expected_a_heat = {
713-
'data': [{'showscale': False,
713+
'data': [{'colorscale': None,
714+
'showscale': False,
714715
'type': 'heatmap',
715716
'z': [[1, 0, 0.5], [0.25, 0.75, 0.45]]}],
716-
'layout': {'annotations': [{'font': {'color': '#000000'},
717+
'layout': {'annotations': [{'font': {'color': '#FFFFFF'},
717718
'showarrow': False,
718719
'text': '1',
719720
'x': 0,
720721
'xref': 'x1',
721722
'y': 0,
722723
'yref': 'y1'},
723-
{'font': {'color': '#FFFFFF'},
724+
{'font': {'color': '#000000'},
724725
'showarrow': False,
725726
'text': '0',
726727
'x': 1,
727728
'xref': 'x1',
728729
'y': 0,
729730
'yref': 'y1'},
730-
{'font': {'color': '#000000'},
731+
{'font': {'color': '#FFFFFF'},
731732
'showarrow': False,
732733
'text': '0.5',
733734
'x': 2,
734735
'xref': 'x1',
735736
'y': 0,
736737
'yref': 'y1'},
737-
{'font': {'color': '#FFFFFF'},
738+
{'font': {'color': '#000000'},
738739
'showarrow': False,
739740
'text': '0.25',
740741
'x': 0,
741742
'xref': 'x1',
742743
'y': 1,
743744
'yref': 'y1'},
744-
{'font': {'color': '#000000'},
745+
{'font': {'color': '#FFFFFF'},
745746
'showarrow': False,
746747
'text': '0.75',
747748
'x': 1,
748749
'xref': 'x1',
749750
'y': 1,
750751
'yref': 'y1'},
751-
{'font': {'color': '#000000'},
752+
{'font': {'color': '#FFFFFF'},
752753
'showarrow': False,
753754
'text': '0.45',
754755
'x': 2,
@@ -774,63 +775,62 @@ def test_more_kwargs(self):
774775
x=['A', 'B'],
775776
y=['One', 'Two',
776777
'Three'],
777-
text=text,
778+
annotation_text=text,
778779
colorscale=[[0,
779780
'#ffffff'],
780781
[1,
781782
'#e6005a']]
782783
)
783784
expected_a = {'data': [{'colorscale': [[0, '#ffffff'], [1, '#e6005a']],
784-
'showscale': False,
785-
'type': 'heatmap',
786-
'x': ['A', 'B'],
787-
'y': ['One', 'Two', 'Three'],
788-
'z': [[1, 0], [0.25, 0.75], [0.45, 0.5]]}],
789-
'layout': {'annotations': [{'font': {'color': '#FFFFFF'},
790-
'showarrow': False,
791-
'text': 'first',
792-
'x': 'A',
793-
'xref': 'x1',
794-
'y': 'One',
795-
'yref': 'y1'},
796-
{'font': {'color': '#000000'},
797-
'showarrow': False,
798-
'text': 'second',
799-
'x': 'B',
800-
'xref': 'x1',
801-
'y': 'One',
802-
'yref': 'y1'},
803-
{'font': {'color': '#000000'},
804-
'showarrow': False,
805-
'text': 'third',
806-
'x': 'A',
807-
'xref': 'x1',
808-
'y': 'Two',
809-
'yref': 'y1'},
810-
{'font': {'color': '#FFFFFF'},
811-
'showarrow': False,
812-
'text': 'fourth',
813-
'x': 'B',
814-
'xref': 'x1',
815-
'y': 'Two',
816-
'yref': 'y1'},
817-
{'font': {'color': '#FFFFFF'},
818-
'showarrow': False,
819-
'text': 'fifth',
820-
'x': 'A',
821-
'xref': 'x1',
822-
'y': 'Three',
823-
'yref': 'y1'},
824-
{'font': {'color': '#FFFFFF'},
825-
'showarrow': False,
826-
'text': 'sixth',
827-
'x': 'B',
828-
'xref': 'x1',
829-
'y': 'Three',
830-
'yref': 'y1'}],
831-
'xaxis': {'gridcolor': 'rgb(0, 0, 0)',
832-
'side': 'top', 'ticks': ''},
833-
'yaxis': {'ticks': '', 'ticksuffix': ' '}}}
785+
'showscale': False,
786+
'type': 'heatmap',
787+
'x': ['A', 'B'],
788+
'y': ['One', 'Two', 'Three'],
789+
'z': [[1, 0], [0.25, 0.75], [0.45, 0.5]]}],
790+
'layout': {'annotations': [{'font': {'color': '#FFFFFF'},
791+
'showarrow': False,
792+
'text': 'first',
793+
'x': 'A',
794+
'xref': 'x1',
795+
'y': 'One',
796+
'yref': 'y1'},
797+
{'font': {'color': '#000000'},
798+
'showarrow': False,
799+
'text': 'second',
800+
'x': 'B',
801+
'xref': 'x1',
802+
'y': 'One',
803+
'yref': 'y1'},
804+
{'font': {'color': '#000000'},
805+
'showarrow': False,
806+
'text': 'third',
807+
'x': 'A',
808+
'xref': 'x1',
809+
'y': 'Two',
810+
'yref': 'y1'},
811+
{'font': {'color': '#FFFFFF'},
812+
'showarrow': False,
813+
'text': 'fourth',
814+
'x': 'B',
815+
'xref': 'x1',
816+
'y': 'Two',
817+
'yref': 'y1'},
818+
{'font': {'color': '#FFFFFF'},
819+
'showarrow': False,
820+
'text': 'fifth',
821+
'x': 'A',
822+
'xref': 'x1',
823+
'y': 'Three',
824+
'yref': 'y1'},
825+
{'font': {'color': '#FFFFFF'},
826+
'showarrow': False,
827+
'text': 'sixth',
828+
'x': 'B',
829+
'xref': 'x1',
830+
'y': 'Three',
831+
'yref': 'y1'}],
832+
'xaxis': {'gridcolor': 'rgb(0, 0, 0)', 'side': 'top', 'ticks': ''},
833+
'yaxis': {'ticks': '', 'ticksuffix': ' '}}}
834834
self.assertEqual(a, expected_a)
835835

836836

@@ -840,12 +840,12 @@ def test_fontcolor_input(self):
840840

841841
# check: PlotlyError if fontcolor input is incorrect
842842

843-
kwargs = {'text': [['one', 'two'], [1, 2], [1, 2], [1, 2]],
843+
kwargs = {'table_text': [['one', 'two'], [1, 2], [1, 2], [1, 2]],
844844
'fontcolor': '#000000'}
845845
self.assertRaises(PlotlyError,
846846
tls.FigureFactory.create_table, **kwargs)
847847

848-
kwargs = {'text': [['one', 'two'], [1, 2], [1, 2], [1, 2]],
848+
kwargs = {'table_text': [['one', 'two'], [1, 2], [1, 2], [1, 2]],
849849
'fontcolor': ['red', 'blue']}
850850
self.assertRaises(PlotlyError,
851851
tls.FigureFactory.create_table, **kwargs)

plotly/tools.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ def _validate_annotated_heatmap(z, annotation_text):
15981598
"same dimmensions")
15991599

16001600
@staticmethod
1601-
def _validate_table(text, fontcolor):
1601+
def _validate_table(table_text, fontcolor):
16021602
"""
16031603
Table specific validations
16041604
@@ -1609,7 +1609,7 @@ def _validate_table(text, fontcolor):
16091609
16101610
See FigureFactory.create_table() for params
16111611
"""
1612-
fontcolor_len_options = [1, 3, len(text)]
1612+
fontcolor_len_options = [1, 3, len(table_text)]
16131613
if len(fontcolor) not in fontcolor_len_options:
16141614
raise exceptions.PlotlyError("Oops, fontcolor should be a list of "
16151615
"length 1, 3 or len(text)")
@@ -2644,7 +2644,7 @@ def create_annotated_heatmap(z, x=None, y=None, annotation_text=None,
26442644
return graph_objs.Figure(data=data, layout=layout)
26452645

26462646
@staticmethod
2647-
def create_table(table_text, colorscale=None, fontcolor=['#000000'],
2647+
def create_table(table_text, colorscale=None, fontcolor=None,
26482648
height_constant=30, index=False, index_title='',
26492649
hoverinfo='none', **kwargs):
26502650
"""
@@ -2705,10 +2705,13 @@ def create_table(table_text, colorscale=None, fontcolor=['#000000'],
27052705
# TODO: protected until #282
27062706
from plotly.graph_objs import graph_objs
27072707

2708+
# Avoiding mutables in the call signature
27082709
colorscale = \
27092710
colorscale if colorscale is not None else [[0, '#66b2ff'],
27102711
[.5, '#e6e6e6'],
27112712
[1, '#ffffff']]
2713+
fontcolor = fontcolor if fontcolor is not None else ['#000000']
2714+
27122715
FigureFactory._validate_table(table_text, fontcolor)
27132716
table_matrix = _Table(table_text, colorscale, fontcolor, index,
27142717
index_title, **kwargs).get_table_matrix()

0 commit comments

Comments
 (0)