コード例 #1
0
    def _process_multiple_folder(self, model_value, item_info, schema_path, model_path):
        """
        Process a multiple-element model section.
        There should be a dictionary of names, each containing a sub-folder.
        :param model_value: the model contents for a folder
        :param item_info: describes the contents of the sub-folder for each element
        :param schema_path: the path of schema elements (no multi-element names), used for supported check
        :param model_path: the path of model elements (including multi-element names), used for logging
        """
        child_list = list()
        for name in model_value:
            name_map = model_value[name]
            next_target_dict = PyOrderedDict()
            next_model_path = model_path + "/" + name
            self._process_folder(name_map, item_info, next_target_dict, schema_path, next_model_path)

            # see if the model name should become an attribute in the target dict
            mapped_name = get_mapped_key(schema_path)
            properties = wko_schema_helper.get_properties(item_info)
            if (mapped_name in properties.keys()) and (mapped_name not in next_target_dict.keys()):
                _add_to_top(next_target_dict, mapped_name, name)

            child_list.append(next_target_dict)

        return child_list
コード例 #2
0
    def testKeys(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['nba_player'] = 'Steph Curry'
        my_ordered_dict['nba_mvp_count'] = 1
        my_ordered_dict['is_retired'] = False
        my_ordered_dict['nba_finals_years'] = ['2015', '2016', '2017']

        expected = ['nba_player', 'nba_mvp_count', 'is_retired', 'nba_finals_years']
        keys = my_ordered_dict.keys()
        self.assertEqual(len(expected), len(keys),
                         'expected the ordered dict keys to be the same length as the expected keys')
        for i, key in enumerate(keys):
            self.assertEqual(key, expected[i], 'expected key at position %s to be %s' % (str(i), expected[i]))
コード例 #3
0
    def testCopyConstructorKeyOrdering(self):
        my_ordered_dict = OrderedDict()
        my_ordered_dict['one'] = 1
        my_ordered_dict['two'] = 2
        my_ordered_dict['five'] = 5
        my_ordered_dict['three'] = 3
        my_ordered_dict['four'] = 4

        copy_ordered_dict = OrderedDict(my_ordered_dict)

        # A myOrderedDict.keys() needs to return the keys, in the
        # exact order that they were inserted
        expected = ['one', 'two', 'five', 'three', 'four']
        copy_ordered_dict_keys = copy_ordered_dict.keys()
        for i in range(len(expected)):
            self.assertEqual(copy_ordered_dict_keys[i], expected[i])
コード例 #4
0
    def testOrderedDictSort(self):
        dict1 = OrderedDict()
        dict1['SecurityConfig.myrealm.IoT-IDCS-Authenticator.ClientSecretEncrypted'] = ''
        dict1['AdminUserName'] = ''
        dict1['ServerTemp.ms-template.SSL.ListenPort'] = '8100'
        dict1['AdminPassword'] = ''
        dict1['JDBC.IoTServerDS.user.Value'] = 'admin'
        dict1['SecurityConfig.CredentialEncrypted'] = ''
        dict1['JDBC.IoTServerDS.PasswordEncrypted'] = ''
        dict1['SecurityConfig.NodeManagerUsername'] = '******'

        sorted_dict = OrderedDict()
        sorted_keys = dict1.keys()
        sorted_keys.sort()
        for key in sorted_keys:
            sorted_dict[key] = dict1[key]

        self.assertEqual(sorted_dict.values()[-1], '8100',
                         'expected dictionary to be sorted by name')