from mock import MagicMock from glue.core.subset import RangeSubsetState, CategoricalROISubsetState from glue.core.component_id import ComponentID from glue.core.component import CategoricalComponent from glue.core.data import Data from glue.core.exceptions import IncompatibleDataException from glue.core.data_collection import DataCollection from glue.core.roi import PolygonalROI from glue.utils import renderless_figure from ..client import HistogramClient from ..layer_artist import HistogramLayerArtist FIGURE = renderless_figure() class TestHistogramClient(object): def setup_method(self, method): self.data = Data(x=[0, 0, 0, 1, 2, 3, 3, 10, 20], y=[-1, -1, -1, -2, -2, -2, -3, -5, -7]) self.subset = self.data.new_subset() self.collect = DataCollection(self.data) self.client = HistogramClient(self.collect, FIGURE) self.axes = self.client.axes FIGURE.canvas.draw = MagicMock() assert FIGURE.canvas.draw.call_count == 0 def draw_count(self):
from matplotlib.ticker import LogFormatterMathtext, ScalarFormatter, FuncFormatter from glue.core.edit_subset_mode import EditSubsetMode from glue.core.component_id import ComponentID from glue.core.component import Component, CategoricalComponent from glue.core.data_collection import DataCollection from glue.core.data import Data from glue.core.roi import RectangularROI, XRangeROI, YRangeROI from glue.core.subset import RangeSubsetState, CategoricalROISubsetState, OrState from glue.tests import example_data from glue.utils import renderless_figure from ..client import ScatterClient # share matplotlib instance, and disable rendering, for speed FIGURE = renderless_figure() class TestScatterClient(object): def setup_method(self, method): self.data = example_data.test_data() self.ids = [ self.data[0].find_component_id('a'), self.data[0].find_component_id('b'), self.data[1].find_component_id('c'), self.data[1].find_component_id('d') ] self.roi_limits = (0.5, 0.5, 1.5, 1.5) self.roi_points = (np.array([1]), np.array([1])) self.collect = DataCollection() EditSubsetMode().data_collection = self.collect
from __future__ import absolute_import, division, print_function from collections import namedtuple import pytest import numpy as np from mock import MagicMock from ..profile_viewer import ProfileViewer from glue.utils import renderless_figure FIG = renderless_figure() Event = namedtuple('Event', 'xdata ydata inaxes button dblclick') class TestProfileViewer(object): def setup_method(self, method): FIG.clf() FIG.canvas.draw = MagicMock() self.viewer = ProfileViewer(FIG) self.axes = self.viewer.axes def test_set_profile(self): self.viewer.set_profile([1, 2, 3], [2, 3, 4]) self.axes.figure.canvas.draw.assert_called_once_with() def test_new_value_callback_fire(self): cb = MagicMock() s = self.viewer.new_value_grip(callback=cb)