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


Python tools.assert_raises方法代码示例

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


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

示例1: test_restore_rse

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_restore_rse(self):
        """ RSE (CORE): Test restore of RSE """
        # Restore deleted RSE
        rse_name = rse_name_generator()
        rse_id = add_rse(rse_name)
        db_session = session.get_session()
        db_session.commit()

        del_rse(rse_id)
        db_session.commit()
        # Verify RSE was deleted
        assert_equal(rse_exists(rse=rse_id), False)

        restore_rse(rse_id=rse_id)
        db_session.commit()
        # Verify RSE was restored
        assert rse_exists(rse=rse_name)

        # Restoration of not deleted RSE:
        rse_name = rse_name_generator()
        rse_id = add_rse(rse_name)
        with assert_raises(RSENotFound):
            restore_rse(rse_id=rse_id) 
开发者ID:rucio,项目名称:rucio,代码行数:25,代码来源:test_rse.py

示例2: test_invalid_state_transition

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_invalid_state_transition():
    @acts_as_state_machine
    class Person(mongoengine.Document):
        name = mongoengine.StringField(default='Billy')

        sleeping = State(initial=True)
        running = State()
        cleaning = State()

        run = Event(from_states=sleeping, to_state=running)
        cleanup = Event(from_states=running, to_state=cleaning)
        sleep = Event(from_states=(running, cleaning), to_state=sleeping)

    establish_mongo_connection()
    person = Person()
    person.save()
    assert person.is_sleeping

    #should raise an invalid state exception
    with assert_raises(InvalidStateTransition):
        person.sleep() 
开发者ID:jtushman,项目名称:state_machine,代码行数:23,代码来源:tests.py

示例3: test_create_and_update_and_list_subscription

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_create_and_update_and_list_subscription(self):
        """ SUBSCRIPTION (API): Test the creation of a new subscription, update it, list it """
        subscription_name = uuid()
        with assert_raises(InvalidObject):
            result = add_subscription(name=subscription_name, account='root', filter={'project': self.projects, 'datatype': ['AOD', ], 'excluded_pattern': self.pattern1, 'account': ['tier0', ]},
                                      replication_rules=[{'lifetime': 86400, 'rse_expression': 'MOCK|MOCK2', 'copies': 2, 'activity': 'noactivity'}], lifetime=100000, retroactive=0, dry_run=0, comments='This is a comment', issuer='root')

        result = add_subscription(name=subscription_name, account='root', filter={'project': self.projects, 'datatype': ['AOD', ], 'excluded_pattern': self.pattern1, 'account': ['tier0', ]},
                                  replication_rules=[{'lifetime': 86400, 'rse_expression': 'MOCK|MOCK2', 'copies': 2, 'activity': 'Data Brokering'}], lifetime=100000, retroactive=0, dry_run=0, comments='This is a comment', issuer='root')
        with assert_raises(TypeError):
            result = update_subscription(name=subscription_name, account='root', metadata={'filter': 'toto'}, issuer='root')
        with assert_raises(InvalidObject):
            result = update_subscription(name=subscription_name, account='root', metadata={'filter': {'project': 'toto'}}, issuer='root')
        result = update_subscription(name=subscription_name, account='root', metadata={'filter': {'project': ['toto', ]}}, issuer='root')
        assert_equal(result, None)
        result = list_subscriptions(name=subscription_name, account='root')
        sub = []
        for res in result:
            sub.append(res)
        assert_equal(len(sub), 1)
        assert_equal(loads(sub[0]['filter'])['project'][0], 'toto') 
开发者ID:rucio,项目名称:rucio,代码行数:23,代码来源:test_subscription.py

