本文整理汇总了Python中enaml.workbench.api.Workbench.get_plugin方法的典型用法代码示例。如果您正苦于以下问题:Python Workbench.get_plugin方法的具体用法?Python Workbench.get_plugin怎么用?Python Workbench.get_plugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enaml.workbench.api.Workbench
的用法示例。
在下文中一共展示了Workbench.get_plugin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_default
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
def initialize_default(extra_manifests,
workspace='psi.experiment.workspace'):
with enaml.imports():
from enaml.workbench.core.core_manifest import CoreManifest
from enaml.workbench.ui.ui_manifest import UIManifest
from psi.context.manifest import ContextManifest
from psi.data.manifest import DataManifest
from psi.experiment.manifest import ExperimentManifest
with warnings.catch_warnings():
warnings.simplefilter('ignore')
workbench = Workbench()
workbench.register(CoreManifest())
workbench.register(UIManifest())
workbench.register(ContextManifest())
workbench.register(DataManifest())
workbench.register(ExperimentManifest())
for manifest in extra_manifests:
workbench.register(manifest())
core = workbench.get_plugin('enaml.workbench.core')
ui = workbench.get_plugin('enaml.workbench.ui')
ui.show_window()
core.invoke_command('enaml.workbench.ui.select_workspace',
{'workspace': workspace})
experiment = workbench.get_plugin('psi.experiment')
return workbench
示例2: TestPNASetRFFrequencyView
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestPNASetRFFrequencyView(object):
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(InstrManagerManifest())
self.workbench.register(TaskManagerManifest())
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = SetRFFrequencyTask(task_name='Test')
self.root.children_task.append(self.task)
self.root.run_time['drivers'] = {'Test': InstrHelper}
def teardown(self):
close_all_windows()
self.workbench.unregister(u'hqc_meas.task_manager')
self.workbench.unregister(u'hqc_meas.instr_manager')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.core')
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)
def test_view2(self):
# Intantiate a view with a selected interface.
self.task.interface = PNASetRFFrequencyInterface(task=self.task)
self.task.frequency = '1.0'
self.task.selected_driver = 'AgilentPNA'
interface = self.task.interface
window = enaml.widgets.api.Window()
core = self.workbench.get_plugin('enaml.workbench.core')
RFFrequencyView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_is(self.task.interface, interface)
示例3: TestLoadArrayView
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestLoadArrayView(object):
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(TaskManagerManifest())
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = LoadArrayTask(task_name='Test')
self.root.children_task.append(self.task)
def teardown(self):
close_all_windows()
self.workbench.unregister(u'hqc_meas.task_manager')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.core')
def test_view(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 = LoadArrayView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_is(self.task.interface, None)
assert_in('CSV', view.file_formats)
self.task.selected_format = 'CSV'
process_app_events()
assert_is_instance(self.task.interface,
CSVLoadInterface)
def test_view2(self):
# Intantiate a view with a selected interface.
interface = CSVLoadInterface()
self.task.interface = interface
self.task.selected_format = 'CSV'
interface = self.task.interface
window = enaml.widgets.api.Window()
core = self.workbench.get_plugin('enaml.workbench.core')
LoadArrayView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_is(self.task.interface, interface)
示例4: test_registration
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
def test_registration(windows):
"""Test that the manifest is properly regsistered.
"""
w = Workbench()
w.register(CoreManifest())
w.register(ErrorsManifest())
w.register(PackagesManifest())
with signal_error_raise():
w.get_plugin('ecpy.app.packages').collect_and_register()
# Edit the name of the package
assert w.get_plugin('ecpy_ext_demo')
示例5: TestWhileView
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestWhileView(object):
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(TaskManagerManifest())
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = WhileTask(task_name='Test', condition='rr')
self.root.children_task.append(self.task)
def teardown(self):
close_all_windows()
self.workbench.unregister(u'hqc_meas.task_manager')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.core')
def test_view(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 = WhileView(window, task=self.task, core=core)
window.show()
process_app_events()
assert_equal(view.widgets()[1].text, 'rr')
view.widgets()[1].text = 'test'
process_app_events()
assert_equal(self.task.condition, 'test')
示例6: TestApplyMagFieldView
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestApplyMagFieldView(object):
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(InstrManagerManifest())
self.workbench.register(TaskManagerManifest())
self.root = RootTask(should_stop=Event(), should_pause=Event())
self.task = ApplyMagFieldTask(task_name='Test')
self.root.children_task.append(self.task)
self.root.run_time['drivers'] = {'Test': InstrHelper}
def teardown(self):
close_all_windows()
self.workbench.unregister(u'hqc_meas.task_manager')
self.workbench.unregister(u'hqc_meas.instr_manager')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.core')
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 = ApplyMagFieldView(window, task=self.task, core=core)
window.show()
process_app_events()
示例7: TestCollectingFromConfig
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestCollectingFromConfig(object):
"""Test collecting dependencies from ConfigObj object.
"""
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(DependenciesManifest())
self.workbench.register(BuildDep())
def teardown(self):
self.workbench.unregister('ecpy.app.dependencies')
self.workbench.unregister('enaml.workbench.core')
def test_collecting(self):
"""Test collecting from a dict-like object.
"""
core = self.workbench.get_plugin('enaml.workbench.core')
res, dep = core.invoke_command(COLLECT,
{'obj': ConfigObj({'val': '1',
'dep_type': 'test'})}
)
assert res
assert dep.keys() == ['test']
def test_handling_errors(self, monkeypatch):
"""Test handling errors occuring when collecting dependencies.
"""
plugin = self.workbench.get_plugin('ecpy.app.dependencies')
for b in plugin.build_deps.contributions.values():
monkeypatch.setattr(b, 'err', True)
core = self.workbench.get_plugin('enaml.workbench.core')
res, dep = core.invoke_command(COLLECT,
{'obj': ConfigObj({'val': '1',
'dep_type': 'test'})}
)
assert not res
assert 'test' in dep
示例8: workbench
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
def workbench():
workbench = Workbench()
workbench.register(CoreManifest())
workbench.register(ContextManifest())
workbench.register(TestManifest())
context = workbench.get_plugin('psi.context')
print context.selectors['default'].order
print context.selectors['default'].parameters
print context.context_items['repetitions'].rove
for r in (20, 15, 10, 2):
context.selectors['default'].add_setting(dict(repetitions=r))
return workbench
示例9: TestAppPlugin
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestAppPlugin(object):
"""Test the AppPlugin capabilities.
"""
def setup(self):
self.workbench = Workbench()
self.workbench.register(AppManifest())
self.workbench.register(CoreManifest())
self.workbench.register(ErrorsManifest())
def test_app_start_up(self):
"""Test running startups leading to new startup registrations.
"""
manifest = StartupContributor()
self.workbench.register(manifest)
plugin = self.workbench.get_plugin('ecpy.app')
plugin.run_app_startup(object())
assert manifest.called == ['test_nested.startup1', 'test.startup2',
'test_nested.startup2']
self.workbench.unregister('ecpy.app')
def test_closing(self):
"""Test that validation stops as soon as the event is rejected.
"""
manifest1 = ClosingContributor1()
manifest2 = ClosingContributor2()
self.workbench.register(manifest1)
self.workbench.register(manifest2)
window = FalseWindow(self.workbench)
plugin = self.workbench.get_plugin('ecpy.app')
ev = CloseEvent()
plugin.validate_closing(window, ev)
assert not ev.is_accepted()
assert not manifest2.called or not manifest1.called
manifest1.accept = True
manifest2.accept = True
plugin.validate_closing(window, ev)
assert ev.is_accepted()
assert manifest2.called
def test_app_cleanup(self):
"""Test running the app cleanup.
"""
manifest = ClosedContributor()
self.workbench.register(manifest)
plugin = self.workbench.get_plugin('ecpy.app')
plugin.run_app_cleanup()
assert manifest.called == ['test_nested.closed1', 'test.closed2',
'test_nested.closed2']
def test_app_startup_registation(self):
"""Test the AppStartup discovery.
"""
manifest = StartupContributor()
self.workbench.register(manifest)
plugin = self.workbench.get_plugin('ecpy.app')
assert len(plugin.startup.contributions) == 2
assert len(plugin._start_heap) == 2
self.workbench.unregister(manifest.id)
assert not plugin.startup.contributions
assert len(plugin._start_heap) == 0
def test_app_closing_registation(self):
"""Test the AppClosing discovery.
"""
manifest = ClosingContributor1()
self.workbench.register(manifest)
plugin = self.workbench.get_plugin('ecpy.app')
assert len(plugin.closing.contributions) == 1
self.workbench.unregister(manifest.id)
assert not plugin.closing.contributions
def test_app_closed_registation(self):
"""Test the AppClosed discovery.
"""
manifest = ClosedContributor()
self.workbench.register(manifest)
plugin = self.workbench.get_plugin('ecpy.app')
#.........这里部分代码省略.........
示例10: TestPlugin
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestPlugin(object):
test_dir = ''
@classmethod
def setup_class(cls):
print complete_line(__name__ +
':{}.setup_class()'.format(cls.__name__), '-', 77)
# Creating dummy directory for prefs (avoid prefs interferences).
directory = os.path.dirname(__file__)
cls.test_dir = os.path.join(directory, '_temps')
create_test_dir(cls.test_dir)
# Creating dummy default.ini file in utils.
util_path = os.path.join(directory, '..', '..', '..', 'hqc_meas',
'utils', 'preferences')
def_path = os.path.join(util_path, 'default.ini')
# Making the preference manager look for info in test dir.
default = ConfigObj(def_path)
default['folder'] = cls.test_dir
default['file'] = 'default_test.ini'
default.write()
conf = ConfigObj(os.path.join(cls.test_dir, 'default_test.ini'))
path = u'hqc_meas.measurement.monitors.text_monitor'
prefs = {'manifests': repr([(path, 'TextMonitorManifest')])}
conf[u'hqc_meas.measure'] = prefs
path = u'hqc_meas.measure.monitors.text_monitor'
rule1 = {'class_name': 'FormatRule', 'name': 'test_format',
'suffixes': repr(['a', 'b']),
'new_entry_formatting': '{a}/{b}',
'new_entry_suffix': 'c'}
rule2 = {'class_name': 'RejectRule',
'name': 'test_reject',
'suffixes': repr(['a', 'b'])}
conf[path] = {'rules': repr({'rule1': rule1, 'rule2': rule2}),
'default_rules': repr(['rule1'])}
conf.write()
@classmethod
def teardown_class(cls):
print complete_line(__name__ +
':{}.teardown_class()'.format(cls.__name__), '-',
77)
# Removing pref files creating during tests.
remove_tree(cls.test_dir)
# Restoring default.ini file in utils
directory = os.path.dirname(__file__)
util_path = os.path.join(directory, '..', '..', '..', 'hqc_meas',
'utils', 'preferences')
def_path = os.path.join(util_path, 'default.ini')
os.remove(def_path)
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(UIManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(LogManifest())
self.workbench.register(MeasureManifest())
# Needed otherwise the monitor manifest is not registered.
self.workbench.get_plugin(u'hqc_meas.measure')
def teardown(self):
self.workbench.unregister(u'hqc_meas.measure')
self.workbench.unregister(u'hqc_meas.logging')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.ui')
self.workbench.unregister(u'enaml.workbench.core')
def test_plugin_build_rule(self):
""" Test building a rule.
"""
config = {'class_name': 'RejectRule',
'name': 'test_reject',
'suffixes': repr(['a', 'b'])}
id_pl = u'hqc_meas.measure.monitors.text_monitor'
plugin = self.workbench.get_plugin(id_pl)
rule = plugin.build_rule(config)
assert_equal(rule.name, 'test_reject')
assert_equal(rule.suffixes, ['a', 'b'])
assert_equal(rule.__class__.__name__, 'RejectRule')
assert_is(plugin.build_rule({'class_name': None}), None)
def test_plugin_create_monitor1(self):
""" Test creating a default monitor using the plugin.
"""
id_pl = u'hqc_meas.measure.monitors.text_monitor'
plugin = self.workbench.get_plugin(id_pl)
monitor = plugin.create_monitor()
#.........这里部分代码省略.........
示例11: Workbench
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
from psi.controller.base_manifest import ControllerManifest
from psi.experiment.manifest import ExperimentManifest
with warnings.catch_warnings():
warnings.simplefilter('ignore')
workbench = Workbench()
workbench.register(CoreManifest())
workbench.register(UIManifest())
workbench.register(ContextManifest())
workbench.register(DataManifest())
workbench.register(ControllerManifest())
workbench.register(ExperimentManifest())
core = workbench.get_plugin('enaml.workbench.core')
ui = workbench.get_plugin('enaml.workbench.ui')
parameters = core.invoke_command('psi.context.get_parameters')
parameters[0].rove = True
name = parameters[0].name
setting = workbench.get_plugin('psi.setting')
setting.selectors['go'].add_setting({name: 12.0})
ui.show_window()
core.invoke_command('enaml.workbench.ui.select_workspace',
{'workspace': 'psi.experiment.view'})
core.invoke_command('psi.controller.start')
ui.start_application()
示例12: TestDebugSpace
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestDebugSpace(object):
test_dir = ""
@classmethod
def setup_class(cls):
print complete_line(__name__ + ":{}.setup_class()".format(cls.__name__), "-", 77)
# Creating dummy directory for prefs (avoid prefs interferences).
directory = os.path.dirname(__file__)
cls.test_dir = os.path.join(directory, "_temps")
create_test_dir(cls.test_dir)
# Creating dummy default.ini file in utils.
util_path = os.path.join(directory, "..", "..", "hqc_meas", "utils", "preferences")
def_path = os.path.join(util_path, "default.ini")
# Making the preference manager look for info in test dir.
default = ConfigObj(def_path)
default["folder"] = cls.test_dir
default["file"] = "default_test.ini"
default.write()
conf = ConfigObj(os.path.join(cls.test_dir, "default_test.ini"))
conf.write()
@classmethod
def teardown_class(cls):
print complete_line(__name__ + ":{}.teardown_class()".format(cls.__name__), "-", 77)
# Removing pref files creating during tests.
remove_tree(cls.test_dir)
# Restoring default.ini file in utils
directory = os.path.dirname(__file__)
util_path = os.path.join(directory, "..", "..", "hqc_meas", "utils", "preferences")
def_path = os.path.join(util_path, "default.ini")
os.remove(def_path)
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(UIManifest())
self.workbench.register(HqcAppManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(LogManifest())
self.workbench.register(TaskManagerManifest())
self.workbench.register(InstrManagerManifest())
self.workbench.register(DebuggerManifest())
self.workbench.register(TestSuiteManifest())
def teardown(self):
core = self.workbench.get_plugin(u"enaml.workbench.core")
core.invoke_command(u"enaml.workbench.ui.close_workspace", {}, self)
self.workbench.unregister(u"hqc_meas.debug")
self.workbench.unregister(u"tests.suite")
self.workbench.unregister(u"hqc_meas.task_manager")
self.workbench.unregister(u"hqc_meas.instr_manager")
self.workbench.unregister(u"hqc_meas.logging")
self.workbench.unregister(u"hqc_meas.preferences")
self.workbench.unregister(u"hqc_meas.state")
self.workbench.unregister(u"hqc_meas.app")
self.workbench.unregister(u"enaml.workbench.ui")
self.workbench.unregister(u"enaml.workbench.core")
close_all_windows()
def test_life_cycle1(self):
""" Test that workspace starting/closing goes well.
"""
plugin = self.workbench.get_plugin(u"hqc_meas.debug")
core = self.workbench.get_plugin(u"enaml.workbench.core")
cmd = u"enaml.workbench.ui.select_workspace"
core.invoke_command(cmd, {"workspace": u"hqc_meas.debug.workspace"}, self)
log_plugin = self.workbench.get_plugin(u"hqc_meas.logging")
# Check the plugin got the workspace
assert_true(plugin.workspace)
workspace = plugin.workspace
# Check the contribution of the debugger was added to the workspace.
assert_true(tester.contributing)
ui = self.workbench.get_plugin("enaml.workbench.ui")
ui.show_window()
process_app_events()
# Check the workspace registration.
assert_true(workspace.log_model)
assert_in(LOG_ID, log_plugin.handler_ids)
logger = logging.getLogger(__name__)
logger.info("test")
process_app_events()
assert_in("test", workspace.log_model.text)
cmd = u"enaml.workbench.ui.close_workspace"
core.invoke_command(cmd, {}, self)
#.........这里部分代码省略.........
示例13: TestState
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestState(object):
"""Test the handling os states by the state plugin.
"""
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(StateContributor())
def test_get_state(self):
"""Test accessing to a state object through the command.
"""
core = self.workbench.get_plugin(CORE_PLUGIN)
par = {'state_id': STATE_ID}
state = core.invoke_command(GET_STATE,
par, trigger=self)
assert hasattr(state, 'string')
assert state.string == 'init'
with raises(AttributeError):
state.string = 1
self.workbench.unregister('ecpy.app.states')
def test_state_unicity(self):
"""Test that asking twice the same state return the same object.
"""
core = self.workbench.get_plugin(CORE_PLUGIN)
par = {'state_id': STATE_ID}
state1 = core.invoke_command(GET_STATE,
par, trigger=self)
state2 = core.invoke_command(GET_STATE,
par, trigger=self)
assert state1 is state2
def test_member_sync(self):
"""Test that the state is correctly synchronised with the plugin.
"""
core = self.workbench.get_plugin(CORE_PLUGIN)
par = {'state_id': STATE_ID}
state = core.invoke_command(GET_STATE,
par, trigger=self)
plugin = self.workbench.get_plugin('test.states')
plugin.string = 'test'
assert state.string == 'test'
def test_death_notif(self):
"""Test that a state whose plugin is unregistered is marked as dead.
"""
core = self.workbench.get_plugin(CORE_PLUGIN)
par = {'state_id': STATE_ID}
state = core.invoke_command(GET_STATE,
par, trigger=self)
self.workbench.unregister(u'test.states')
assert not state.alive
示例14: TestTemplateConfig
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestTemplateConfig(object):
"""
"""
test_dir = ''
@classmethod
def setup_class(cls):
print complete_line(__name__ +
':{}.setup_class()'.format(cls.__name__), '-', 77)
# Creating dummy directory for prefs (avoid prefs interferences).
cls.test_dir = os.path.join(FILE_DIR, '_temps')
create_test_dir(cls.test_dir)
# Creating dummy default.ini file in utils.
util_path = os.path.join(PACKAGE_PATH, 'utils', 'preferences')
def_path = os.path.join(util_path, 'default.ini')
# Making the preference manager look for info in test dir.
default = ConfigObj(def_path)
default['folder'] = cls.test_dir
default['file'] = 'default_test.ini'
default.write()
# Creating a false template.
template_path = os.path.join(cls.test_dir, 'temp_templates')
os.mkdir(template_path)
conf = ConfigObj()
conf.filename = os.path.join(template_path, 'test.ini')
conf.update(create_template_sequence())
conf.write()
# Saving plugin preferences.
man_conf = {'templates_folders': repr([template_path])}
conf = ConfigObj(os.path.join(cls.test_dir, 'default_test.ini'))
conf[u'hqc_meas.pulses'] = {}
conf[u'hqc_meas.pulses'].update(man_conf)
conf.write()
@classmethod
def teardown_class(cls):
print complete_line(__name__ +
':{}.teardown_class()'.format(cls.__name__), '-',
77)
# Removing pref files creating during tests.
remove_tree(cls.test_dir)
# Restoring default.ini file in utils
util_path = os.path.join(PACKAGE_PATH, 'utils', 'preferences')
def_path = os.path.join(util_path, 'default.ini')
os.remove(def_path)
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(StateManifest())
self.workbench.register(PreferencesManifest())
self.workbench.register(DependenciesManifest())
self.workbench.register(PulsesManagerManifest())
self.plugin = self.workbench.get_plugin('hqc_meas.pulses')
def teardown(self):
self.workbench.unregister(u'hqc_meas.pulses')
self.workbench.unregister(u'hqc_meas.dependencies')
self.workbench.unregister(u'hqc_meas.preferences')
self.workbench.unregister(u'hqc_meas.state')
self.workbench.unregister(u'enaml.workbench.core')
def test_init(self):
# Test the context is properly created at config init.
seqs, _ = self.plugin.sequences_request(['Test'])
_, conf, doc = seqs['Test']
t_config = TemplateConfig(template_doc=doc, template_config=conf)
assert_items_equal(t_config.context.logical_channels, ['A', 'B'])
assert_items_equal(t_config.context.analogical_channels,
['Ch1', 'Ch2'])
assert_equal(t_config.context.channel_mapping,
{'A': '', 'B': '', 'Ch1': '', 'Ch2': ''})
def test_building_template1(self):
# Test building a template.
seqs, _ = self.plugin.sequences_request(['Test'])
_, conf, doc = seqs['Test']
t_config = TemplateConfig(template_doc=doc, template_config=conf,
manager=self.plugin)
t_config.template_name = 'Test'
seq = t_config.build_sequence()
assert_false(t_config.errors)
assert_is_instance(seq, TemplateSequence)
assert_equal(seq.name, 'Test')
# No need to check more as build_from_config is already tested in
# test_template_sequence.
def test_building_template2(self):
# Test building a template for which some dependencies are missing.
#.........这里部分代码省略.........
示例15: TestPreferencesPlugin
# 需要导入模块: from enaml.workbench.api import Workbench [as 别名]
# 或者: from enaml.workbench.api.Workbench import get_plugin [as 别名]
class TestPreferencesPlugin(object):
"""Test the preferences plugin capabilities.
"""
def setup(self):
self.workbench = Workbench()
self.workbench.register(CoreManifest())
self.workbench.register(AppManifest())
self.workbench.register(ErrorsManifest())
@pytest.mark.ui
def test_app_startup1(self, tmpdir, windows):
"""Test app start-up when no app_directory.ini exists.
"""
manifest = PreferencesManifest()
self.workbench.register(manifest)
# Remove any trash app_directory.ini file. The global fixture ensure
# that it cannot be a user file.
app_pref = os.path.join(ecpy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
if os.path.isfile(app_pref):
os.remove(app_pref)
# Start the app and fake a user answer.
app = self.workbench.get_plugin('ecpy.app')
app_dir = str(tmpdir.join('ecpy'))
with handle_dialog(custom=lambda x: setattr(x, 'path', app_dir)):
app.run_app_startup(object())
assert os.path.isfile(app_pref)
assert ConfigObj(app_pref)['app_path'] == app_dir
assert os.path.isdir(app_dir)
@pytest.mark.ui
def test_app_startup2(self, tmpdir, windows):
"""Test app start-up when user quit app.
"""
manifest = PreferencesManifest()
self.workbench.register(manifest)
# Remove any trash app_directory.ini file. The global fixture ensure
# that it cannot be a user file.
app_pref = os.path.join(ecpy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
if os.path.isfile(app_pref):
os.remove(app_pref)
# Start the app and fake a user answer.
app = self.workbench.get_plugin('ecpy.app')
with pytest.raises(SystemExit):
with handle_dialog('reject'):
app.run_app_startup(object())
def test_app_startup3(self, tmpdir, windows):
"""Test app start-up when a preference file already exists.
"""
manifest = PreferencesManifest()
self.workbench.register(manifest)
# Create a trash app_directory.ini file. The global fixture ensure
# that it cannot be a user file. Don't use app_dir fixture as I need to
# test directory creation.
app_pref = os.path.join(ecpy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
app_dir = str(tmpdir.join('ecpy'))
conf = ConfigObj()
conf.filename = app_pref
conf['app_path'] = app_dir
conf.write()
assert not os.path.isdir(app_dir)
# Start the app and fake a user answer.
app = self.workbench.get_plugin('ecpy.app')
app.run_app_startup(object())
assert os.path.isdir(app_dir)
def test_app_startup4(self, tmpdir, windows):
"""Test app start-up when user request to reset app folder.
"""
manifest = PreferencesManifest()
self.workbench.register(manifest)
app_dir = str(tmpdir.join('ecpy'))
# Add a app_directory.ini file.
app_pref = os.path.join(ecpy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
if not os.path.isfile(app_pref):
conf = ConfigObj()
conf.filename = app_pref
conf['app_path'] = app_dir
conf.write()
#.........这里部分代码省略.........