当前位置: 首页>>代码示例>>Python>>正文


Python DomainContextHandler.settings_to_widget方法代码示例

本文整理汇总了Python中Orange.widgets.settings.DomainContextHandler.settings_to_widget方法的典型用法代码示例。如果您正苦于以下问题:Python DomainContextHandler.settings_to_widget方法的具体用法?Python DomainContextHandler.settings_to_widget怎么用?Python DomainContextHandler.settings_to_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Orange.widgets.settings.DomainContextHandler的用法示例。


在下文中一共展示了DomainContextHandler.settings_to_widget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DomainContextSettingsHandlerTests

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import settings_to_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)
        ))
#.........这里部分代码省略.........
开发者ID:jujuefengliu,项目名称:orange3,代码行数:103,代码来源:test_settings.py

示例2: DomainContextSettingsHandlerTests

# 需要导入模块: from Orange.widgets.settings import DomainContextHandler [as 别名]
# 或者: from Orange.widgets.settings.DomainContextHandler import settings_to_widget [as 别名]

#.........这里部分代码省略.........
            '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)

        self.assertEqual(widget.current_context.values, dict(
            string_setting=("abc", -2),
            list_setting=[1, 2, 3],
            dict_setting=({1: 2}, -2),
            continuous_setting=("cf1", VarTypes.Continuous),
            discrete_setting=("df1", VarTypes.Discrete),
            class_setting=("dc1", VarTypes.Discrete),
            excluded_meta_setting=("dm1", -2),
            meta_setting=("dm1", VarTypes.Discrete),
        ))

    def test_settings_to_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(""))
        self.add_setting(widget, "continuous_setting", ContextSetting(""))
        self.add_setting(widget, "discrete_setting", ContextSetting(""))
        self.add_setting(widget, "list_setting", ContextSetting([]))
        self.add_setting(widget, "attr_list_setting",
                         ContextSetting([], selected="selection1"))
        self.add_setting(widget, "attr_tuple_list_setting",
                         ContextSetting([], selected="selection2",
                                        exclude_metas=False))
        widget.current_context.values = dict(
            string_setting=("abc", -2),
            continuous_setting=("cf1", VarTypes.Continuous),
            discrete_setting=("df1", VarTypes.Discrete),
            list_setting=[1, 2, 3],
            attr_list_setting=["df1", "dc1"],
            selection1=[0],
            attr_tuple_list_setting=[("dm1", VarTypes.Discrete),
                                     ("cm1", VarTypes.Continuous)],
            selection2=[1],
        )

        self.handler.settings_to_widget(widget)

        self.assertEqual(widget.string_setting, "abc")
        self.assertEqual(widget.continuous_setting, "cf1")
        self.assertEqual(widget.discrete_setting, "df1")
        self.assertEqual(widget.list_setting, [1, 2, 3])
        self.assertEqual(widget.attr_list_setting, ["df1", "dc1"])
        self.assertEqual(widget.attr_tuple_list_setting,
开发者ID:amela,项目名称:orange3,代码行数:70,代码来源:test_settings.py


注:本文中的Orange.widgets.settings.DomainContextHandler.settings_to_widget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。