示例4: test_add_key

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_add_key(self):
        """ META (CLIENTS): Add a new key """
        types = [{'type': 'FILE', 'expected': KeyType.FILE},
                 {'type': 'ALL', 'expected': KeyType.ALL},
                 {'type': 'COLLECTION', 'expected': KeyType.COLLECTION},
                 {'type': 'DATASET', 'expected': KeyType.DATASET},
                 {'type': 'D', 'expected': KeyType.DATASET},
                 {'type': 'FILE', 'expected': KeyType.FILE},
                 {'type': 'F', 'expected': KeyType.FILE},
                 {'type': 'DERIVED', 'expected': KeyType.DERIVED},
                 {'type': 'C', 'expected': KeyType.CONTAINER}]

        for key_type in types:
            key_name = 'datatype%s' % str(uuid())
            self.meta_client.add_key(key_name, key_type['type'])
            stored_key_type = session.get_session().query(models.DIDKey).filter_by(key=key_name).one()['key_type']
            assert_true(stored_key_type, key_type['expected'])

        with assert_raises(UnsupportedKeyType):
            self.meta_client.add_key('datatype', 'A') 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:test_meta.py

示例5: test_delete_rse

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_delete_rse(self):
        """ RSE (CORE): Test deletion of RSE """
        # Deletion of not empty RSE
        rse_name = rse_name_generator()
        rse_id = add_rse(rse_name)
        db_session = session.get_session()
        rse_usage = db_session.query(models.RSEUsage).filter_by(rse_id=rse_id, source='rucio').one()
        rse_usage.used = 1
        db_session.commit()
        with assert_raises(RSEOperationNotSupported):
            del_rse(rse_id)

        # Deletion of not found RSE:
        # rse_name = rse_name_generator() #- No longer valid syntax
        # with assert_raises(RSENotFound):
        #     del_rse(rse=rse_name) 
开发者ID:rucio,项目名称:rucio,代码行数:18,代码来源:test_rse.py

示例6: test_judge_deny_rule

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_judge_deny_rule(self):
        """ JUDGE INJECTOR: Test the judge when asking approval for a rule and denying it"""
        scope = InternalScope('mock')
        files = create_files(3, scope, self.rse1_id)
        dataset = 'dataset_' + str(uuid())
        add_did(scope, dataset, DIDType.from_sym('DATASET'), self.jdoe)
        attach_dids(scope, dataset, files, self.jdoe)

        # Add a first rule to the DS
        rule_id = add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=1, rse_expression=self.rse4, grouping='DATASET', weight=None, lifetime=None, locked=False, subscription_id=None, ask_approval=True)[0]

        assert(get_rule(rule_id)['state'] == RuleState.WAITING_APPROVAL)

        deny_rule(rule_id=rule_id, approver=self.jdoe)

        assert_raises(RuleNotFound, get_rule, rule_id) 
开发者ID:rucio,项目名称:rucio,代码行数:18,代码来源:test_judge_injector.py

示例7: test_add_rule_with_r2d2_container_treating_and_duplicate_rule

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_add_rule_with_r2d2_container_treating_and_duplicate_rule(self):
        """ JUDGE INJECTOR (CORE): Add a replication rule with an r2d2 container treatment and duplicate rule"""
        scope = InternalScope('mock')
        container = 'asdf.r2d2_request.2016-04-01-15-00-00.ads.' + str(uuid())
        add_did(scope, container, DIDType.from_sym('CONTAINER'), self.jdoe)
        datasets = []
        for i in range(3):
            files = create_files(3, scope, self.rse1_id)
            dataset = 'dataset_' + str(uuid())
            datasets.append(dataset)
            add_did(scope, dataset, DIDType.from_sym('DATASET'), self.jdoe)
            attach_dids(scope, dataset, files, self.jdoe)
            attach_dids(scope, container, [{'scope': scope, 'name': dataset}], self.jdoe)
        add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=1, rse_expression=self.rse1, grouping='DATASET', weight=None, lifetime=900, locked=False, subscription_id=None, ask_approval=False)
        rule_id = add_rule(dids=[{'scope': scope, 'name': container}], account=self.jdoe, copies=1, rse_expression=self.rse1, grouping='DATASET', weight=None, lifetime=900, locked=False, subscription_id=None, ask_approval=True)[0]
        approve_rule(rule_id, approver=self.jdoe)
        assert(get_rule(rule_id)['state'] == RuleState.INJECT)
        rule_injector(once=True)
        # Check if there is a rule for each file
        with assert_raises(RuleNotFound):
            get_rule(rule_id)
        for dataset in datasets:
            assert(len([r for r in list_rules({'scope': scope, 'name': dataset})]) > 0) 
