本文整理汇总了Python中glue.app.qt.GlueApplication.close方法的典型用法代码示例。如果您正苦于以下问题:Python GlueApplication.close方法的具体用法?Python GlueApplication.close怎么用?Python GlueApplication.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glue.app.qt.GlueApplication
的用法示例。
在下文中一共展示了GlueApplication.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_close_on_last_layer_remove
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_close_on_last_layer_remove(self):
# regression test for 391
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(y=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
with patch.object(self.widget_cls, 'close') as close:
w = app.new_data_viewer(self.widget_cls, data=d1)
w.add_data(d2)
dc.remove(d1)
dc.remove(d2)
assert close.call_count >= 1
app.close()
示例2: TestDataTableModel
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestDataTableModel():
def setup_method(self, method):
self.gapp = GlueApplication()
self.viewer = self.gapp.new_data_viewer(TableViewer)
self.data = Data(x=[1, 2, 3, 4], y=[2, 3, 4, 5])
self.gapp.data_collection.append(self.data)
self.viewer.add_data(self.data)
self.model = DataTableModel(self.viewer)
def teardown_method(self, method):
self.gapp.close()
self.gapp = None
def test_column_count(self):
assert self.model.columnCount() == 2
def test_column_count_hidden(self):
self.model.show_coords = True
assert self.model.columnCount() == 4
def test_header_data(self):
for i, c in enumerate(self.data.main_components):
result = self.model.headerData(i, Qt.Horizontal, Qt.DisplayRole)
assert result == c.label
for i in range(self.data.size):
result = self.model.headerData(i, Qt.Vertical, Qt.DisplayRole)
assert result == str(i)
def test_row_count(self):
assert self.model.rowCount() == 4
def test_data(self):
for i, c in enumerate(self.data.main_components):
for j in range(self.data.size):
idx = self.model.index(j, i)
result = self.model.data(idx, Qt.DisplayRole)
assert float(result) == self.data[c, j]
@pytest.mark.xfail
def test_data_2d(self):
self.data = Data(x=[[1, 2], [3, 4]], y=[[2, 3], [4, 5]])
self.model = DataTableModel(self.data)
for i, c in enumerate(self.data.main_components):
for j in range(self.data.size):
idx = self.model.index(j, i)
result = self.model.data(idx, Qt.DisplayRole)
assert float(result) == self.data[c].ravel()[j]
示例3: test_single_draw_call_on_create
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_single_draw_call_on_create(self):
d = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d])
app = GlueApplication(dc)
try:
from glue.viewers.matplotlib.qt.widget import MplCanvas
draw = MplCanvas.draw
MplCanvas.draw = MagicMock()
app.new_data_viewer(self.widget_cls, data=d)
# each Canvas instance gives at most 1 draw call
selfs = [c[0][0] for c in MplCanvas.draw.call_arg_list]
assert len(set(selfs)) == len(selfs)
finally:
MplCanvas.draw = draw
app.close()
示例4: test_close_on_last_layer_remove
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_close_on_last_layer_remove(self):
# regression test for 391
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(y=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.add_data(d2)
process_events()
assert len(app.viewers[0]) == 1
dc.remove(d1)
process_events()
assert len(app.viewers[0]) == 1
dc.remove(d2)
process_events()
assert len(app.viewers[0]) == 0
app.close()
示例5: test_add_viewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_add_viewer(self, tmpdir):
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.viewer_size = (300, 400)
filename = tmpdir.join('session.glu').strpath
app.save_session(filename, include_data=True)
app2 = GlueApplication.restore_session(filename)
# test session is restored correctly
for viewer in app2.viewers:
assert viewer[0].viewer_size == (300, 400)
app.close()
app2.close()
示例6: test_viewer_size
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_viewer_size(self, tmpdir):
# regression test for #781
# viewers were not restored with the right size
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.viewer_size = (300, 400)
filename = tmpdir.join('session.glu').strpath
app.save_session(filename, include_data=True)
app2 = GlueApplication.restore_session(filename)
for viewer in app2.viewers:
assert viewer[0].viewer_size == (300, 400)
app.close()
app2.close()
示例7: test_close_on_last_layer_remove
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_close_on_last_layer_remove(self):
# regression test for 391
# Note: processEvents is needed for things to work correctly with PySide2
qtapp = get_qapp()
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(y=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.add_data(d2)
qtapp.processEvents()
assert len(app.viewers[0]) == 1
dc.remove(d1)
qtapp.processEvents()
assert len(app.viewers[0]) == 1
dc.remove(d2)
qtapp.processEvents()
assert len(app.viewers[0]) == 0
app.close()
示例8: TestProfileViewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestProfileViewer(object):
def setup_method(self, method):
self.data = Data(label='d1')
self.data.coords = SimpleCoordinates()
self.data['x'] = np.arange(24).reshape((3, 4, 2))
self.app = GlueApplication()
self.session = self.app.session
self.hub = self.session.hub
self.data_collection = self.session.data_collection
self.data_collection.append(self.data)
self.viewer = self.app.new_data_viewer(ProfileViewer)
def teardown_method(self, method):
self.viewer.close()
self.viewer = None
self.app.close()
self.app = None
def test_functions(self):
self.viewer.add_data(self.data)
self.viewer.state.function = 'mean'
assert len(self.viewer.layers) == 1
layer_artist = self.viewer.layers[0]
assert_allclose(layer_artist.state.profile[0], [0, 2, 4])
assert_allclose(layer_artist.state.profile[1], [3.5, 11.5, 19.5])
def test_incompatible(self):
self.viewer.add_data(self.data)
data2 = Data(y=np.random.random((3, 4, 2)))
self.data_collection.append(data2)
self.viewer.add_data(data2)
assert len(self.viewer.layers) == 2
assert self.viewer.layers[0].enabled
assert not self.viewer.layers[1].enabled
def test_selection(self):
self.viewer.add_data(self.data)
self.viewer.state.x_att = self.data.pixel_component_ids[0]
roi = XRangeROI(0.9, 2.1)
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
assert_equal(self.data.subsets[0].to_mask()[:, 0, 0], [0, 1, 1])
self.viewer.state.x_att = self.data.world_component_ids[0]
roi = XRangeROI(1.9, 3.1)
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
assert_equal(self.data.subsets[0].to_mask()[:, 0, 0], [0, 1, 0])
def test_enabled_layers(self):
data2 = Data(label='d1', y=np.arange(24).reshape((3, 4, 2)))
self.data_collection.append(data2)
self.viewer.add_data(self.data)
self.viewer.add_data(data2)
assert self.viewer.layers[0].enabled
assert not self.viewer.layers[1].enabled
self.data_collection.add_link(ComponentLink([data2.world_component_ids[1]], self.data.world_component_ids[0], using=lambda x: 2 * x))
assert self.viewer.layers[0].enabled
assert self.viewer.layers[1].enabled
def test_slice_subset_state(self):
self.viewer.add_data(self.data)
subset = self.data.new_subset()
subset.subset_state = SliceSubsetState(self.data, [slice(1, 2), slice(None)])
assert self.viewer.layers[0].enabled
assert self.viewer.layers[1].enabled
def test_clone(self):
# Regression test for a bug that meant that deserializing a profile
# viewer resulted in disabled layers
self.viewer.add_data(self.data)
subset = self.data.new_subset()
subset.subset_state = SliceSubsetState(self.data, [slice(1, 2), slice(None)])
app = clone(self.app)
#.........这里部分代码省略.........
示例9: TestPlotly
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestPlotly(object):
def setup_method(self, method):
d = Data(x=[1, 2, 3], y=[2, 3, 4], z=['a', 'b', 'c'], label='data')
dc = DataCollection([d])
self.app = GlueApplication(dc)
self.data = d
def teardown_method(self, method):
self.app.close()
self.app = None
def test_scatter(self):
d = self.data
d.style.markersize = 6
d.style.color = '#ff0000'
d.style.alpha = .4
viewer = self.app.new_data_viewer(ScatterViewer, data=d)
viewer.state.x_att = d.id['y']
viewer.state.y_att = d.id['x']
args, kwargs = build_plotly_call(self.app)
data = args[0]['data'][0]
expected = dict(type='scatter', mode='markers', name=d.label,
marker=dict(size=6, color='rgba(255, 0, 0, 0.4)',
symbol='circle'))
for k, v in expected.items():
assert data[k] == v
np.testing.assert_array_equal(data['x'], d['y'])
np.testing.assert_array_equal(data['y'], d['x'])
layout = args[0]['layout']
assert layout['showlegend']
viewer.close()
def test_scatter_subset(self):
d = self.data
s = d.new_subset(label='subset')
s.subset_state = d.id['x'] > 1
s.style.marker = 's'
viewer = self.app.new_data_viewer(ScatterViewer, data=d)
viewer.state.x_att = d.id['x']
viewer.state.y_att = d.id['x']
args, kwargs = build_plotly_call(self.app)
data = args[0]['data']
# check that subset is on Top
assert len(data) == 2
assert data[0]['name'] == 'data'
assert data[1]['name'] == 'subset'
viewer.close()
def test_axes(self):
viewer = self.app.new_data_viewer(ScatterViewer, data=self.data)
viewer.state.x_log = True
viewer.state.x_min = 10
viewer.state.x_max = 100
viewer.state.x_att = self.data.id['x']
viewer.state.y_log = False
viewer.state.y_min = 2
viewer.state.y_max = 4
viewer.state.y_att = self.data.id['y']
args, kwargs = build_plotly_call(self.app)
xaxis = dict(type='log', rangemode='normal',
range=[1, 2], title='x', zeroline=False)
yaxis = dict(type='linear', rangemode='normal',
range=[2, 4], title='y', zeroline=False)
layout = args[0]['layout']
for k, v in layout['xaxis'].items():
assert xaxis.get(k, v) == v
for k, v in layout['yaxis'].items():
assert yaxis.get(k, v) == v
viewer.close()
def test_histogram(self):
d = self.data
d.style.color = '#000000'
viewer = self.app.new_data_viewer(HistogramViewer, data=d)
viewer.state.x_att = d.id['y']
viewer.state.hist_x_min = 0
viewer.state.hist_x_max = 10
viewer.state.hist_n_bin = 20
#.........这里部分代码省略.........
示例10: TestImageViewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestImageViewer(object):
def setup_method(self, method):
self.coords = MyCoords()
self.image1 = Data(label='image1', x=[[1, 2], [3, 4]], y=[[4, 5], [2, 3]])
self.image2 = Data(label='image2', a=[[3, 3], [2, 2]], b=[[4, 4], [3, 2]],
coords=self.coords)
self.catalog = Data(label='catalog', c=[1, 3, 2], d=[4, 3, 3])
self.hypercube = Data(label='hypercube', x=np.arange(120).reshape((2, 3, 4, 5)))
# Create data versions with WCS coordinates
self.image1_wcs = Data(label='image1_wcs', x=self.image1['x'],
coords=WCSCoordinates(wcs=WCS(naxis=2)))
self.hypercube_wcs = Data(label='hypercube_wcs', x=self.hypercube['x'],
coords=WCSCoordinates(wcs=WCS(naxis=4)))
self.application = GlueApplication()
self.session = self.application.session
self.hub = self.session.hub
self.data_collection = self.session.data_collection
self.data_collection.append(self.image1)
self.data_collection.append(self.image2)
self.data_collection.append(self.catalog)
self.data_collection.append(self.hypercube)
self.data_collection.append(self.image1_wcs)
self.data_collection.append(self.hypercube_wcs)
self.viewer = self.application.new_data_viewer(ImageViewer)
self.data_collection.register_to_hub(self.hub)
self.viewer.register_to_hub(self.hub)
self.options_widget = self.viewer.options_widget()
def teardown_method(self, method):
self.viewer.close()
self.viewer = None
self.application.close()
self.application = None
def test_basic(self):
# Check defaults when we add data
self.viewer.add_data(self.image1)
assert combo_as_string(self.options_widget.ui.combosel_x_att_world) == 'Coordinate components:World 0:World 1'
assert combo_as_string(self.options_widget.ui.combosel_y_att_world) == 'Coordinate components:World 0:World 1'
assert self.viewer.axes.get_xlabel() == 'World 1'
assert self.viewer.state.x_att_world is self.image1.id['World 1']
assert self.viewer.state.x_att is self.image1.pixel_component_ids[1]
# TODO: make sure limits are deterministic then update this
# assert self.viewer.state.x_min == -0.5
# assert self.viewer.state.x_max == +1.5
assert self.viewer.axes.get_ylabel() == 'World 0'
assert self.viewer.state.y_att_world is self.image1.id['World 0']
assert self.viewer.state.y_att is self.image1.pixel_component_ids[0]
# TODO: make sure limits are deterministic then update this
# assert self.viewer.state.y_min == -0.5
# assert self.viewer.state.y_max == +1.5
assert not self.viewer.state.x_log
assert not self.viewer.state.y_log
assert len(self.viewer.state.layers) == 1
def test_custom_coords(self):
# Check defaults when we add data with coordinates
self.viewer.add_data(self.image2)
assert combo_as_string(self.options_widget.ui.combosel_x_att_world) == 'Coordinate components:Banana:Apple'
assert combo_as_string(self.options_widget.ui.combosel_x_att_world) == 'Coordinate components:Banana:Apple'
assert self.viewer.axes.get_xlabel() == 'Apple'
assert self.viewer.state.x_att_world is self.image2.id['Apple']
assert self.viewer.state.x_att is self.image2.pixel_component_ids[1]
assert self.viewer.axes.get_ylabel() == 'Banana'
assert self.viewer.state.y_att_world is self.image2.id['Banana']
assert self.viewer.state.y_att is self.image2.pixel_component_ids[0]
def test_flip(self):
self.viewer.add_data(self.image1)
x_min_start = self.viewer.state.x_min
x_max_start = self.viewer.state.x_max
self.options_widget.button_flip_x.click()
assert self.viewer.state.x_min == x_max_start
assert self.viewer.state.x_max == x_min_start
#.........这里部分代码省略.........
示例11: TestScatterViewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestScatterViewer(object):
def setup_method(self, method):
self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3],
y=[3.2, 3.3, 3.4, 3.5], z=['a', 'b', 'c', 'a'])
self.data_2d = Data(label='d2', a=[[1, 2], [3, 4]], b=[[5, 6], [7, 8]],
x=[[3, 5], [5.4, 1]], y=[[1.2, 4], [7, 8]])
self.app = GlueApplication()
self.session = self.app.session
self.hub = self.session.hub
self.data_collection = self.session.data_collection
self.data_collection.append(self.data)
self.data_collection.append(self.data_2d)
self.viewer = self.app.new_data_viewer(ScatterViewer)
def teardown_method(self, method):
self.viewer.close()
self.viewer = None
self.app.close()
self.app = None
def test_basic(self):
viewer_state = self.viewer.state
# Check defaults when we add data
self.viewer.add_data(self.data)
assert combo_as_string(self.viewer.options_widget().ui.combosel_x_att) == 'Main components:x:y:z:Coordinate components:Pixel Axis 0 [x]:World 0'
assert combo_as_string(self.viewer.options_widget().ui.combosel_y_att) == 'Main components:x:y:z:Coordinate components:Pixel Axis 0 [x]:World 0'
assert viewer_state.x_att is self.data.id['x']
assert_allclose(viewer_state.x_min, -1.1 - 0.18)
assert_allclose(viewer_state.x_max, 3.4 + 0.18)
assert viewer_state.y_att is self.data.id['y']
assert_allclose(viewer_state.y_min, 3.2 - 0.012)
assert_allclose(viewer_state.y_max, 3.5 + 0.012)
assert not viewer_state.x_log
assert not viewer_state.y_log
assert len(viewer_state.layers) == 1
# Change to categorical component and check new values
viewer_state.y_att = self.data.id['z']
assert viewer_state.x_att is self.data.id['x']
assert_allclose(viewer_state.x_min, -1.1 - 0.18)
assert_allclose(viewer_state.x_max, 3.4 + 0.18)
assert viewer_state.y_att is self.data.id['z']
assert_allclose(viewer_state.y_min, -0.5 - 0.12)
assert_allclose(viewer_state.y_max, 2.5 + 0.12)
assert not viewer_state.x_log
assert not viewer_state.y_log
def test_flip(self):
viewer_state = self.viewer.state
self.viewer.add_data(self.data)
assert_allclose(viewer_state.x_min, -1.1 - 0.18)
assert_allclose(viewer_state.x_max, 3.4 + 0.18)
self.viewer.options_widget().button_flip_x.click()
assert_allclose(viewer_state.x_max, -1.1 - 0.18)
assert_allclose(viewer_state.x_min, 3.4 + 0.18)
assert_allclose(viewer_state.y_min, 3.2 - 0.012)
assert_allclose(viewer_state.y_max, 3.5 + 0.012)
self.viewer.options_widget().button_flip_y.click()
assert_allclose(viewer_state.y_max, 3.2 - 0.012)
assert_allclose(viewer_state.y_min, 3.5 + 0.012)
def test_remove_data(self):
self.viewer.add_data(self.data)
assert combo_as_string(self.viewer.options_widget().ui.combosel_x_att) == 'Main components:x:y:z:Coordinate components:Pixel Axis 0 [x]:World 0'
assert combo_as_string(self.viewer.options_widget().ui.combosel_y_att) == 'Main components:x:y:z:Coordinate components:Pixel Axis 0 [x]:World 0'
self.data_collection.remove(self.data)
assert combo_as_string(self.viewer.options_widget().ui.combosel_x_att) == ''
assert combo_as_string(self.viewer.options_widget().ui.combosel_y_att) == ''
def test_update_component_updates_title(self):
self.viewer.add_data(self.data)
assert self.viewer.windowTitle() == '2D Scatter'
self.viewer.state.x_att = self.data.id['y']
assert self.viewer.windowTitle() == '2D Scatter'
def test_combo_updates_with_component_add(self):
#.........这里部分代码省略.........
示例12: TestDendrogramViewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestDendrogramViewer():
def setup_method(self, method):
self.data = Data(label='d1', parent=[-1, 0, 1, 1], height=[1.3, 2.2, 3.2, 4.4])
self.app = GlueApplication()
self.session = self.app.session
self.hub = self.session.hub
self.data_collection = self.session.data_collection
self.data_collection.append(self.data)
self.viewer = self.app.new_data_viewer(DendrogramViewer)
self.data_collection.register_to_hub(self.hub)
self.viewer.register_to_hub(self.hub)
def teardown_method(self, method):
self.viewer.close()
self.viewer = None
self.app.close()
self.app = None
def test_point_select(self):
self.viewer.add_data(self.data)
# By default selecting a structure selects all substructures
roi = PointROI(0.5, 1.5)
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
mask1 = self.data.subsets[0].subset_state.to_mask(self.data)
assert_equal(mask1, [0, 1, 1, 1])
# But this option can be turned off
self.viewer.state.select_substruct = False
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
mask1 = self.data.subsets[0].subset_state.to_mask(self.data)
assert_equal(mask1, [0, 1, 0, 0])
self.viewer.state.select_substruct = True
# Try selecting a leaf
roi = PointROI(0.2, 2.8)
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
mask1 = self.data.subsets[0].subset_state.to_mask(self.data)
assert_equal(mask1, [0, 0, 1, 0])
# Try selecting another leaf
roi = PointROI(0.7, 2.8)
self.viewer.apply_roi(roi)
assert len(self.data.subsets) == 1
mask1 = self.data.subsets[0].subset_state.to_mask(self.data)
assert_equal(mask1, [0, 0, 0, 1])
def test_attribute_change_triggers_relayout(self):
self.data.add_component([4, 5, 6, 7], 'flux')
self.viewer.add_data(self.data)
l = self.viewer.state._layout
self.viewer.state.height_att = self.data.id['flux']
assert self.viewer.state._layout is not l
示例13: TestQtPlotlyExporter
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestQtPlotlyExporter():
def setup_class(self):
data = Data(x=[1, 2, 3], y=[2, 3, 4], label='data')
dc = DataCollection([data])
self.app = GlueApplication(dc)
data.style.color = '#000000'
v = self.app.new_data_viewer(HistogramViewer, data=data)
v.component = data.id['y']
v.xmin = 0
v.xmax = 10
v.bins = 20
self.args, self.kwargs = build_plotly_call(self.app)
def teardown_class(self):
self.app.close()
self.app = None
def get_exporter(self):
return QtPlotlyExporter(plotly_args=self.args, plotly_kwargs=self.kwargs)
def test_default_no_credentials(self, tmpdir):
credentials_file = tmpdir.join('.credentials').strpath
make_credentials_file(credentials_file)
with patch('plotly.tools.CREDENTIALS_FILE', credentials_file):
exporter = self.get_exporter()
assert not exporter.radio_account_config.isChecked()
assert exporter.radio_account_manual.isChecked()
assert exporter.radio_sharing_secret.isChecked()
def test_default_with_credentials(self, tmpdir):
credentials_file = tmpdir.join('.credentials').strpath
make_credentials_file(credentials_file, username='batman', api_key='batmobile')
with patch('plotly.tools.CREDENTIALS_FILE', credentials_file):
exporter = self.get_exporter()
assert exporter.radio_account_config.isChecked()
assert 'username: batman' in exporter.radio_account_config.text()
assert exporter.radio_sharing_secret.isChecked()
def test_edit_username_toggle_custom(self, tmpdir):
credentials_file = tmpdir.join('.credentials').strpath
make_credentials_file(credentials_file, username='batman', api_key='batmobile')
with patch('plotly.tools.CREDENTIALS_FILE', credentials_file):
exporter = self.get_exporter()
assert exporter.radio_account_config.isChecked()
exporter.username = 'a'
assert exporter.radio_account_manual.isChecked()
exporter.radio_account_config.setChecked(True)
assert exporter.radio_account_config.isChecked()
exporter.api_key = 'a'
assert exporter.radio_account_manual.isChecked()
def test_accept_default(self, tmpdir):
credentials_file = tmpdir.join('.credentials').strpath
make_credentials_file(credentials_file, username='batman', api_key='batmobile')
with patch('plotly.tools.CREDENTIALS_FILE', credentials_file):
with patch('plotly.plotly.plot', mock.MagicMock()):
with patch('plotly.plotly.sign_in', mock.MagicMock()):
with patch('webbrowser.open_new_tab') as open_new_tab:
exporter = self.get_exporter()
exporter.accept()
assert exporter.text_status.text() == 'Exporting succeeded'
ERRORS = [
(PlotlyError(SIGN_IN_ERROR), 'Authentication failed'),
(PlotlyError(MAX_PRIVATE_ERROR), 'Maximum number of private plots reached'),
(PlotlyError('Oh noes!'), 'An unexpected error occurred'),
(TypeError('A banana is not an apple'), 'An unexpected error occurred')
]
@pytest.mark.parametrize(('error', 'status'), ERRORS)
def test_accept_errors(self, tmpdir, error, status):
credentials_file = tmpdir.join('.credentials').strpath
make_credentials_file(credentials_file, username='batman', api_key='batmobile')
#.........这里部分代码省略.........
示例14: TestHistogramViewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
class TestHistogramViewer(object):
def setup_method(self, method):
self.data = Data(label='d1', x=[3.4, 2.3, -1.1, 0.3], y=['a', 'b', 'c', 'a'])
self.app = GlueApplication()
self.session = self.app.session
self.hub = self.session.hub
self.data_collection = self.session.data_collection
self.data_collection.append(self.data)
self.viewer = self.app.new_data_viewer(HistogramViewer)
def teardown_method(self, method):
self.viewer.close()
self.viewer = None
self.app.close()
self.app = None
def test_basic(self):
viewer_state = self.viewer.state
# Check defaults when we add data
self.viewer.add_data(self.data)
assert combo_as_string(self.viewer.options_widget().ui.combosel_x_att) == 'Main components:x:y:Coordinate components:Pixel Axis 0 [x]:World 0'
assert viewer_state.x_att is self.data.id['x']
assert viewer_state.x_min == -1.1
assert viewer_state.x_max == 3.4
assert viewer_state.y_min == 0.0
assert viewer_state.y_max == 1.2
assert viewer_state.hist_x_min == -1.1
assert viewer_state.hist_x_max == 3.4
assert viewer_state.hist_n_bin == 15
assert not viewer_state.cumulative
assert not viewer_state.normalize
assert not viewer_state.x_log
assert not viewer_state.y_log
assert len(viewer_state.layers) == 1
# Change to categorical component and check new values
viewer_state.x_att = self.data.id['y']
assert viewer_state.x_min == -0.5
assert viewer_state.x_max == 2.5
assert viewer_state.y_min == 0.0
assert viewer_state.y_max == 2.4
assert viewer_state.hist_x_min == -0.5
assert viewer_state.hist_x_max == 2.5
assert viewer_state.hist_n_bin == 3
assert not viewer_state.cumulative
assert not viewer_state.normalize
assert not viewer_state.x_log
assert not viewer_state.y_log
def test_log_labels(self):
# Regression test to make sure the labels are correctly changed to log
# when the x-axis is in log space.
viewer_state = self.viewer.state
data = Data(x=np.logspace(-5, 5, 10000))
self.data_collection.append(data)
self.viewer.add_data(data)
viewer_state.x_log = True
labels = [x.get_text() for x in self.viewer.axes.xaxis.get_ticklabels()]
# Different Matplotlib versions return slightly different
# labels, but the ones below should be present regardless
# of Matplotlib version.
expected_present = ['$\\mathdefault{10^{-5}}$',
'$\\mathdefault{10^{-3}}$',
'$\\mathdefault{10^{-1}}$',
'$\\mathdefault{10^{1}}$',
'$\\mathdefault{10^{3}}$',
'$\\mathdefault{10^{5}}$']
for label in expected_present:
assert label in labels
def test_flip(self):
viewer_state = self.viewer.state
self.viewer.add_data(self.data)
#.........这里部分代码省略.........
示例15: test_foreground_background_settings
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import close [as 别名]
def test_foreground_background_settings():
d_1d = Data(x=np.random.random(100), y=np.random.random(100), label='Data 1d')
d_2d = Data(x=np.random.random((100, 100)), y=np.random.random((100, 100)), label='Data 2d')
dc = DataCollection([d_1d, d_2d])
app = GlueApplication(dc)
# Make sure that settings change existing viewers, so we create a bunch of
# viewers here.
scatter1 = app.new_data_viewer(ScatterViewer)
scatter1.add_data(d_1d)
image1 = app.new_data_viewer(ImageViewer)
image1.add_data(d_2d)
histogram1 = app.new_data_viewer(HistogramViewer)
histogram1.add_data(d_1d)
dendrogram1 = app.new_data_viewer(DendrogramViewer)
example_custom = _generate_custom_viewer()
custom1 = app.new_data_viewer(example_custom)
RED = (1, 0, 0, 0.5)
GREEN = (0, 1, 0, 0.6)
app.show()
with patch('glue.config.settings') as settings:
settings.FOREGROUND_COLOR = 'black'
settings.BACKGROUND_COLOR = 'white'
settings.DATA_COLOR = '0.5'
settings.DATA_ALPHA = 0.5
settings.FONT_SIZE = 8.0
dialog = PreferencesDialog(app)
dialog.show()
dialog.background = RED
dialog.foreground = GREEN
dialog.accept()
assert_axes_background(scatter1.axes, RED)
assert_axes_background(image1.axes, RED)
assert_axes_background(histogram1.axes, RED)
assert_axes_background(dendrogram1.axes, RED)
assert_axes_background(custom1.axes, RED)
assert_axes_foreground(scatter1.axes, GREEN)
assert_axes_foreground(image1.axes, GREEN)
assert_axes_foreground(histogram1.axes, GREEN)
assert_axes_foreground(dendrogram1.axes, GREEN)
assert_axes_foreground(custom1.axes, GREEN)
# Now make sure that new viewers also inherit these settings
scatter2 = app.new_data_viewer(ScatterViewer)
scatter2.add_data(d_1d)
image2 = app.new_data_viewer(ImageViewer)
image2.add_data(d_2d)
histogram2 = app.new_data_viewer(HistogramViewer)
histogram2.add_data(d_1d)
dendrogram2 = app.new_data_viewer(DendrogramViewer)
custom2 = app.new_data_viewer(example_custom)
assert_axes_background(scatter2.axes, RED)
assert_axes_background(image2.axes, RED)
assert_axes_background(histogram2.axes, RED)
assert_axes_background(dendrogram2.axes, RED)
assert_axes_background(custom2.axes, RED)
assert_axes_foreground(scatter2.axes, GREEN)
assert_axes_foreground(image2.axes, GREEN)
assert_axes_foreground(histogram2.axes, GREEN)
assert_axes_foreground(dendrogram2.axes, GREEN)
assert_axes_foreground(custom2.axes, GREEN)
app.close()