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


Python TestCase.assertRaises方法代码示例

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


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

示例1: check_and_expect_exception

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
def check_and_expect_exception(put: unittest.TestCase,
                               arrangement: Arrangement,
                               expected_exception: ValueAssertion[Exception]):
    with tmp_dir_as_cwd(arrangement.cwd_dir_contents):
        with put.assertRaises(Exception) as cm:
            # ACT & ASSERT #
            sut.parse(arrangement.sections_configuration, arrangement.root_file)
        expected_exception.apply_with_message(put, cm.exception, 'Exception')
开发者ID:emilkarlen,项目名称:exactly,代码行数:10,代码来源:arrangement_and_expectation.py

示例2: assert_invalid_board_parameters_should_raise_exception

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
def assert_invalid_board_parameters_should_raise_exception(create_board,
                                                           row_count: int,
                                                           column_count: int,
                                                           expected_minimum_row_count: int,
                                                           expected_minimum_column_count: int,
                                                           test_case: TestCase):
    with test_case.assertRaises(InvalidBoard) as exception_context:
        create_board(row_count=row_count, column_count=column_count, observer=None)

    exception = exception_context.exception
    test_case.assertEqual(exception.requested_row_count, row_count)
    test_case.assertEqual(exception.requested_column_count, column_count)
    test_case.assertEqual(exception.minimum_row_count, expected_minimum_row_count)
    test_case.assertEqual(exception.minimum_column_count, expected_minimum_column_count)
开发者ID:wileykestner,项目名称:minesweeper,代码行数:16,代码来源:__init__.py

示例3: check

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
def check(setup: Setup,
          put: unittest.TestCase):
    # ARRANGE #
    with tempfile.TemporaryDirectory(prefix=program_info.PROGRAM_NAME + '-test-') as tmp_dir:
        with preserved_cwd():
            tmp_dir_path = resolved_path(tmp_dir)
            os.chdir(str(tmp_dir_path))

            setup.file_structure_to_read().write_to(tmp_dir_path)
            # ACT & ASSERT #
            with put.assertRaises(Exception) as cm:
                # ACT #
                Reader(default_environment()).apply(setup.root_suite_based_at(tmp_dir_path))
            # ASSERT #
            setup.check_exception(tmp_dir_path, cm.exception, put)
开发者ID:emilkarlen,项目名称:exactly,代码行数:17,代码来源:check_exception.py