开发者ID:rucio,项目名称:rucio,代码行数:25,代码来源:test_judge_injector.py

示例8: test_add_account_success

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_add_account_success(self):
        """ ACCOUNT (CLIENTS): create a new account and get information about account."""
        account = account_name_generator()
        type, email = 'USER', 'rucio@email.com'
        ret = self.client.add_account(account, type, email)
        assert_true(ret)

        with assert_raises(Duplicate):
            self.client.add_account(account, type, email)

        with assert_raises(InvalidObject):
            self.client.add_account('BAD_ACCOUNT_NAME', type, email)

        with assert_raises(InvalidObject):
            self.client.add_account('toooooooloooooonaccounnnnnnnntnammmmme', type, email)

        acc_info = self.client.get_account(account)
        assert_equal(acc_info['account'], account) 
开发者ID:rucio,项目名称:rucio,代码行数:20,代码来源:test_account.py

示例9: test_update_dids

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_update_dids(self):
        """ DATA IDENTIFIERS (CORE): Update file size and checksum"""
        tmp_scope = InternalScope('mock')
        root = InternalAccount('root')
        dsn = 'dsn_%s' % generate_uuid()
        lfn = 'lfn.%s' % str(generate_uuid())
        add_did(scope=tmp_scope, name=dsn, type=DIDType.DATASET, account=root)

        files = [{'scope': tmp_scope, 'name': lfn,
                  'bytes': 724963570, 'adler32': '0cc737eb',
                  'meta': {'guid': str(generate_uuid()), 'events': 100}}]
        attach_dids(scope=tmp_scope, name=dsn, rse_id=get_rse_id(rse='MOCK'), dids=files, account=root)

        set_metadata(scope=tmp_scope, name=lfn, key='adler32', value='0cc737ee')
        assert_equal(get_metadata(scope=tmp_scope, name=lfn)['adler32'], '0cc737ee')

        with assert_raises(DataIdentifierNotFound):
            set_metadata(scope=tmp_scope, name='Nimportnawak', key='adler32', value='0cc737ee')

        set_metadata(scope=tmp_scope, name=lfn, key='bytes', value=724963577)
        assert_equal(get_metadata(scope=tmp_scope, name=lfn)['bytes'], 724963577) 
开发者ID:rucio,项目名称:rucio,代码行数:23,代码来源:test_did.py

示例10: test_scope_with_lfn

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_scope_with_lfn(self):
        good_1 = {
            'name': '/store/mc/2008/2/21/FastSim-CSA07Electron-1203615548/0009/B6E531DD-99E1-DC11-9FEC-001617E30D4A.root',
            'scope': 'cms', 'type': 'FILE'}
        good_2 = {'name': '/store/user/rucio/ewv/Higgs-123/PrivateSample/v1/1000/a_X-2.root', 'scope': 'user.ewv',
                  'type': 'FILE'}
        bad_1 = {
            'name': '/store/mc/2008/2/21/FastSim-CSA07Electron-1203615548/0009/B6E531DD-99E1-DC11-9FEC-001617E30D4A.root',
            'scope': 'user.ewv', 'type': 'FILE'}
        bad_2 = {'name': '/store/user/rucio/ewv/Higgs-123/PrivateSample/v1/1000/a_X-2.root', 'scope': 'cms',
                 'type': 'FILE'}
        bad_3 = {'name': '/store/user/rucio/ewv/Higgs-123/PrivateSample/v1/1000/a_X-2.root', 'scope': 'user.jdoe',
                 'type': 'FILE'}

        validate_schema('did', good_1)
        validate_schema('did', good_2)
        with assert_raises(InvalidObject):
            validate_schema('did', bad_1)  # User scope for CMS file
        with assert_raises(InvalidObject):
            validate_schema('did', bad_2)  # CMS scope for user file
        with assert_raises(InvalidObject):
            validate_schema('did', bad_3)  # User with wrong scope 
