def test_two_plots_with_independent_axes(self): c1 = Contour(self.cube, self.axes) levels = 5 other = _add_levels(self.cube, levels)[:, 0] c2 = Contour(other, self.axes) with mock.patch('cube_browser.Contour.__call__') as func: browser = Browser([c1, c2]) browser.display() # Check the initial render. self.assertEqual(func.call_count, 2) expected = [ mock.call(time=self.value), mock.call(model_level_number=self.value) ] func.assert_has_calls(expected) # Now simulate a 'time' slider change. slider = browser._slider_by_name['time'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 3) expected.append(mock.call(time=self.value)) func.assert_has_calls(expected) # Now simulate a 'model_level_number' slider change. slider = browser._slider_by_name['model_level_number'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 4) expected.append(mock.call(model_level_number=self.value)) func.assert_has_calls(expected)
def test_two_plots_with_independent_axes(self): c1 = Contour(self.cube, self.axes) levels = 5 other = _add_levels(self.cube, levels)[:, 0] c2 = Contour(other, self.axes) with mock.patch('cube_browser.Contour.__call__') as func: browser = Browser([c1, c2]) browser.display() # Check the initial render. self.assertEqual(func.call_count, 2) expected = [mock.call(time=self.value), mock.call(model_level_number=self.value)] func.assert_has_calls(expected) # Now simulate a 'time' slider change. slider = browser._slider_by_name['time'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 3) expected.append(mock.call(time=self.value)) func.assert_has_calls(expected) # Now simulate a 'model_level_number' slider change. slider = browser._slider_by_name['model_level_number'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 4) expected.append(mock.call(model_level_number=self.value)) func.assert_has_calls(expected)
def test_single_plot_with_axis(self): plot = Contour(self.cube, self.axes) with mock.patch('cube_browser.Contour.__call__') as func: browser = Browser(plot) browser.display() # Check the initial render. func.assert_called_once_with(time=self.value) # Now simulate a slider change. slider = browser._slider_by_name['time'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 2) expected = [mock.call(time=self.value), mock.call(time=self.value)] func.assert_has_calls(expected)
def test_two_plots_with_shared_axis(self): coords = ('time', 'grid_latitude') c1 = Contour(self.cube, self.axes, coords=coords) c2 = Contour(self.cube, self.axes, coords=coords) with mock.patch('cube_browser.Contour.__call__') as func: browser = Browser([c1, c2]) browser.display() # Check the initial render. expected = [mock.call(grid_longitude=self.value)] self.assertEqual(func.call_args_list, expected * 2) # Now simulate a slider change. slider = browser._slider_by_name['grid_longitude'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_args_list, expected * 4)
def test_two_plots_with_shared_alias_axis(self): coords = ('time', 'grid_longitude') c1 = Contour(self.cube, self.axes, coords=coords) c1.alias(wibble=1) c2 = Contour(self.cube, self.axes, coords=coords) c2.alias(wibble=1) with mock.patch('cube_browser.Contour.__call__') as func: browser = Browser([c1, c2]) browser.display() # Check the initial render. self.assertEqual(func.call_count, 2) expected = [mock.call(wibble=self.value)] * 2 func.assert_has_calls(expected) # Now simulate a slider change. slider = browser._slider_by_name['wibble'] change = dict(owner=slider) browser.on_change(change) self.assertEqual(func.call_count, 4) expected *= 2 func.assert_has_calls(expected)