本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.clone_context方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.clone_context方法的具体用法?Python DomainContextHandler.clone_context怎么用?Python DomainContextHandler.clone_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.settings.DomainContextHandler
的用法示例。
在下文中一共展示了DomainContextHandler.clone_context方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DomainContextSettingsHandlerTests
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import clone_context [as 别名]
#.........这里部分代码省略.........
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)
))
self.assertEqual(self.match(mock_context), 1.)
def test_match_if_all_required_list_values_match_returns_1(self):
mock_context = Mock(values=dict(
required_setting=(DISCRETE_ATTR_ABC, Discrete)
))
self.assertEqual(self.match(mock_context), 1.)
def test_clone_context(self):
mock_context = Mock(values=dict(
required_setting=(DISCRETE_ATTR_ABC, Discrete)
))
attrs, metas = self.handler.encode_domain(domain)
cloned_context = self.handler.clone_context(mock_context, domain, attrs, metas)
self.assertEqual(cloned_context.values, mock_context.values)
def add_setting(self, widget, name, setting):
setting.name = name
setattr(widget, name, setting.default)
self.handler.provider.settings[name] = setting
def match(self, context):
attrs, metas = self.handler.encode_domain(domain)
return self.handler.match(context, None, attrs, metas)
def test_initialize_sets_current_context(self):
self.widget = MockWidget()
del self.widget.current_context
self.handler.initialize(self.widget)
self.assertIs(self.widget.current_context, None)
示例2: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import clone_context [as 别名]
#.........这里部分代码省略.........
# Metas in values
context = Mock(values=dict(
with_metas=('d4', Discrete),
required=('d1', Discrete)))
self.assertEqual(1., self.handler.match(context, *self.args))
# Attributes in lists
context = Mock(values=dict(
with_metas=[("d1", Discrete)]
))
self.assertEqual(1., self.handler.match(context, *self.args))
# Metas in lists
context = Mock(values=dict(
with_metas=[("d4", Discrete)]
))
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])
示例3: TestDomainContextHandler
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import clone_context [as 别名]
#.........这里部分代码省略.........
context = Mock(values=dict(
with_metas=[("d4", Discrete)]
))
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))
# 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,
示例4: DomainContextHandlerTestCase
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import clone_context [as 别名]
#.........这里部分代码省略.........
context = Mock(values=dict(
with_metas=[("d4", Discrete)]
))
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))
# 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,