Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_views_request(self):
self.workbench.register(TaskManagerManifest())
core = self.workbench.get_plugin(u'enaml.workbench.core')
com = u'hqc_meas.task_manager.views_request'
with enaml.imports():
from hqc_meas.tasks.views.base_task_views import ComplexView
views, miss = core.invoke_command(com,
{'task_classes': ['ComplexTask']},
self)
assert_in('ComplexTask', views)
assert_equal(views['ComplexTask'], ComplexView)
assert_equal(miss, [])
# -*- coding: utf-8 -*-
#==============================================================================
# module : test_workspace.py
# author : Matthieu Dartiailh
# license : MIT license
#==============================================================================
import enaml
from enaml.workbench.api import Workbench
import os
import logging
from configobj import ConfigObj
from nose.tools import (assert_in, assert_not_in, assert_equal, assert_true,
assert_is_instance, assert_false)
from hqc_meas.debug.debugger_workspace import LOG_ID
with enaml.imports():
from enaml.workbench.core.core_manifest import CoreManifest
from enaml.workbench.ui.ui_manifest import UIManifest
from hqc_meas.utils.state.manifest import StateManifest
from hqc_meas.utils.preferences.manifest import PreferencesManifest
from hqc_meas.utils.log.manifest import LogManifest
from hqc_meas.tasks.manager.manifest import TaskManagerManifest
from hqc_meas.instruments.manager.manifest import InstrManagerManifest
from hqc_meas.debug.debugger_manifest import DebuggerManifest
from hqc_meas.app_manifest import HqcAppManifest
from .helpers import (TestSuiteManifest, TestDebugger, TestDebuggerView,
tester)
from ..util import (complete_line, process_app_events, close_all_windows,
remove_tree, create_test_dir)
def test_color_initialization():
"""Test the different initialization format supported by Color.
"""
components = [1, 2, 3, 4]
c = Color(*components)
for name, value in zip(['red', 'green', 'blue', 'alpha'], components):
assert getattr(c, name) == value
c = Color(alpha=-1)
for name in ['red', 'green', 'blue', 'alpha']:
assert getattr(c, name) == 0
assert c._tkdata is None
try:
from enaml.qt.q_resource_helpers import get_cached_qcolor
except Exception:
return
get_cached_qcolor(c)
assert c._tkdata is not None
def setup_package():
sys.path.append('..')
QtApplication()
print('')
print(complete_line(__name__ + '__init__.py : setup_package()', '='))
directory = os.path.dirname(__file__)
util_path = os.path.join(directory, '..', 'hqc_meas', 'utils',
'preferences')
def_path = os.path.join(util_path, 'default.ini')
if os.path.isfile(def_path):
os.rename(def_path, os.path.join(util_path, '_user_default.ini'))
def test_formatter(self):
""" Test setting the formatter of a handler.
"""
if not QtApplication.instance():
QtApplication()
core = self.workbench.get_plugin(u'enaml.workbench.core')
model = PanelModel()
handler = GuiHandler(model=model)
core.invoke_command(u'hqc_meas.logging.add_handler',
{'id': 'ui', 'handler': handler, 'logger': 'test'},
self)
formatter = logging.Formatter('toto : %(message)s')
core.invoke_command(u'hqc_meas.logging.set_formatter',
{'formatter': formatter, 'handler_id': 'ui'},
self)
logger = logging.getLogger('test')
logger.info('test')
def qt_app():
"""Make sure a QtApplication is active.
"""
try:
from enaml.qt.qt_application import QtApplication
except ImportError:
pytest.skip('No Qt binding found: %s' % format_exc())
app = QtApplication.instance()
if app is None:
app = QtApplication()
yield app
app.stop()
else:
yield app
def test_view2(self):
# Intantiate a view with a selected interface.
interface = LinspaceLoopInterface()
self.task.interface = interface
window = enaml.widgets.api.Window()
core = self.workbench.get_plugin('enaml.workbench.core')
LoopView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_is(self.task.interface, interface)
def close_all_windows():
qapp = QtApplication.instance()._qapp
qapp.flush()
qapp.processEvents()
sleep(0.1)
for window in Window.windows:
window.close()
qapp.flush()
qapp.processEvents()
def get_window(qtbot, cls=Window, timeout=1000):
"""Convenience function running the event loop and returning the first
window found in the set of active windows.
Parameters
----------
cls : type, optional
Type of the window which should be returned.
timeout : int, optional
Timeout after which the operation should fail in ms
Returns
-------
window : Window or None
Return the first window found matching the specified class
def test_view1(self):
# Intantiate a view with no selected interface and select one after
window = enaml.widgets.api.Window()
core = self.workbench.get_plugin('enaml.workbench.core')
view = RFFrequencyView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_in('AgilentPNA', view.drivers)
self.task.selected_driver = 'AgilentPNA'
process_app_events()
assert_is_instance(self.task.interface, PNASetRFFrequencyInterface)