本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.settings_from_widget方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.settings_from_widget方法的具体用法?Python DomainContextHandler.settings_from_widget怎么用?Python DomainContextHandler.settings_from_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.settings.DomainContextHandler
的用法示例。
在下文中一共展示了DomainContextHandler.settings_from_widget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DomainContextSettingsHandlerTests
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import settings_from_widget [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: DomainContextSettingsHandlerTests
# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import settings_from_widget [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 from disk
self.domain = self._create_domain()
def test_encode_domain_with_match_none(self):
self.handler.match_values = self.handler.MATCH_VALUES_NONE
encoded_attributes, encoded_metas = \
self.handler.encode_domain(self.domain)
self.assertEqual(encoded_attributes, {
'cf1': VarTypes.Continuous,
'df1': VarTypes.Discrete,
'df2': VarTypes.Discrete,
'dc1': VarTypes.Discrete,
})
self.assertEqual(encoded_metas, {
'cm1': VarTypes.Continuous,
'dm1': VarTypes.Discrete,
})
def test_encode_domain_with_match_class(self):
self.handler.match_values = self.handler.MATCH_VALUES_CLASS
encoded_attributes, encoded_metas = \
self.handler.encode_domain(self.domain)
self.assertEqual(encoded_attributes, {
'cf1': VarTypes.Continuous,
'df1': VarTypes.Discrete,
'df2': VarTypes.Discrete,
'dc1': ["g", "h", "i"],
})
self.assertEqual(encoded_metas, {
'cm1': VarTypes.Continuous,
'dm1': VarTypes.Discrete,
})
def test_encode_domain_with_match_all(self):
self.handler.match_values = self.handler.MATCH_VALUES_ALL
encoded_attributes, encoded_metas = \
self.handler.encode_domain(self.domain)
self.assertEqual(encoded_attributes, {
'cf1': VarTypes.Continuous,
'df1': ["a", "b", "c"],
'df2': ["d", "e", "f"],
'dc1': ["g", "h", "i"],
})
self.assertEqual(encoded_metas, {
'cm1': VarTypes.Continuous,
'dm1': ["j", "k", "l"],
})
def test_encode_domain_with_false_attributes_in_res(self):
self.handler = DomainContextHandler(attributes_in_res=False,
metas_in_res=True)
encoded_attributes, encoded_metas = \
self.handler.encode_domain(self.domain)
self.assertEqual(encoded_attributes, {})
self.assertEqual(encoded_metas, {
'cm1': VarTypes.Continuous,
'dm1': VarTypes.Discrete,
})
def test_encode_domain_with_false_metas_in_res(self):
self.handler = DomainContextHandler(attributes_in_res=True,
metas_in_res=False)
encoded_attributes, encoded_metas = \
self.handler.encode_domain(self.domain)
self.assertEqual(encoded_attributes, {
'cf1': VarTypes.Continuous,
'df1': VarTypes.Discrete,
'df2': VarTypes.Discrete,
'dc1': VarTypes.Discrete,
})
self.assertEqual(encoded_metas, {})
def test_settings_from_widget(self):
widget = MockWidget()
widget.current_context.attributes, widget.current_context.metas = \
self.handler.encode_domain(self.domain)
self.add_setting(widget, "string_setting", ContextSetting("abc"))
self.add_setting(widget, "list_setting", ContextSetting([1, 2, 3]))
self.add_setting(widget, "dict_setting", ContextSetting({1: 2}))
self.add_setting(widget, "continuous_setting", ContextSetting("cf1"))
self.add_setting(widget, "discrete_setting", ContextSetting("df1"))
self.add_setting(widget, "class_setting", ContextSetting("dc1"))
self.add_setting(widget, "excluded_meta_setting", ContextSetting("dm1"))
self.add_setting(widget, "meta_setting",
ContextSetting("dm1", exclude_metas=False))
self.handler.settings_from_widget(widget)
#.........这里部分代码省略.........