示例4: test_invalid_multinode

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
    def test_invalid_multinode(self):  # pylint: disable=too-many-locals
        user = self.factory.make_user()
        device_type = self.factory.make_device_type()
        submission = yaml.load(open(
            os.path.join(os.path.dirname(__file__), 'kvm-multinode.yaml'), 'r'))

        tag_list = [
            self.factory.ensure_tag('usb-flash'),
            self.factory.ensure_tag('usb-eth')
        ]
        self.factory.make_device(device_type, 'fakeqemu1')
        self.factory.make_device(device_type, 'fakeqemu2')
        self.factory.make_device(device_type, 'fakeqemu3', tags=tag_list)
        deploy = [action['deploy'] for action in submission['actions'] if 'deploy' in action]
        # replace working image with a broken URL
        for block in deploy:
            block['images'] = {
                'rootfs': {
                    'url': 'http://localhost/unknown/invalid.gz',
                    'image_arg': '{rootfs}'
                }
            }
        job_object_list = _pipeline_protocols(submission, user, yaml.dump(submission))
        self.assertEqual(len(job_object_list), 2)
        self.assertEqual(
            job_object_list[0].sub_id,
            "%d.%d" % (int(job_object_list[0].id), 0))
        # FIXME: dispatcher master needs to make this kind of test more accessible.
        for job in job_object_list:
            definition = yaml.load(job.definition)
            self.assertNotEqual(definition['protocols']['lava-multinode']['sub_id'], '')
            job.actual_device = Device.objects.get(hostname='fakeqemu1')
            job_def = yaml.load(job.definition)
            job_ctx = job_def.get('context', {})
            parser = JobParser()
            device = None
            device_object = None
            if not job.dynamic_connection:
                device = job.actual_device

                try:
                    device_config = device.load_device_configuration(job_ctx, system=False)  # raw dict
                except (jinja2.TemplateError, yaml.YAMLError, IOError) as exc:
                    # FIXME: report the exceptions as useful user messages
                    self.fail("[%d] jinja2 error: %s" % (job.id, exc))
                if not device_config or not isinstance(device_config, dict):
                    # it is an error to have a pipeline device without a device dictionary as it will never get any jobs.
                    msg = "Administrative error. Device '%s' has no device dictionary." % device.hostname
                    self.fail('[%d] device-dictionary error: %s' % (job.id, msg))

                device_object = PipelineDevice(device_config, device.hostname)  # equivalent of the NewDevice in lava-dispatcher, without .yaml file.
                # FIXME: drop this nasty hack once 'target' is dropped as a parameter
                if 'target' not in device_object:
                    device_object.target = device.hostname
                device_object['hostname'] = device.hostname

            validate_list = job.sub_jobs_list if job.is_multinode else [job]
            for check_job in validate_list:
                parser_device = None if job.dynamic_connection else device_object
                try:
                    # pass (unused) output_dir just for validation as there is no zmq socket either.
                    pipeline_job = parser.parse(
                        check_job.definition, parser_device,
                        check_job.id, None, None, None,
                        output_dir=check_job.output_dir)
                except (AttributeError, JobError, NotImplementedError, KeyError, TypeError) as exc:
                    self.fail('[%s] parser error: %s' % (check_job.sub_id, exc))
                with TestCase.assertRaises(self, (JobError, InfrastructureError)) as check:
                    pipeline_job.pipeline.validate_actions()
                    check_missing_path(self, check, 'qemu-system-x86_64')
        for job in job_object_list:
            job = TestJob.objects.get(id=job.id)
            self.assertNotEqual(job.sub_id, '')
开发者ID:margam2410,项目名称:lava-server,代码行数:75,代码来源:test_pipeline.py

示例5: test_failure_when_nodes_returned_dont_match_nodes_specified

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
    def test_failure_when_nodes_returned_dont_match_nodes_specified(self, unused_sleep_mock):
        self.presto_client_mock.get_rows.return_value = [['bad_host']]

        TestCase.assertRaises(self, RuntimeError, smoketest_presto, self.presto_client_mock, ['master'])
开发者ID:Teradata,项目名称:ambari-presto-service,代码行数:6,代码来源:test_presto_client.py

示例6: test_failure_when_catalogs_are_not_available

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
 def test_failure_when_catalogs_are_not_available(self, ensure_catalogs_are_available_mock,
                                                  unused_sleep_mock):
     TestCase.assertRaises(self, RuntimeError, smoketest_presto, self.presto_client_mock, ['master'])
开发者ID:Teradata,项目名称:ambari-presto-service,代码行数:5,代码来源:test_presto_client.py

示例7: test_failure_when_nodes_are_not_up

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
 def test_failure_when_nodes_are_not_up(self, ensure_nodes_are_up_mock):
     TestCase.assertRaises(self, RuntimeError, smoketest_presto, self.presto_client_mock, ['master'])
开发者ID:Teradata,项目名称:ambari-presto-service,代码行数:4,代码来源:test_presto_client.py

示例8: test_failure_when_fewer_than_25_rows_returned_from_nation

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
    def test_failure_when_fewer_than_25_rows_returned_from_nation(self, unused_sleep_mock):
        self.presto_client_mock.get_rows.return_value = [['master']]

        TestCase.assertRaises(self, RuntimeError, smoketest_presto, self.presto_client_mock, ['master'])
开发者ID:Teradata,项目名称:ambari-presto-service,代码行数:6,代码来源:test_presto_client.py

示例9: assertRaises

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import assertRaises [as 别名]
 def assertRaises(*args, **kwargs):
     return TestCase.assertRaises(None, *args, **kwargs)
开发者ID:lcdb,项目名称:lcdb-workflows,代码行数:4,代码来源:interface.py


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