當前位置: 首頁>>代碼示例>>Python>>正文


Python StoragePolicyCollection.get_by_index方法代碼示例

本文整理匯總了Python中swift.common.storage_policy.StoragePolicyCollection.get_by_index方法的典型用法代碼示例。如果您正苦於以下問題:Python StoragePolicyCollection.get_by_index方法的具體用法?Python StoragePolicyCollection.get_by_index怎麽用?Python StoragePolicyCollection.get_by_index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在swift.common.storage_policy.StoragePolicyCollection的用法示例。


在下文中一共展示了StoragePolicyCollection.get_by_index方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_policies_type_attribute

# 需要導入模塊: from swift.common.storage_policy import StoragePolicyCollection [as 別名]
# 或者: from swift.common.storage_policy.StoragePolicyCollection import get_by_index [as 別名]
 def test_policies_type_attribute(self):
     test_policies = [
         StoragePolicy(0, "zero", is_default=True),
         StoragePolicy(1, "one"),
         StoragePolicy(2, "two"),
         StoragePolicy(3, "three", is_deprecated=True),
         ECStoragePolicy(10, "ten", ec_type="jerasure_rs_vand", ec_ndata=10, ec_nparity=3),
     ]
     policies = StoragePolicyCollection(test_policies)
     self.assertEquals(policies.get_by_index(0).policy_type, REPL_POLICY)
     self.assertEquals(policies.get_by_index(1).policy_type, REPL_POLICY)
     self.assertEquals(policies.get_by_index(2).policy_type, REPL_POLICY)
     self.assertEquals(policies.get_by_index(3).policy_type, REPL_POLICY)
     self.assertEquals(policies.get_by_index(10).policy_type, EC_POLICY)
開發者ID:dencaval,項目名稱:swift,代碼行數:16,代碼來源:test_storage_policy.py

示例2: test_policies_type_attribute

# 需要導入模塊: from swift.common.storage_policy import StoragePolicyCollection [as 別名]
# 或者: from swift.common.storage_policy.StoragePolicyCollection import get_by_index [as 別名]
 def test_policies_type_attribute(self):
     test_policies = [
         StoragePolicy(0, 'zero', is_default=True),
         StoragePolicy(1, 'one'),
         StoragePolicy(2, 'two'),
         StoragePolicy(3, 'three', is_deprecated=True),
         ECStoragePolicy(10, 'ten', ec_type=DEFAULT_TEST_EC_TYPE,
                         ec_ndata=10, ec_nparity=3),
     ]
     policies = StoragePolicyCollection(test_policies)
     self.assertEqual(policies.get_by_index(0).policy_type,
                      REPL_POLICY)
     self.assertEqual(policies.get_by_index(1).policy_type,
                      REPL_POLICY)
     self.assertEqual(policies.get_by_index(2).policy_type,
                      REPL_POLICY)
     self.assertEqual(policies.get_by_index(3).policy_type,
                      REPL_POLICY)
     self.assertEqual(policies.get_by_index(10).policy_type,
                      EC_POLICY)
開發者ID:aureliengoulon,項目名稱:swift,代碼行數:22,代碼來源:test_storage_policy.py

示例3: test_add_remove_names

# 需要導入模塊: from swift.common.storage_policy import StoragePolicyCollection [as 別名]
# 或者: from swift.common.storage_policy.StoragePolicyCollection import get_by_index [as 別名]
    def test_add_remove_names(self):
        test_policies = [StoragePolicy(0, 'zero', True),
                         StoragePolicy(1, 'one', False),
                         StoragePolicy(2, 'two', False)]
        policies = StoragePolicyCollection(test_policies)

        # add names
        policies.add_policy_alias(1, 'tahi')
        self.assertEqual(policies.get_by_name('tahi'), test_policies[1])

        policies.add_policy_alias(2, 'rua', 'dos')
        self.assertEqual(policies.get_by_name('rua'), test_policies[2])
        self.assertEqual(policies.get_by_name('dos'), test_policies[2])

        self.assertRaisesWithMessage(PolicyError, 'Invalid name',
                                     policies.add_policy_alias, 2, 'double\n')

        self.assertRaisesWithMessage(PolicyError, 'Invalid name',
                                     policies.add_policy_alias, 2, '')

        # try to add existing name
        self.assertRaisesWithMessage(PolicyError, 'Duplicate name',
                                     policies.add_policy_alias, 2, 'two')

        self.assertRaisesWithMessage(PolicyError, 'Duplicate name',
                                     policies.add_policy_alias, 1, 'two')

        # remove name
        policies.remove_policy_alias('tahi')
        self.assertEqual(policies.get_by_name('tahi'), None)

        # remove only name
        self.assertRaisesWithMessage(PolicyError,
                                     'Policies must have at least one name.',
                                     policies.remove_policy_alias, 'zero')

        # remove non-existent name
        self.assertRaisesWithMessage(PolicyError,
                                     'No policy with name',
                                     policies.remove_policy_alias, 'three')

        # remove default name
        policies.remove_policy_alias('two')
        self.assertEqual(policies.get_by_name('two'), None)
        self.assertEqual(policies.get_by_index(2).name, 'rua')

        # change default name to a new name
        policies.change_policy_primary_name(2, 'two')
        self.assertEqual(policies.get_by_name('two'), test_policies[2])
        self.assertEqual(policies.get_by_index(2).name, 'two')

        # change default name to an existing alias
        policies.change_policy_primary_name(2, 'dos')
        self.assertEqual(policies.get_by_index(2).name, 'dos')

        # change default name to a bad new name
        self.assertRaisesWithMessage(PolicyError, 'Invalid name',
                                     policies.change_policy_primary_name,
                                     2, 'bad\nname')

        # change default name to a name belonging to another policy
        self.assertRaisesWithMessage(PolicyError,
                                     'Other policy',
                                     policies.change_policy_primary_name,
                                     1, 'dos')
開發者ID:aureliengoulon,項目名稱:swift,代碼行數:67,代碼來源:test_storage_policy.py


注:本文中的swift.common.storage_policy.StoragePolicyCollection.get_by_index方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。