开发者ID:rucio,项目名称:rucio,代码行数:24,代码来源:test_schema_cms.py

示例11: test_delete_replicas

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_delete_replicas(self):
        """ REPLICA (CORE): Delete replicas """
        tmp_scope = InternalScope('mock')
        root = InternalAccount('root')
        nbfiles = 5
        files1 = [{'scope': tmp_scope, 'name': 'file_%s' % generate_uuid(), 'bytes': 1, 'adler32': '0cc737eb', 'meta': {'events': 10}} for _ in range(nbfiles)]
        rse_id1 = get_rse_id(rse='MOCK')
        rse_id2 = get_rse_id(rse='MOCK3')

        add_replicas(rse_id=rse_id1, files=files1, account=root, ignore_availability=True)

        files2 = [{'scope': tmp_scope, 'name': 'file_%s' % generate_uuid(), 'bytes': 1, 'adler32': '0cc737eb', 'meta': {'events': 10}} for _ in range(nbfiles)]
        add_replicas(rse_id=rse_id1, files=files2, account=root, ignore_availability=True)
        add_replicas(rse_id=rse_id2, files=files2, account=root, ignore_availability=True)

        delete_replicas(rse_id=rse_id1, files=files1 + files2)

        for file in files1:
            with assert_raises(DataIdentifierNotFound):
                print(get_did(scope=file['scope'], name=file['name']))

        for file in files2:
            get_did(scope=file['scope'], name=file['name']) 
开发者ID:rucio,项目名称:rucio,代码行数:25,代码来源:test_replica.py

示例12: test_set_tombstone

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_set_tombstone(self):
        """ REPLICA (CORE): set tombstone on replica """
        # Set tombstone on one replica
        rse = 'MOCK4'
        rse_id = get_rse_id(rse=rse)
        scope = InternalScope('mock')
        user = InternalAccount('root')
        name = generate_uuid()
        add_replica(rse_id, scope, name, 4, user)
        assert_equal(get_replica(rse_id, scope, name)['tombstone'], None)
        set_tombstone(rse_id, scope, name)
        assert_equal(get_replica(rse_id, scope, name)['tombstone'], OBSOLETE)

        # Set tombstone on locked replica
        name = generate_uuid()
        add_replica(rse_id, scope, name, 4, user)
        RuleClient().add_replication_rule([{'name': name, 'scope': scope.external}], 1, rse, locked=True)
        with assert_raises(ReplicaIsLocked):
            set_tombstone(rse_id, scope, name)

        # Set tombstone on not found replica
        name = generate_uuid()
        with assert_raises(ReplicaNotFound):
            set_tombstone(rse_id, scope, name) 
开发者ID:rucio,项目名称:rucio,代码行数:26,代码来源:test_replica.py

