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


Python Assembly.dict_sock['Testing']方法代码示例

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


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

示例1: test_list_and_dict_slot_attributes

# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import dict_sock['Testing'] [as 别名]
    def test_list_and_dict_slot_attributes(self):

        top = Assembly()
        top.add('sock', Slot(MyClass, iotype='in', desc='Stuff0'))
        top.add('list_sock', List(Slot(MyClass), iotype='in', desc='Stuff'))
        top.add('dict_sock', Dict(key_trait=Str,
                                  value_trait=Slot(MyClass),
                                  iotype='in', desc='Stuff2'))
        attrs = top.get_attributes(io_only=False)
        slot_attrs = attrs['Slots']
        self.assertTrue({'name': 'list_sock',
                         'containertype': 'list',
                         'filled': [],
                         'klass': 'MyClass',
                         'desc': 'Stuff'} in slot_attrs)
        self.assertTrue({'name': 'dict_sock',
                         'containertype': 'dict',
                         'filled': {},
                         'klass': 'MyClass',
                         'desc': 'Stuff2'} in slot_attrs)
        self.assertTrue({'name': 'sock',
                         'containertype': 'singleton',
                         'filled': None,
                         'klass': 'MyClass',
                         'desc': 'Stuff0'} in slot_attrs)

        # Now fill some slots.

        top.list_sock.append(MyClass())
        top.list_sock.append(MyClass())
        top.dict_sock['Testing'] = MyClass()

        top.sock = MyClass()
        # Note, only tested with one item in the dict because it is not ordered,
        # and hash order will vary on different platforms.

        attrs = top.get_attributes(io_only=False)
        slot_attrs = attrs['Slots']
        self.assertTrue({'name': 'list_sock',
                         'containertype': 'list',
                         'filled': ['MyClass', 'MyClass'],
                         'klass': 'MyClass',
                         'desc': 'Stuff'} in slot_attrs)
        # Need some special checking for the dict slot
        # since we get back a MyClass instance
        dict_slots = filter(lambda x: x["name"] == "dict_sock", slot_attrs)
        self.assertEqual(len(dict_slots), 1)
        dict_slot = dict_slots[0]
        self.assertEqual(dict_slot["containertype"], "dict")
        self.assertEqual(dict_slot["klass"], "MyClass")
        self.assertEqual(dict_slot["desc"], "Stuff2")
        self.assertEqual(dict_slot["filled"], {'Testing': 'MyClass'})
        self.assertTrue({'name': 'sock',
                         'containertype': 'singleton',
                         'filled': 'MyClass',
                         'klass': 'MyClass',
                         'desc': 'Stuff0'} in slot_attrs)
开发者ID:hitej,项目名称:meta-core,代码行数:59,代码来源:test_slot.py

示例2: test_list_and_dict_slot_attributes

# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import dict_sock['Testing'] [as 别名]
    def test_list_and_dict_slot_attributes(self):
        
        top = Assembly()
        top.add('sock', Slot(MyClass, iotype='in', desc='Stuff0'))
        top.add('list_sock', List(Slot(MyClass), iotype='in', desc='Stuff'))
        top.add('dict_sock', Dict(key_trait=Str, 
                                  value_trait=Slot(MyClass), 
                                  iotype='in', desc='Stuff2'))
        attrs = top.get_attributes(io_only=False)
        slot_attrs = attrs['Slots']
        self.assertTrue({'name': 'list_sock',
                         'containertype': 'list',
                         'filled': [],
                         'klass': 'MyClass',
                         'desc': 'Stuff'} in slot_attrs)
        self.assertTrue({'name': 'dict_sock',
                         'containertype': 'dict',
                         'filled': [],
                         'klass': 'MyClass',
                         'desc': 'Stuff2'} in slot_attrs)
        self.assertTrue({'name': 'sock',
                         'containertype': 'singleton',
                         'filled': None,
                         'klass': 'MyClass',
                         'desc': 'Stuff0'} in slot_attrs)

        # Now fill some slots.
        
        top.list_sock.append(MyClass())
        top.list_sock.append(MyClass())
        top.dict_sock['Testing'] = MyClass()
        
        top.sock = MyClass()
        # Note, only tested with one item in the dict because it is not ordered,
        # and hash order will vary on different platforms.
        
        attrs = top.get_attributes(io_only=False)
        slot_attrs = attrs['Slots']
        self.assertTrue({'name': 'list_sock',
                         'containertype': 'list',
                         'filled': ['MyClass', 'MyClass'],
                         'klass': 'MyClass',
                         'desc': 'Stuff'} in slot_attrs)
        self.assertTrue({'name': 'dict_sock',
                         'containertype': 'dict',
                         'filled': ['Testing'],
                         'klass': 'MyClass',
                         'desc': 'Stuff2'} in slot_attrs)
        self.assertTrue({'name': 'sock',
                         'containertype': 'singleton',
                         'filled': 'MyClass',
                         'klass': 'MyClass',
                         'desc': 'Stuff0'} in slot_attrs)
开发者ID:akhi28,项目名称:OpenMDAO-Framework,代码行数:55,代码来源:test_slot.py


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