-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for moving/deleting traces
- Loading branch information
Jon M. Mease
committed
Apr 21, 2018
1 parent
df15d14
commit 0543793
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
plotly/tests/test_core/test_figure_messages/test_move_delete_traces.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from unittest import TestCase | ||
from mock import MagicMock | ||
import plotly.graph_objs as go | ||
|
||
|
||
class TestMoveDeleteTracesMessages(TestCase): | ||
def setUp(self): | ||
# Construct initial scatter object | ||
self.figure = go.Figure(data=[ | ||
go.Scatter(y=[3, 2, 1], marker={'color': 'green'}), | ||
go.Bar(y=[3, 2, 1, 0, -1], marker={'opacity': 0.5}), | ||
go.Sankey(arrangement='snap') | ||
]) | ||
|
||
# Mock out the message methods | ||
self.figure._send_moveTraces_msg = MagicMock() | ||
self.figure._send_deleteTraces_msg = MagicMock() | ||
|
||
def test_move_traces_swap(self): | ||
|
||
# Swap first and last trace | ||
traces = self.figure.data | ||
self.figure.data = [traces[2], traces[1], traces[0]] | ||
|
||
# Check messages | ||
self.figure._send_moveTraces_msg.assert_called_once_with( | ||
[0, 1, 2], [2, 1, 0]) | ||
self.assertFalse(self.figure._send_deleteTraces_msg.called) | ||
|
||
def test_move_traces_cycle(self): | ||
|
||
# Cycle traces forward | ||
traces = self.figure.data | ||
self.figure.data = [traces[2], traces[0], traces[1]] | ||
|
||
# Check messages | ||
self.figure._send_moveTraces_msg.assert_called_once_with( | ||
[0, 1, 2], [1, 2, 0]) | ||
self.assertFalse(self.figure._send_deleteTraces_msg.called) | ||
|
||
def test_delete_single_traces(self): | ||
# Delete middle trace | ||
traces = self.figure.data | ||
self.figure.data = [traces[0], traces[2]] | ||
|
||
# Check messages | ||
self.figure._send_deleteTraces_msg.assert_called_once_with([1]) | ||
self.assertFalse(self.figure._send_moveTraces_msg.called) | ||
|
||
def test_delete_multiple_traces(self): | ||
# Delete middle trace | ||
traces = self.figure.data | ||
self.figure.data = [traces[1]] | ||
|
||
# Check messages | ||
self.figure._send_deleteTraces_msg.assert_called_once_with([0, 2]) | ||
self.assertFalse(self.figure._send_moveTraces_msg.called) | ||
|
||
def test_delete_all_traces(self): | ||
# Delete middle trace | ||
self.figure.data = [] | ||
|
||
# Check messages | ||
self.figure._send_deleteTraces_msg.assert_called_once_with([0, 1, 2]) | ||
self.assertFalse(self.figure._send_moveTraces_msg.called) | ||
|
||
def test_move_and_delete_traces(self): | ||
# Delete middle trace | ||
traces = self.figure.data | ||
self.figure.data = [traces[2], traces[0]] | ||
|
||
# Check messages | ||
self.figure._send_deleteTraces_msg.assert_called_once_with([1]) | ||
self.figure._send_moveTraces_msg.assert_called_once_with( | ||
[0, 1], [1, 0]) |