Skip to content

Commit

Permalink
Added tests for moving/deleting traces
Browse files Browse the repository at this point in the history
  • 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.
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])

0 comments on commit 0543793

Please sign in to comment.