示例13: test_add_did_meta

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_add_did_meta(self):
        """ META (CLIENTS) : Adds a fully set json column to a did, updates if some keys present """
        if self.implemented:
            data1 = {"key1": "value_" + str(uuid()), "key2": "value_" + str(uuid()), "key3": "value_" + str(uuid())}
            self.did_client.add_did_meta(scope=self.tmp_scope, name=self.tmp_name, meta=data1)

            metadata = self.did_client.get_did_meta(scope=self.tmp_scope, name=self.tmp_name)
            assert_equal(len(metadata), 3)
            assert_equal(metadata, data1)

            data2 = {"key4": "value_" + str(uuid()), "key5": "value_" + str(uuid())}
            self.did_client.add_did_meta(scope=self.tmp_scope, name=self.tmp_name, meta=data2)

            metadata = self.did_client.get_did_meta(scope=self.tmp_scope, name=self.tmp_name)
            assert_equal(len(metadata), 5)
            assert_equal(metadata, dict(list(data1.items()) + list(data2.items())))

            with assert_raises(DataIdentifierNotFound):
                self.did_client.add_did_meta(scope=self.tmp_scope, name='Nimportnawak', meta=data1)

            data3 = {"key2": "value2", "key6": "value6"}
            self.did_client.add_did_meta(scope=self.tmp_scope, name=self.tmp_name, meta=data3)
            metadata = self.did_client.get_did_meta(scope=self.tmp_scope, name=self.tmp_name)
            assert_equal(len(metadata), 6)
            assert_equal(metadata["key2"], "value2") 
开发者ID:rucio,项目名称:rucio,代码行数:27,代码来源:test_did_meta.py

示例14: test_delete_rule_and_cancel_transfers

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_delete_rule_and_cancel_transfers(self):
        """ REPLICATION RULE (CORE): Test to delete a previously created rule and do not cancel overlapping transfers"""
        scope = InternalScope('mock')
        files = create_files(3, scope, self.rse1_id)
        dataset = 'dataset_' + str(uuid())
        add_did(scope, dataset, DIDType.from_sym('DATASET'), self.jdoe)
        attach_dids(scope, dataset, files, self.jdoe)

        rule_id_1 = add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=1, rse_expression=self.rse1, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
        add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=2, rse_expression=self.T1, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]
        add_rule(dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=3, rse_expression=self.T1, grouping='NONE', weight='fakeweight', lifetime=None, locked=False, subscription_id=None)[0]

        delete_rule(rule_id_1)

        for file in files:
            rse_locks = get_replica_locks(scope=file['scope'], name=file['name'])
            assert(len(rse_locks) == 5)
            # TODO Need to check transfer queue here, this is actually not the check of this test case
        assert_raises(RuleNotFound, delete_rule, uuid()) 
开发者ID:rucio,项目名称:rucio,代码行数:21,代码来源:test_rule.py

示例15: test_rule_add_fails_account_global_limit

# 需要导入模块: from nose import tools [as 别名]
# 或者: from nose.tools import assert_raises [as 别名]
def test_rule_add_fails_account_global_limit(self):
        """ REPLICATION RULE (CORE): Test if a rule fails correctly when global account limit conflict"""
        scope = InternalScope('mock')
        files = create_files(3, scope, self.rse3_id, bytes=100)
        dataset = 'dataset_' + str(uuid())
        add_did(scope, dataset, DIDType.from_sym('DATASET'), self.jdoe)
        attach_dids(scope, dataset, files, self.jdoe)

        set_local_account_limit(account=self.jdoe, rse_id=self.rse3_id, bytes=400)
        # check with two global limits - one breaking limit is enough to let the rule fail
        set_global_account_limit(rse_expression='%s|MOCK2' % self.rse3, account=self.jdoe, bytes=400)
        set_global_account_limit(rse_expression='%s|MOCK' % self.rse3, account=self.jdoe, bytes=10)
        assert_raises(InsufficientAccountLimit, add_rule, dids=[{'scope': scope, 'name': dataset}], account=self.jdoe, copies=1, rse_expression=self.rse3, grouping='ALL', weight=None, lifetime=None, locked=False, subscription_id=None)

        set_local_account_limit(account=self.jdoe, rse_id=self.rse3_id, bytes=-1)
        set_global_account_limit(rse_expression='%s|MOCK' % self.rse3, account=self.jdoe, bytes=-1)
        set_global_account_limit(rse_expression='%s|MOCK2' % self.rse3, account=self.jdoe, bytes=-1) 
开发者ID:rucio,项目名称:rucio,代码行数:19,代码来源:test_rule.py


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