本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.open_context方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.open_context方法的具体用法?Python DomainContextHandler.open_context怎么用?Python DomainContextHandler.open_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.settings.DomainContextHandler
的用法示例。
在下文中一共展示了DomainContextHandler.open_context方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DomainContextSettingsHandlerTests
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import open_context [as 别名]
class DomainContextSettingsHandlerTests(unittest.TestCase):
def setUp(self):
self.handler = DomainContextHandler(attributes_in_res=True,
metas_in_res=True)
self.handler.read_defaults = lambda: None # Disable reading settings from disk
self.handler.bind(MockWidget)
self.widget = MockWidget()
encoded_attributes, encoded_metas = self.handler.encode_domain(domain)
self.widget.current_context.attributes = encoded_attributes
self.widget.current_context.metas = encoded_metas
self.handler.initialize(self.widget)
self.handler.initialize(self.widget.subprovider)
self.handler.open_context(self.widget, domain)
def test_settings_from_widget(self):
widget = self.widget
widget.ordinary_setting = VALUE
widget.string_setting = VALUE
widget.list_setting = [1, 2, 3]
widget.dict_setting = {1: 2}
widget.continuous_setting = CONTINOUS_ATTR
widget.discrete_setting = DISCRETE_ATTR_ABC
widget.class_setting = DISCRETE_CLASS_GHI
widget.excluded_meta_setting = DISCRETE_META_JKL
widget.meta_setting = DISCRETE_META_JKL
self.handler.settings_from_widget(widget)
values = widget.current_context.values
self.assertEqual((VALUE, UNKNOWN_TYPE), values['ordinary_setting'])
self.assertEqual((VALUE, UNKNOWN_TYPE), values['string_setting'])
self.assertEqual([1, 2, 3], values['list_setting'])
self.assertEqual(({1: 2}, UNKNOWN_TYPE), values['dict_setting'])
self.assertEqual((CONTINOUS_ATTR, Continuous), values['continuous_setting'])
self.assertEqual((DISCRETE_ATTR_ABC, Discrete), values['discrete_setting'])
self.assertEqual((DISCRETE_CLASS_GHI, Discrete), values['class_setting'])
self.assertEqual((DISCRETE_META_JKL, UNKNOWN_TYPE), values['excluded_meta_setting'])
self.assertEqual((DISCRETE_META_JKL, Discrete), values['meta_setting'])
def test_settings_to_widget(self):
self.widget.current_context.values = dict(
string_setting=(VALUE, -2),
continuous_setting=(CONTINOUS_ATTR, Continuous),
discrete_setting=(DISCRETE_ATTR_ABC, Discrete),
list_setting=[1, 2, 3],
attr_list_setting=[DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI],
selection1=[0],
attr_tuple_list_setting=[(DISCRETE_META_JKL, Discrete),
(CONTINUOUS_META, Continuous)],
selection2=[1],
)
self.handler.settings_to_widget(self.widget)
self.assertEqual(self.widget.string_setting, VALUE)
self.assertEqual(self.widget.continuous_setting, CONTINOUS_ATTR)
self.assertEqual(self.widget.discrete_setting, DISCRETE_ATTR_ABC)
self.assertEqual(self.widget.list_setting, [1, 2, 3])
self.assertEqual(self.widget.attr_list_setting, [DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI])
self.assertEqual(self.widget.attr_tuple_list_setting,
[DISCRETE_META_JKL, CONTINUOUS_META])
self.assertEqual(self.widget.selection1, [0])
self.assertEqual(self.widget.selection2, [1])
def test_settings_to_widget_filters_selections(self):
self.widget.current_context.values = dict(
attr_list_setting=[DISCRETE_META_JKL, DISCRETE_ATTR_ABC,
CONTINUOUS_META, DISCRETE_CLASS_GHI],
selection1=[1, 2],
)
self.handler.settings_to_widget(self.widget)
self.assertEqual(self.widget.attr_list_setting, [DISCRETE_ATTR_ABC, DISCRETE_CLASS_GHI])
self.assertEqual(self.widget.selection1, [0])
def test_perfect_match_returns_2(self):
attrs, metas = self.handler.encode_domain(domain)
mock_context = Mock(attributes=attrs, metas=metas, values={})
self.assertEqual(self.match(mock_context), 2.)
def test_match_when_nothing_to_match_returns_point_1(self):
attrs, metas = self.handler.encode_domain(domain)
mock_context = Mock(values={})
self.assertEqual(self.match(mock_context), 0.1)
def test_match_if_all_values_match_returns_1(self):
mock_context = Mock(values=dict(
discrete_setting=(DISCRETE_ATTR_ABC, Discrete),
required_setting=(DISCRETE_ATTR_ABC, Discrete),
))
self.assertEqual(self.match(mock_context), 1.)
def test_match_if_all_list_values_match_returns_1(self):
mock_context = Mock(values=dict(
discrete_setting=("df1", Discrete)
))
#.........这里部分代码省略.........
示例2: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import open_context [as 别名]
#.........这里部分代码省略.........
))
self.assertEqual(1., self.handler.match(context, *self.args))
def test_match_returns_point_1_when_nothing_to_match(self):
self.handler.bind(SimpleWidget)
context = Mock(values={})
self.assertEqual(0.1, self.handler.match(context, *self.args))
def test_match_returns_zero_on_incompatible_context(self):
self.handler.bind(SimpleWidget)
# required
context = Mock(values=dict(required=('u', Discrete),
with_metas=('d1', Discrete)))
self.assertEqual(0, self.handler.match(context, *self.args))
def test_clone_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
required=('u', Continuous)
))
new_values = self.handler.clone_context(context, *self.args).values
self.assertEqual(new_values['text'], ('u', -2))
self.assertEqual([('d1', Discrete), ('c1', Continuous)],
new_values['with_metas'])
self.assertNotIn('required', new_values)
def test_open_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d2', Discrete)]
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
widget = SimpleWidget()
self.handler.initialize(widget)
old_metas_list = widget.with_metas
self.handler.open_context(widget, self.args[0])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertIs(old_metas_list, widget.with_metas)
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('d2', Discrete)])
def test_open_context_with_imperfect_match(self):
self.handler.bind(SimpleWidget)
context = self.create_context(None, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)]
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
示例3: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import open_context [as 别名]
#.........这里部分代码省略.........
with_metas=('d1', Discrete)))
self.assertEqual(0, self.handler.match(context, *self.args))
# selected if_selected
context = Mock(values=dict(with_metas=('d1', Discrete),
if_selected=[('u', Discrete)],
selected=[0]))
self.assertEqual(0, self.handler.match(context, *self.args))
# unselected if_selected
context = Mock(values=dict(with_metas=('d1', Discrete),
if_selected=[('u', Discrete),
('d1', Discrete)],
selected=[1]))
self.assertAlmostEqual(0.667, self.handler.match(context, *self.args),
places=2)
def test_clone_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
required=('u', Continuous)
))
new_values = self.handler.clone_context(context, *self.args).values
self.assertEqual(new_values['text'], ('u', -2))
self.assertEqual([('d1', Discrete), ('c1', Continuous)],
new_values['with_metas'])
self.assertNotIn('required', new_values)
def test_open_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d2', Discrete)]
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
widget = SimpleWidget()
self.handler.initialize(widget)
self.handler.open_context(widget, self.args[0])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertSequenceEqual(context.ordered_domain,
(('c1', Continuous), ('d1', Discrete),
('d2', Discrete), ('d3', Discrete),
('c2', Continuous), ('d4', Discrete)))
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('d2', Discrete)])
def test_open_context_with_imperfect_match(self):
self.handler.bind(SimpleWidget)
context = self.create_context(None, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
if_selected=[('c1', Discrete), ('c1', Continuous),
('d1', Discrete), ('d1', Continuous)],
示例4: DomainContextHandlerTestCase
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import open_context [as 别名]
#.........这里部分代码省略.........
with_metas=('d1', Discrete)))
self.assertEqual(0, self.handler.match(context, *self.args))
# selected if_selected
context = Mock(values=dict(with_metas=('d1', Discrete),
if_selected=[('u', Discrete)],
selected=[0]))
self.assertEqual(0, self.handler.match(context, *self.args))
# unselected if_selected
context = Mock(values=dict(with_metas=('d1', Discrete),
if_selected=[('u', Discrete),
('d1', Discrete)],
selected=[1]))
self.assertAlmostEqual(0.667, self.handler.match(context, *self.args),
places=2)
def test_clone_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
required=('u', Continuous)
))
new_values = self.handler.clone_context(context, *self.args).values
self.assertEqual(new_values['text'], ('u', -2))
self.assertEqual([('d1', Discrete), ('c1', Continuous)],
new_values['with_metas'])
self.assertNotIn('required', new_values)
def test_open_context(self):
self.handler.bind(SimpleWidget)
context = self.create_context(self.domain, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d2', Discrete)]
))
self.handler.global_contexts = \
[Mock(values={}), context, Mock(values={})]
widget = SimpleWidget()
self.handler.initialize(widget)
self.handler.open_context(widget, self.args[0])
context = widget.current_context
self.assertEqual(context.attributes, self.args[1])
self.assertEqual(context.metas, self.args[2])
self.assertSequenceEqual(context.ordered_domain,
(('c1', Continuous), ('d1', Discrete),
('d2', Discrete), ('d3', Discrete),
('c2', Continuous), ('d4', Discrete)))
self.assertEqual(widget.text, 'u')
self.assertEqual(widget.with_metas, [('d1', Discrete),
('d2', Discrete)])
def test_open_context_with_imperfect_match(self):
self.handler.bind(SimpleWidget)
context = self.create_context(None, dict(
text=('u', -2),
with_metas=[('d1', Discrete), ('d1', Continuous),
('c1', Continuous), ('c1', Discrete)],
if_selected=[('c1', Discrete), ('c1', Continuous),
('d1', Discrete), ('d1', Continuous)],